Refine with an expert
An expert language model produces high-quality refinements of seed documents.
Qwen2.5-72B-InstructBetter data, one precise deletion at a time.
Web data contains valuable knowledge wrapped in noise. RefineX learns to remove the noise with precise, executable edits.
Document filters decide what to keep. End-to-end rewriting can change more than intended. RefineX takes a finer approach: an expert first refines the text, then its edits are distilled into compact deletion-only programs.
A 0.6B refining model learns to generate these programs at scale. The resulting corpus retains its original wording while supporting stronger downstream performance.
The foundational capabilities of large language models (LLMs) are deeply influenced by the quality of their pretraining corpora. However, enhancing data quality at scale remains a significant challenge, primarily due to the trade-off between refinement effectiveness and processing efficiency. While rule-based filtering remains the dominant paradigm, it typically operates at the document level and lacks the granularity needed to refine specific content within documents.
Inspired by emerging work such as ProX, we propose RefineX, a novel framework for large-scale, surgical refinement of pretraining data through programmatic editing tasks. RefineX enables efficient and fine-grained data refinement while reliably preserving the diversity and naturalness of raw text. The core strength of RefineX lies in distilling high-quality, expert-guided end-to-end refinement results into minimal edit-based deletion programs. This high-precision distillation pipeline is used to train an efficient and reliable refine model that can systematically improve every instance in the corpus at scale.
We evaluate RefineX across from-scratch pretraining at multiple model scales and find that it consistently outperforms models trained on raw, filtered, or alternatively refined data across diverse downstream tasks. On the 750M model, RefineX yields 2.6%–7.2% average gains on lighteval tasks, and achieves comparable performance using significantly fewer training tokens. Further analysis shows that RefineX reliably enhances text quality with both high efficiency and precision, outperforming prior approaches such as end-to-end generation and Prox-C. These results position RefineX as a scalable, effective, and reliable solution for optimizing pretraining data in modern LLM pipelines.
Separate the quality of expert refinement
from the cost of applying it everywhere.
An expert language model produces high-quality refinements of seed documents.
Qwen2.5-72B-InstructCompare raw and refined text. Keep deletions and discard insertions and replacements.
Deletion-only supervisionTrain a compact model on approximately 2 million selected text–program pairs.
Qwen3-0.6B-BaseGenerate short programs and execute them to remove low-value content from the corpus.
Compact, executable edits
Trained from scratch. Evaluated across 10 tasks.
The highest average in all six data settings.
Compare refinement methods on the same source corpus.
+2.7 points over Prox-D without additional refinement, at the same training-token budget.
Baseline means no additional fine-grained refinement. Prox-D is LLM-based document filtering; Comb combines Gopher, C4, and FineWeb rules. Values are the paper’s reported averages.
RefineX rows are highlighted. Bold numbers are the best within each source-corpus group, including ties. Reported averages are preserved from the paper.
At 750M scale, Prox-D + RefineX reaches 42.4 average accuracy with 12B tokens, compared with 42.1 for Comb at 20B tokens.


A real example from the paper.
The retained text is unchanged.
[…]
June 24, 2016
STORE | CHECKOUT/CART
EXCLUSIVE // Listen to Stage Kids’ new album ‘Intra Mental’ in full
Five years after their full-length release, Killer Tofu, the San Diego-based instrumental band Stage Kids have reemerged with their latest masterpiece, Intra Mental. Two new members (keyboard and electronics) have joined the quintet since 2011, resulting in more complex and dynamic soundscapes. But the majority of us are summing this one up in one word: definitive.
[…]
Related exclusive fecking bahamas full intra mental stage kids stream Share On Tweet
[…]
[…]
Five years after their full-length release, Killer Tofu, the San Diego-based instrumental band Stage Kids have reemerged with their latest masterpiece, Intra Mental. Two new members (keyboard and electronics) have joined the quintet since 2011, resulting in more complex and dynamic soundscapes. But the majority of us are summing this one up in one word: definitive.
[…]
Excerpt from Case 2 in the paper. […] marks omitted passages. The example shows the paper’s recorded refinement output.
Three operations.
Fine-grained control.
remove_lines(start, end)Delete a range of linesremove_str(line, text)Delete a uniquely matched stringkeep_all()Preserve the whole documentIf you find RefineX useful in your research,
please consider citing our paper.
@misc{bi2025refinex,
title = {{RefineX}: Learning to Refine Pre-training Data at Scale
from Expert-Guided Programs},
author = {Baolong Bi and Shenghua Liu and Xingzhang Ren and
Dayiheng Liu and Junyang Lin and Yiwei Wang and
Lingrui Mei and Junfeng Fang and Jiafeng Guo and Xueqi Cheng},
year = {2025},
eprint = {2507.03253},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2507.03253}
}Follow the RefineX repository ↗ for updates. Code and refining models are listed as coming soon.