PRE-TRAINING DATA REFINEMENT

RefineXLearning to Refine Pre-training Data
at Scale from Expert-Guided Programs

Better data, one precise deletion at a time.

Baolong Bi1 Shenghua Liu1,† Xingzhang Ren2,† Dayiheng Liu2,† Junyang Lin2 Yiwei Wang3 Lingrui Mei1 Junfeng Fang4 Jiafeng Guo1 Xueqi Cheng1
1 Institute of Computing Technology, Chinese Academy of Sciences2 Alibaba Group3 University of California, Merced4 National University of Singapore
Author information

1 Also affiliated with Key Laboratory of Network Data Science and Technology, ICT, CAS; State Key Laboratory of AI Safety; and University of Chinese Academy of Sciences.

† Corresponding authors: Shenghua Liu, Xingzhang Ren, and Dayiheng Liu.

Explore the research
DOWNSTREAM PERFORMANCE44.7%Average accuracy across 10 tasks750M model · 20B tokens · Prox-D + RefineX DATA EFFICIENCY40% fewerTraining tokens for a higher score12B with Prox-D + RefineX vs. 20B with Comb FAITHFUL REFINEMENT0 new wordsKeep the original wordingPer 1,000 refined tokens, in all 5 quality groups
01 / THE IDEA

Refine the text.
Preserve its voice.

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.

Read the abstract

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.

02 / THE METHOD

Expert knowledge.
Lightweight execution.

Separate the quality of expert refinement
from the cost of applying it everywhere.

01

Refine with an expert

An expert language model produces high-quality refinements of seed documents.

Qwen2.5-72B-Instruct
02

Extract precise edits

Compare raw and refined text. Keep deletions and discard insertions and replacements.

Deletion-only supervision
03

Distill the programs

Train a compact model on approximately 2 million selected text–program pairs.

Qwen3-0.6B-Base
04

Refine at scale

Generate short programs and execute them to remove low-value content from the corpus.

Compact, executable edits
RefineX training pipeline: an expert refines seed text, deletion programs are extracted to train a small refiner, and the refiner generates executable programs to clean the pre-training corpus.
THE REFINEX FRAMEWORK Reliable supervision during training; efficient program execution during corpus refinement. Original PDF ↗
What changes from ProX to RefineX?

ProX asks the expert to generate a refinement program directly. RefineX lets the expert produce refined text first, then derives deletion programs by comparing the input and output. This separates text refinement from program construction.

Comparison of ProX direct program generation and RefineX expert text refinement followed by deletion-program extraction.
03 / THE RESULTS

Better data.
Stronger models.

Trained from scratch. Evaluated across 10 tasks.
The highest average in all six data settings.

20B training tokens RedPajama-V2

Average downstream accuracy

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.

Explore all 10 benchmarks 18 configurations per model size
750M model · 20B training tokens · accuracy (%)

RefineX rows are highlighted. Bold numbers are the best within each source-corpus group, including ties. Reported averages are preserved from the paper.

QUALITY WITHOUT THE GENERATION OVERHEAD

Make every training token count.

At 750M scale, Prox-D + RefineX reaches 42.4 average accuracy with 12B tokens, compared with 42.1 for Comb at 20B tokens.

01

Learn more from less data

Average downstream performance versus training tokens, comparing RefineX, Prox-C and unrefined baselines at the 750M model scale.
Average downstream accuracy across training checkpoints. RefineX consistently improves the learning curve. Original PDF ↗
02

Generate edits, efficiently

Generated-to-input token ratio and the proportion of unchanged documents, grouped by initial text quality, for E2E, Prox-C and RefineX.
Generated/input token ratio (top) and unchanged-document ratio (bottom), grouped by initial quality. Original PDF ↗
04 / A CLOSER LOOK

The knowledge stays.
The noise goes.

A real example from the paper.
The retained text is unchanged.

CASE STUDY / A music article from the web

Original document

RAW TEXT

[…]

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

[…]

Refined by RefineX

DELETIONS ONLY

[…]

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.

[…]

Original wording preserved

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 lines
remove_str(line, text)Delete a uniquely matched string
keep_all()Preserve the whole document
05 / BUILD ON THIS WORK

Citation

If you find RefineX useful in your research,
please consider citing our paper.

BibTeX
Download .bib
@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.

Paper figure

Open original PDF ↗