TL;DR
Researchers have introduced SwallowCode and SwallowMath, two new pre-training datasets created using a novel "transform-and-retain" strategy. Instead of simply filtering out low-quality web data, the team used frontier Large Language Models (LLMs) to systematically rewrite it into high-quality, self-contained, and stylistically consistent examples. This approach leads to massive performance boosts—such as a +17.0 increase on HumanEval—for models trained on this refined data.
The Problem: Noise in Pre-Training Data
The performance of LLMs in specialized domains like mathematics and programming is fundamentally bottlenecked by the quality of their training corpora. Most open-source datasets (like The Stack or CommonCrawl) are scraped from the web and riddled with noise, including boilerplate code, missing context, inefficient algorithms, and inconsistent formatting.
Current state-of-the-art approaches usually rely on exclusionary filtering—using rules or classifiers to throw away "bad" data. The authors argue this is highly wasteful. Furthermore, there is a growing "data quality gap" between proprietary frontier models and the open-source community, as the high-quality corpora used to train the best models are rarely released.
Methods: The Transform-and-Retain Pipeline
To address this, the authors propose a transform-and-retain methodology. Rather than discarding mediocre data, they use a powerful "teacher" model (Llama-3.3-70B-Instruct) to rewrite it, maximizing data utility.
The SwallowCode Pipeline (Python)
The pipeline refines Python snippets from The-Stack-v2 through four distinct stages:
- Syntax Validation: Removes any code that fails to compile in Python 3.10.
- Linter-based Filtering: Uses
pylintto score code, discarding anything below a 7/10 threshold. - Style-Guided Code Rewriting (SGCR): An LLM rewrites the code to follow the Google Python Style Guide, adding type hints, docstrings, and descriptive variable names.
- Self-Contained Optimization Rewriting (SCOR): The LLM ensures the code is "self-contained" (e.g., inlining dependencies) and replaces inefficient algorithms (like O(n²) loops) with optimized versions.
The SwallowMath Pipeline
The authors applied a similar logic to the Finemath-4+ dataset. The LLM was prompted to remove web headers, footers, and metadata; restore missing context in incomplete questions; and reformat solutions into clear, step-by-step explanations.
Key Insights
- Rewriting > Filtering: Ablation studies showed that while filtering provided a modest 1-2 point boost, the rewriting stages (SGCR and SCOR) provided a massive 14-point jump in performance.
- The "Instruction Drift" Problem: Asking an LLM to fix style and logic simultaneously caused it to fail at one or the other. Decoupling the process into two distinct stages (SGCR then SCOR) solved this.
- Data Efficiency: Models trained on rewritten data reached higher accuracy levels with significantly fewer tokens compared to models trained on raw, noisy data.
- The MBPP Benchmark Trap: Enforcing "good" coding style (like
snake_case) actually lowered scores on the MBPP benchmark, because MBPP's unit tests often expect specific, non-standard function names (likecamelCase). This highlights a potential flaw in how the community evaluates code models.
Key Results
The researchers performed continual pre-training (CPT) on Llama-3.1-8B and Qwen2-7B for 50 billion tokens. The results were striking:
- Coding: Llama-3.1-8B trained on SwallowCode (~16.1 billion tokens) saw a +17.0 increase in pass@1 on HumanEval and +16.1 on HumanEval+ compared to the Stack-Edu baseline.
- Math: Substituting SwallowMath (~2.3 billion tokens) led to a +12.4 accuracy boost on GSM8K and +7.6 on MATH.
- Generalizability: The gains weren't limited to the Llama family; Qwen2-7B also saw a +10.3 improvement on HumanEval when using the SwallowCode pipeline.
Limitations and Future Work
While highly effective, rewriting billions of tokens is computationally expensive. The authors estimate it took over 23,000 H100 GPU hours to generate the datasets. However, they argue this is a one-time "investment" that creates a reusable community asset.
Currently, the code pipeline is focused exclusively on Python, making expansion to C++, Java, and Rust a logical next step. Additionally, future work must investigate "teacher bias" (whether rewritten data inherits hallucination patterns from the Llama-3.3-70B model) and how these benefits scale when training models from scratch on trillions of tokens.
Summary updated