RefineX: Learning to Refine Pre-training Data at Scale from Expert-Guided Programs

Baolong Bi, Shenghua Liu, Xingzhang Ren, Dayiheng Liu, Junyang Lin, Yiwei Wang, Lingrui Mei, Junfeng Fang, Jiafeng Guo, Xueqi Cheng · DOI

Introduction

The "Garbage In, Garbage Out" principle is a cornerstone of Large Language Model (LLM) development: the quality of the pre-training corpus fundamentally dictates the model's ultimate capabilities. However, cleaning massive, web-scale datasets like RedPajama or Common Crawl remains a significant challenge. Current approaches typically fall into two categories: blunt rule-based filtering, which often discards valuable content, or expensive end-to-end (E2E) refinement using powerful LLMs, which is computationally prohibitive at scale and risks introducing hallucinations.

RefineX introduces a novel framework that bridges this gap by distilling expert-level "surgical" edits into efficient, deletion-only programs. By training a lightweight model to predict these programs rather than rewriting text from scratch, RefineX achieves significant performance gains while maintaining the speed necessary for processing trillions of tokens.

The RefineX Methodology

RefineX employs a two-stage distillation pipeline to create a high-speed "Refine Model." Unlike previous attempts that struggled with noisy training data, RefineX focuses on reliable program generation through an "Edit Distance Bridge."

The RefineX pipeline: Training the refiner with reliable data and performing large-scale inference.
  1. Expert-Guided Distillation: Instead of prompting an expert model to write code directly, RefineX asks it to perform E2E refinement—rewriting noisy text into a cleaner version.
  2. The Edit Distance Bridge: A Minimum Edit Distance (Levenshtein) algorithm compares the raw text with the expert’s refined version. It specifically extracts deletion operations (removing lines or specific strings), ensuring the refiner never adds new, potentially hallucinated content.
  3. Programmatic Training: These deletions are converted into simple Python-like functions (e.g., remove_lines(1, 3)). A 0.6B parameter model is then trained to predict these programs from raw text.
  4. Scalable Execution: During inference, the small Refine Model generates these programs, which are then executed by a standard Python interpreter. This approach is significantly faster than E2E rewriting and preserves the stylistic essence of the original data.

Experimental Setup

The authors utilized RedPajama-V2 as the source corpus. To train the Refine Model, they sampled 5 million documents, using the DataMan tool to ensure a high-quality distribution for distillation.

For evaluation, models with 350M and 750M parameters were pre-trained from scratch on 20-billion-token subsets. RefineX was compared against established baselines including C4, Gopher, FineWeb, and ProX-C. Downstream performance was measured across 10 benchmarks via LightEval, including MMLU, ARC, and HellaSwag.

Results and Discussion

RefineX demonstrated superior performance and efficiency across all tested scales. On the 750M parameter model, RefineX yielded average gains of 2.6% to 7.2% compared to raw or filtered data.

Average performance across benchmarks as a function of training tokens, comparing RefineX against various baselines.

Key Findings:

  • Data Efficiency: A model trained on 10B tokens of RefineX-processed data matched or outperformed a model trained on 20B tokens of standard filtered data, suggesting that surgical cleaning is twice as effective as document-level filtering.
  • Zero Hallucination: By restricting operations to deletions, RefineX introduced zero new words into the refined text, a critical advantage over E2E methods that often hallucinate content.
  • Computational Efficiency: The 0.6B Refine Model is small enough for massive deployment, making it a practical solution for cleaning the trillions of tokens required for modern LLM training.

Conclusion

RefineX represents a significant step forward in scalable data curation. By transforming the complex task of text refinement into a simple program prediction problem, it enables surgical data cleaning at a fraction of the cost of LLM-based rewriting. While currently limited to deletion operations, future iterations may explore "safe" ways to incorporate limited insertion or replacement tasks to further enhance data quality.

Summary updated

BibTeX
@misc{bi2025refinex,
  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},
  title = {{RefineX: Learning to Refine Pre-training Data at Scale from Expert-Guided Programs}},
  year = {2025},
  eprint = {2507.03253},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.03253},
}
Figure