Abstract
While Large Language Models (LLMs) are increasingly trained on vast quantities of source code, the causal impact of this data on non-coding reasoning tasks remains under-explored. This paper investigates whether code pretraining enhances general logic or if it introduces specific inductive biases. Through controlled experiments using competitive and additive data mixtures, we find that code significantly improves performance on tasks with formal structural requirements, such as semantic parsing and multi-digit arithmetic. However, this comes at a cost to purely linguistic tasks and world knowledge, suggesting a fundamental trade-off between structural and linguistic inductive biases.
Introduction
The prevailing wisdom in the AI community suggests that training on source code does more than just teach a model to program; it supposedly "teaches the model to think." High-performing models like GPT-4 and Gemini are trained on massive mixtures of natural language and code, leading researchers to hypothesize that the rigorous logic and structural consistency of programming languages translate into improved general reasoning capabilities.
However, establishing a causal link has proven difficult. Most existing evidence is observational, comparing models with different architectures, sizes, or total training budgets. This study addresses the causal question directly: by holding model architecture and training parameters constant, how does varying the proportion of code in the pretraining data affect performance on non-code tasks?
Experimental Methodology
To isolate the effects of code, the researchers pretrained a series of 374M-parameter decoder-only Transformer models. They employed two distinct experimental frameworks to analyze the relationship between code and language data:
- Competitive Setting: The total number of training tokens was fixed at 132 billion. As the percentage of code in the mixture increased, the amount of natural language data was proportionally reduced. This measures the marginal utility of code relative to language.
- Additive Setting: The amount of natural language data was held constant (132 billion tokens), and code was added on top. This determines if code provides a performance "bonus" independent of language exposure.
The "code mixture" was treated as a continuous variable ranging from 0% to 90%. The natural language data was sourced from C4 (Common Crawl), while code data was extracted from a cleaned version of GitHub repositories within The Pile.
The Structural Advantage
The most significant finding was that code pretraining dramatically improves performance on tasks requiring formal, structured outputs. This was most evident in compositional generalization tasks like COGS and COGS-vf, where models must transform natural language sentences into logical expressions.
In the COGS-vf structural generalization task, linear regression predicted a 14.7% accuracy increase as the code proportion moved from 0% to 100%. Interestingly, the researchers found that this benefit was not merely due to better syntax (e.g., balancing parentheses). Instead, code pretraining appeared to help models better understand the "distribution of arguments"—essentially, identifying the roles of different entities in a sentence (who did what to whom) more accurately than models trained on language alone.
The Linguistic Trade-off
Despite the gains in logic and structure, the study revealed a clear "no free lunch" scenario. Increased exposure to code led to a measurable decline in performance on purely linguistic tasks. For instance, in the "English Passivization" task—which requires converting active voice to passive voice—accuracy dropped as the code mixture increased.
Furthermore, code pretraining negatively impacted tasks requiring broad world knowledge or identification of linguistic nuances, such as common morpheme identification. The authors hypothesize that code introduces a "structural" inductive bias. While this bias is highly effective for math and logic, it may compete with the "linguistic" bias necessary for mastering the fluid and often ambiguous nature of natural language.
Arithmetic and Scaling
The benefits of code were also highly visible in mathematics. Performance on BigBench arithmetic tasks showed a strong positive correlation with the code mixture. Notably, this advantage scaled with problem difficulty; the performance gap between code-heavy and language-only models was much wider for 5-digit multiplication than for simple 1-digit addition. This suggests that the algorithmic nature of code helps models internalize the step-by-step procedures required for complex calculation.
Conclusion
This research provides empirical evidence that code pretraining is a double-edged sword. It acts as a powerful catalyst for structural reasoning and mathematical proficiency, likely by providing a cleaner, more logical signal than the noisy patterns found in natural language. However, this specialization comes at the cost of linguistic sensitivity and factual recall.
Future work remains to be done at larger model scales (e.g., 70B+ parameters) to see if these trade-offs persist. Additionally, investigating how post-training techniques like instruction tuning might bridge the gap between structural logic and linguistic nuance will be critical for developing the next generation of balanced LLMs.
Summary updated