Introduction Code data isn't just for building better programmers; it has emerged as a fundamental building block for general intelligence in language models. This systematic study reveals that including code in pre-training mixtures boosts natural language reasoning by up to 8.2% and world knowledge by 4.2%, proving that "thinking in code" helps Large Language Models (LLMs) generalize far beyond the terminal.
The Problem While it has become common practice to include code in the training data for LLMs—even those not intended for coding—the industry has largely relied on anecdotal evidence. We know that models like Llama 3 significantly increased their code proportions (from 4.5% in Llama 2 to 17%), but we lacked a rigorous, controlled study on why this helps non-code tasks.
The authors tackle the "precise impact" of code. They investigate whether code helps with logic, how much code is "too much," and whether the quality of the code (e.g., web-scraped vs. synthetically generated) changes the outcome for general natural language tasks.
Methodology & Datasets The researchers conducted an exhaustive set of ablations using models ranging from 470M to 2.8B parameters.
Their experimental framework focused on several critical levers:
- Initialization: Comparing models trained from scratch on text vs. those initialized with code-heavy weights.
- Proportions: Testing mixtures from 0% to 100% code.
- Training Phases: Analyzing the impact of code during "continued pre-training" versus the "cooldown" phase (the final stage of training where high-quality data is up-weighted and the learning rate is annealed).
- Data Properties: Comparing standard web-based code against markup (HTML/CSS), code-adjacent data (GitHub commits), and high-quality synthetic code.
To support these ablations, the study utilized a robust mix of datasets:
- Pre-training Text: SlimPajama, a massive, cleaned version of RedPajama-1.2T.
- Pre-training Code: The Stack (web-based), along with a separate subset for Markdown/HTML/CSS.
- Synthetic Code: A proprietary dataset of Python problems formally verified for correctness.
- Evaluation Suite: A broad battery including TriviaQA and NaturalQuestions (World Knowledge); 11 reasoning benchmarks like BoolQ, HellaSwag, and Winogrande (NL Reasoning); and HumanEval/MBPP (Code).
- Generative Quality: Dolly-200, used for "LLM-as-a-judge" win-rate evaluations.
Key Insights and Ideas * Code as a Reasoning Engine: The most striking finding is that code-heavy initialization followed by text training outperforms training on text alone for reasoning tasks. This suggests that the structural logic of programming languages provides a "scaffold" for the model to better understand complex natural language logic. * The World Knowledge Trade-off: There is a limit to the benefits of code. While reasoning improves with more code, world knowledge eventually suffers. If a model is trained on 100% code, it loses the ability to answer factual questions because code lacks the encyclopedic facts found in natural language text. The authors found a "sweet spot" around 25% code for balancing these capabilities.
- Quality Trumps Quantity: Synthetic, verified code is incredibly potent. Replacing just 10% of web-scraped code with high-quality synthetic Python problems led to a 9% boost in NL reasoning and a 44% boost in code performance.
- Don't Drop Code During Cooldown: Many practitioners focus exclusively on high-quality text during the final "cooldown" phase. This paper shows that keeping code in the mix during cooldown is critical; removing it leads to a drop in performance across nearly all metrics, including a 4.1% drop in generative win-rates.
Key Results * Reasoning Gains: Compared to text-only models, the best code-integrated variants saw an 8.2% relative increase in natural language reasoning. * Knowledge & Win-rates: The addition of code resulted in a 4.2% boost in world knowledge and a 6.6% improvement in generative win-rates (as judged by a stronger model). * Code Performance: Beyond the side benefits, the models saw a 12x boost in actual coding ability compared to text-only baselines. * Scaling Consistency: These trends held steady as the model size increased from 470M to 2.8B, suggesting these findings likely apply to even larger frontier models.
Limitations and Future Work The primary limitation acknowledged is compute cost. While 2.8B parameters is a respectable size for research, it is small compared to the 70B+ parameter models used in industry. The authors were unable to test if these benefits plateau or change at massive scales due to the prohibitive compute costs of running so many ablations. Additionally, the study does not explore the impact of code on safety and bias. Future work could investigate whether the logical nature of code helps models follow safety guidelines more strictly or if it introduces new, unforeseen biases into natural language generations.
Summary updated