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

TL;DR
This paper demonstrates that by adding relative position embeddings to digits, transformers can significantly improve their arithmetic capabilities, achieving near-perfect accuracy on large digit addition and enhancing multi-step reasoning tasks.
Contribution
Introducing relative position embeddings for digits in transformers to improve arithmetic and reasoning performance, enabling state-of-the-art results with minimal training.
Findings
Achieved 99% accuracy on 100-digit addition with minimal training.
Relative position embeddings significantly boost arithmetic performance.
Enhanced reasoning tasks like sorting and multiplication through improved numeracy.
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,…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsComputability, Logic, AI Algorithms
MethodsMODEL EDITOR NETWORKS WITH GRADIENT DECOMPOSITION
