Abstract
Large Language Models (LLMs) demonstrate remarkable capabilities across diverse domains, yet their performance on basic arithmetic remains inconsistent, particularly when generalizing to problem lengths unseen during training. This paper investigates the underlying mechanism of mathematical reasoning in Transformers, questioning whether they learn systematic rules or rely on local case-based interpolation. Through a series of "Leave-Square-Out" interventions, the authors demonstrate that Transformers are primarily case-based reasoners, failing in regions where local training data is absent. To bridge this gap, the paper introduces Rule-Following Fine-Tuning (RFFT), a method that teaches models to explicitly recite and apply abstract rules. RFFT enables significant leaps in length generalization, allowing models to solve 12-digit addition problems with over 95% accuracy after training only on 1-5 digit examples.
Introduction
While Transformers like GPT-4 can generate complex code and nuanced poetry, they frequently stumble on arithmetic tasks that humans solve using simple, repeatable algorithms. This discrepancy points to a fundamental question in artificial intelligence: Are Transformers learning rules—systematic algorithms that apply to any valid input—or are they learning cases—matching new problems to the nearest examples seen during training?
In a rule-based system, a model that understands the algorithm for addition should theoretically be able to add numbers of any length. Conversely, a case-based system solves $42 + 57$ by interpolating from similar training instances like $41 + 57$ or $42 + 56$. This paper argues that current Transformers are trapped in the case-based paradigm and proposes a methodology to transition them toward true rule-based reasoning.
Proving the Case-Based Hypothesis
To diagnose the reasoning style of Transformers, the researchers utilized a Leave-Square-Out Intervention. They visualized model accuracy on a 2D grid of inputs $(a, b)$ and intentionally removed a "square" of data from the training set (for example, all instances where both $a$ and $b$ fall between 40 and 60).
If the model were truly rule-based, the absence of these specific numbers would not hinder its performance, as the underlying algorithm remains constant. However, the results revealed distinct "holes" in the accuracy heatmaps. The models failed specifically in the regions where they lacked nearby training examples, providing a "smoking gun" for case-based reasoning. The model was not learning a global rule, but rather constructing a local lookup table.
Rule-Following Fine-Tuning (RFFT)
To address this limitation, the authors developed Rule-Following Fine-Tuning (RFFT). This approach moves beyond the standard "scratchpad" method, which typically only requires the model to show intermediate calculation steps. The authors argue that standard scratchpads often result in "mechanical recitation," where the model simply memorizes a longer sequence of cases without understanding the logic.
RFFT shifts the focus to explicit logic by providing the model with formal rules (expressed as Python code or natural language) within the input. During fine-tuning, the model is trained to:
- Recite the specific rule it is currently applying.
- Update its internal state (e.g., tracking variables like
carryorcurrent_sum). - Execute the logic step-by-step until the final answer is reached.
Experimental Framework
The hypotheses were tested across five diverse mathematical and logical tasks:
- Standard Addition: Base-10 addition.
- Modular Addition: Addition within a finite field (mod 113).
- Base-9 Addition: Used to prevent the model from relying on pre-training data leakage.
- Linear Regression: Predicting outputs for linear functions.
- Chicken & Rabbit Problems: Algebraic word problems.
- Exotic Digits: A control dataset where digits 0-8 were replaced with letters A-I to ensure the model was not relying on memorized digit patterns.
Key Insights
The Failure of Scratchpads
The study suggests that traditional scratchpads do not inherently teach reasoning. Instead, they often lead the model to mimic the output of a process. Without an explicit rule to follow, the model treats the intermediate steps as just another set of cases to be memorized.
Scale and Rule-Following
An emergent property of scale was observed regarding the ease of rule adoption. Larger models, such as GPT-3.5, required significantly fewer examples (as few as 100) to learn a rule via RFFT compared to smaller models like Llama-2-7B. This suggests that while models are case-based by default, the capacity to follow abstract rules improves with model size.
Results and Generalization
The impact of RFFT on length generalization was profound. Models trained on 1-5 digit addition using RFFT were able to generalize to 12-digit addition with over 95% accuracy. This represents a massive improvement over direct-answer and standard scratchpad methods, which often fail completely when the number of digits exceeds the training range. In unfamiliar tasks, such as base-9 addition with exotic letter-digits, RFFT maintained high performance while other methods collapsed.
Limitations and Future Directions
Despite its success, RFFT has notable limitations. Currently, the rules must be human-defined and the input-output formats must be manually designed for each task. The model is not yet autonomously "discovering" these rules. Furthermore, the verbose nature of RFFT can lead to extremely long outputs for complex problems, potentially hitting context window limits or increasing the risk of hallucinations during extended reasoning chains.
Future research will likely focus on how models might autonomously extract rules from examples (In-Context Learning) rather than requiring explicit supervision during the fine-tuning phase.
Summary updated