Length Generalization in Arithmetic Transformers
Samy Jelassi, St\'ephane d'Ascoli, Carles Domingo-Enrich, Yuhuai Wu,, Yuanzhi Li, Fran\c{c}ois Charton

TL;DR
This paper investigates how transformer models can generalize to longer arithmetic sequences, proposing relative position embeddings for addition and a priming method for multiplication, with implications for broader sequence tasks.
Contribution
The paper introduces a priming technique that enables transformers to generalize to longer sequences in arithmetic tasks, extending beyond previous limitations.
Findings
Relative position embeddings enable length generalization in addition.
Priming with a few long sequences improves multiplication generalization.
Priming sample size scales logarithmically with training set size.
Abstract
We examine how transformers cope with two challenges: learning basic integer arithmetic, and generalizing to longer sequences than seen during training. We find that relative position embeddings enable length generalization for simple tasks, such as addition: models trained on -digit numbers can perform -digit sums. However, this method fails for multiplication, and we propose train set priming: adding a few ( to ) long sequences to the training set. We show that priming allows models trained on -digit -digit multiplications to generalize to examples. We also show that models can be primed for different generalization lengths, and that the priming sample size scales as the logarithm of the training set size. Finally, we discuss potential applications of priming beyond arithmetic.
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.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsComputational Physics and Python Applications · Model Reduction and Neural Networks · Neural Networks and Applications
