Research map / Large language models / Instruction and fine-tuning
Case-Based or Rule-Based: How Do Transformers Do the Math?
Read the paperCheck your idea against 108,967 papers
AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.
Uses leave-square-out data interventions on five math tasks to show fine-tuned transformers rely on case-based rather than rule-based reasoning, then proposes Rule-Following Fine-Tuning (RFFT) that makes GPT-3.5 generalize from 1-5 digit to 12-digit addition.
Problem
LLMs fail at simple math such as addition on inputs longer than training data; it is debated whether transformers learn underlying rules or recall similar training cases.
Approach
Distinguish case-based from rule-based reasoning via data interventions that remove a square region of training examples and test whether accuracy holes appear; then teach rule-following by putting explicit rules (a Python program) in the input and fine-tuning the model to quote and execute each rule step by step.
Key results
- RFFT on GPT-3.5-turbo trained on 100 samples of 1-5 digit addition keeps over 95% accuracy on 12-digit addition, over 40% higher than scratchpad.
- Llama-2-7B with RFFT maintains 91.1% accuracy on 9-digit sums, while scratchpad achieves under 40% on similar lengths.
- Leave-square-out on GPT-2 produces clear accuracy holes in test squares for addition, modular addition, base addition, and linear regression despite 100% random-split accuracy.
Measured effects reported in the paper
| What was changed | Where | Measured | Effect |
|---|---|---|---|
| Provide explicit addition rules and train the model to recite and follow them step by step instead of using direct-answer or scratchpad fine-tuning | GPT-3.5-turbo-1106 · Addition, up to 12 digits | accuracy: over 95% | Helped |
| Provide explicit addition rules and train the model to follow them step by step rather than use scratchpad fine-tuning | Llama-2-7B · Addition, 6- to 9-digit sums | accuracy: 91.1%; less than 40% | Helped |
| Use scratchpad fine-tuning instead of direct-answer training (ablation) | GPT-2 and GPT-2-medium · Addition, Leave-Square-Out with square side length l_k≥20 | test accuracy | Helped |
| Use scratchpad fine-tuning instead of direct-answer training (ablation) | GPT-2 and GPT-2-medium · Addition, Leave-Square-Out with square side length l_k=10 | test accuracy | Hurt |
| Use scratchpad instead of direct-answer fine-tuning (ablation) | GPT-3.5-turbo-1106 · Addition, including 15-digit addition | accuracy: 46.2% on 15-digit addition with direct answer | Hurt |
| Train on a leave-square-out split rather than a random split (ablation) | GPT-2 and GPT-2-medium · Five math tasks: addition, modular addition, base addition, linear regression, and chicken & rabbit | test accuracy: 100%; above 95% | Hurt |
| Increase the left-out test-square side length (ablation) | GPT-2 and GPT-2-medium · Addition, Leave-Square-Out | test accuracy | Hurt |
| Increase addition training range and scale the left-out square accordingly (ablation) | GPT-2 · Addition, Leave-Square-Out over ranges [0,100), [0,200), and [0,500) | test accuracy | No clear effect |
| Replace base-9 digits 0–8 with letters A–I (ablation) | Fine-tuned Llama-2-7B · Base-9 addition, Leave-Square-Out | test accuracy | Hurt |
| Provide explicit rules in-context rather than direct-answer or scratchpad examples (ablation) | GPT-3.5-turbo-0125 · Familiar base-10 addition | accuracy | Hurt |
| Provide explicit rules in-context rather than direct-answer or scratchpad examples (ablation) | GPT-3.5-turbo-0125 · Unfamiliar base-9 addition | accuracy | Helped |
| Train on a random split instead of leaving out a test square (ablation) | Llama-2-7B trained from scratch · Base-9 addition | test accuracy: 30.2% to 92% | Helped |
Surprising findings
- Scratchpad fine-tuning of GPT-3.5 underperformed direct answer fine-tuning, contrary to expectation.
- Fine-tuned pretrained Llama-2-7B on base-9 addition with letter digits (A-I) showed a hole, suggesting pretraining biases rather than systematic rule learning.
Limitations
- RFFT is task-specific and requires carefully designed input-output sequences.
- Study focuses on fine-tuning for specific tasks rather than pretrained model reasoning mechanisms or prompting techniques like CoT.
- Errors persist at longer lengths due to execution mistakes (e.g., pop) and limited long-context ability.
Experimental setup
Datasets: synthetic addition modular addition base-9 addition linear regression chicken & rabbit problems last-letter concatenation
Benchmarks: synthetic addition test sets (1-9 and 6-15 digits) leave-square-out test squares on five math tasks
Metrics: accuracy accuracy over test squares accuracy gap train vs test
Baselines: direct answer fine-tuning scratchpad fine-tuning
Builds on: scratchpad fine-tuning grokking chain-of-thought
Closest papers by meaning
- Grokking of Implicit Reasoning in Transformers: A Mechanistic Journey to the Edge of Generalization (NeurIPS 2024 · similarity 0.86)
- Learning Theorem Rationale for Improving the Mathematical Reasoning Capability of Large Language Models (AAAI 2025 · similarity 0.86)
- Advancing Mathematical Reasoning in Language Models: The Impact of Problem-Solving Data, Data Synthesis Methods, and Training Stages (ICLR 2025 · similarity 0.86)
- When can transformers reason with abstract symbols? (ICLR 2024 · similarity 0.86)
- OMEGA: Can LLMs Reason Outside the Box in Math? Evaluating Exploratory, Compositional, and Transformative Generalization (NeurIPS 2025 · similarity 0.86)
- RMath: A Logic Reasoning-Focused Datasets Toward Mathematical Multistep Reasoning Tasks (AAAI 2025 · similarity 0.85)
Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.
