Transformers Can Do Arithmetic with the Right Embeddings
Sean McLeish, Arpit Bansal, Alex Stein, Neel Jain, John Kirchenbauer, Brian R. Bartoldson, Bhavya Kailkhura, Abhinav Bhatele, Jonas Geiping, Avi Schwarzschild, Tom Goldstein
Abstract
The poor performance of transformers on arithmetic tasks seems to stem in large part from their inability to keep track of the exact position of each digit inside of a large span of digits. We mend this problem by adding an embedding to each digit that encodes its position relative to the start of the number. In addition to the boost these embeddings provide on their own, we show that this fix enables architectural modifications such as input injection and recurrent layers to improve performance even further. With positions resolved, we can study the logical extrapolation ability of transformers. Can they solve arithmetic problems that are larger and more complex than those in their training data? We find that training on only 20 digit numbers with a single GPU for one day, we can reach state-of-the-art performance, achieving up to 99% accuracy on 100 digit addition problems. Finally, we show that these gains in numeracy also unlock improvements on other multi-step reasoning tasks including sorting and multiplication.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
38 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Scaling Vision Transformers cites Language Models are Few-Shot Learners
- Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation cites Language Models are Few-Shot Learners
- Extrapolation by Association: Length Generalization Transfer In Transformers cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Extrapolation by Association: Length Generalization Transfer In Transformers cites Language Models are Few-Shot Learners
- Extrapolation by Association: Length Generalization Transfer In Transformers cites Position Coupling: Improving Length Generalization of Arithmetic Transformers Using Task Structure
- Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth Approach cites ALBERT: A Lite BERT for Self-supervised Learning of Language Representations
- Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth Approach cites Scaling Vision Transformers
- FoNE: Precise Single-Token Number Embeddings via Fourier Features cites Benford's Curse: Tracing Digit Bias to Numerical Hallucination in LLMs
- FoNE: Precise Single-Token Number Embeddings via Fourier Features cites Language Models are Few-Shot Learners
- FoNE: Precise Single-Token Number Embeddings via Fourier Features cites Faith and Fate: Limits of Transformers on Compositionality
- Position Coupling: Improving Length Generalization of Arithmetic Transformers Using Task Structure cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Faith and Fate: Limits of Transformers on Compositionality cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Faith and Fate: Limits of Transformers on Compositionality cites Language Models are Few-Shot Learners
Cited by top-tier papers38
- Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth ApproachJonas Geiping, Sean McLeish, Neel Jain, John Kirchenbauer et al.NeurIPS 2025 · 431 citations
- Position Coupling: Improving Length Generalization of Arithmetic Transformers Using Task StructureHanseul Cho, Jaeyoung Cha, Pranjal Awasthi, Srinadh Bhojanapalli et al.NeurIPS 2024 · 28 citations
- FoNE: Precise Single-Token Number Embeddings via Fourier FeaturesTianyi Zhou, Deqing Fu, Mahdi Soltanolkotabi, Robin Jia et al.ICLR 2026 · 24 citations
- Extrapolation by Association: Length Generalization Transfer In TransformersZiyang Cai, Nayoung Lee, Avi Schwarzschild, Samet Oymak et al.NeurIPS 2025 · 13 citations
- Benford's Curse: Tracing Digit Bias to Numerical Hallucination in LLMsJiandong Shao, Yao Lu, Jianfei YangNeurIPS 2025 · 8 citations
Builds on23
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
- ALBERT: A Lite BERT for Self-supervised Learning of Language RepresentationsZhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel et al.ICLR 2020 · 7,418 citations
- Train Short, Test Long: Attention with Linear Biases Enables Input Length ExtrapolationOfir Press, Noah A. Smith, Mike LewisICLR 2022 · 1,168 citations
- Scaling Vision TransformersXiaohua Zhai, Alexander Kolesnikov, Neil Houlsby, Lucas BeyerCVPR 2022 · 767 citations
- Faith and Fate: Limits of Transformers on CompositionalityNouha Dziri, Ximing Lu, Melanie Sclar, Xiang Lorraine Li et al.NeurIPS 2023 · 728 citations
Related papers
- How Numerical Precision Affects Arithmetical Reasoning Capabilities of LLMsGuhao Feng, Kai Yang, Yuntian Gu, Xinyue Ai et al.ACL Findings 2025 · 5 citations
- Arithmetic Transformers Can Length-Generalize in Both Operand Length and CountHanseul Cho, Jaeyoung Cha, Srinadh Bhojanapalli, Chulhee YunICLR 2025
- Investigating Numeracy Learning Ability of a Text-to-Text Transfer ModelKuntal Kumar Pal, Chitta BaralEMNLP Findings 2021 · 18 citations
- Neural Execution Engines: Learning to Execute SubroutinesYujun Yan, Kevin Swersky, Danai Koutra, Parthasarathy Ranganathan et al.NeurIPS 2020 · 47 citations
- Scaling Behavior for Large Language Models regarding Numeral Systems: An Example using PythiaZhejian Zhou, Jiayu Wang, Dahua Lin, Kai ChenEMNLP Findings 2024
