[Paper Review] Teaching Arithmetic to Small Transformers
The paper shows that small decoder-only Transformers can learn arithmetic from scratch using carefully formatted data, with output-reversal and chain-of-thought scratchpads dramatically improving sample efficiency and generalization beyond standard matrix completion intuitions.
Large language models like GPT-4 exhibit emergent capabilities across general-purpose tasks, such as basic arithmetic, when trained on extensive text data, even though these tasks are not explicitly encoded by the unsupervised, next-token prediction objective. This study investigates how small transformers, trained from random initialization, can efficiently learn arithmetic operations such as addition, multiplication, and elementary functions like square root, using the next-token prediction objective. We first demonstrate that conventional training data is not the most effective for arithmetic learning, and simple formatting changes can significantly improve accuracy. This leads to sharp phase transitions as a function of training data scale, which, in some cases, can be explained through connections to low-rank matrix completion. Building on prior work, we then train on chain-of-thought style data that includes intermediate step results. Even in the complete absence of pretraining, this approach significantly and simultaneously improves accuracy, sample complexity, and convergence speed. We also study the interplay between arithmetic and text data during training and examine the effects of few-shot prompting, pretraining, and model scale. Additionally, we discuss length generalization challenges. Our work highlights the importance of high-quality, instructive data that considers the particular characteristics of the next-word prediction objective for rapidly eliciting arithmetic capabilities.
Motivation & Objective
- Investigate how small transformers trained from random initialization can learn arithmetic operations.
- Assess the impact of data format and sampling on learning arithmetic under next-token prediction.
- Explore the role of chain-of-thought (CoT) data in training for arithmetic tasks.
- Examine how pretraining, model scale, and mix of text/arithmetic data affect arithmetic learning and generalization.
- Analyze length generalization and limits of learning arithmetic as a mapping vs. algorithm.
Proposed method
- Train NanoGPT (6 layers, 384 hidden, ~10.6M parameters) from random initialization on arithmetic tasks.
- Evaluate four data formats for addition: Plain, Reverse, Simplified Scratchpad, Detailed Scratchpad.
- Use structured sampling to balance digits and carry-ons across n-digit inputs.
- Relate learning to low-rank matrix completion and analyze phase transitions in sample complexity.
- Extend experiments to chain-of-thought style data to assess impact on learning speed and accuracy.
- Compare with pretraining/fine-tuning setups on larger models to study scale and transfer effects.
Experimental results
Research questions
- RQ1Can small transformer models learn arithmetic from scratch using next-token prediction?
- RQ2How do data formatting and sampling influence sample efficiency and accuracy in learning arithmetic?
- RQ3Does chain-of-thought style data further improve learning of arithmetic tasks, especially from scratch?
- RQ4What is the role of model scale and pretraining in acquiring arithmetic abilities?
- RQ5How well do learned arithmetic capabilities generalize to unseen digits or numbers and to longer digit lengths?
Key findings
- Plain addition data yields suboptimal performance; output reversal substantially improves accuracy and reduces needed training data.
- There is a sharp phase transition in learning addition as training data increases, consistent with low-rank matrix completion intuition.
- Addition learned by NanoGPT can generalize to unseen numbers and partially missing digit sets beyond standard LRMC limits, indicating capabilities beyond simple matrix completion.
- Chain-of-thought data significantly improves sample efficiency and accuracy in learning addition, even from scratch, with performance dependent on the level of intermediate-step detail.
- Balanced sampling of digits and carry-ons improves performance over random sampling across 3-digit addition tasks.
- Transformer-based learning of addition differs from LRMC, suggesting additional generalization mechanisms beyond matrix completion.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.