Overcoming a Theoretical Limitation of Self-Attention
David Chiang, Peter Cholak
Abstract
Although transformers are remarkably effective for many tasks, there are some surprisingly easy-looking regular languages that they struggle with. Hahn shows that for languages where acceptance depends on a single input symbol, a transformer’s classification decisions get closer and closer to random guessing (that is, a cross-entropy of 1) as input strings get longer and longer. We examine this limitation using two languages: PARITY, the language of bit strings with an odd number of 1s, and FIRST, the language of bit strings starting with a 1. We demonstrate three ways of overcoming the limitation implied by Hahn’s lemma. First, we settle an open question by constructing a transformer that recognizes PARITY with perfect accuracy, and similarly for FIRST. Second, we use layer normalization to bring the cross-entropy of both models arbitrarily close to zero. Third, when transformers need to focus on a single position, as for FIRST, we find that they can fail to generalize to longer strings; we offer a simple remedy to this problem that also improves length generalization in machine translation.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 8227d353-6eb2-4289-b4a4-047bb549feb2Cited by top-tier papers61
- TransNeXt: Robust Foveal Visual Perception for Vision TransformersDai ShiCVPR 2024 · 313 citations
- What Algorithms can Transformers Learn? A Study in Length GeneralizationHattie Zhou, Arwen Bradley, Etai Littwin, Noam Razin et al.ICLR 2024 · 189 citations
- Scaling Laws of RoPE-based ExtrapolationXiaoran Liu, Hang Yan, Chenxin An, Xipeng Qiu et al.ICLR 2024 · 130 citations
- The Transient Nature of Emergent In-Context Learning in TransformersAaditya K. Singh, Stephanie C. Y. Chan, Ted Moskovitz, Erin Grant et al.NeurIPS 2023 · 92 citations
- Exposing Attention Glitches with Flip-Flop Language ModelingBingbin Liu, Jordan T. Ash, Surbhi Goel, Akshay Krishnamurthy et al.NeurIPS 2023 · 90 citations
Builds on4
- Are Transformers universal approximators of sequence-to-sequence functions?Chulhee Yun, Srinadh Bhojanapalli, Ankit Singh Rawat, Sashank J. Reddi et al.ICLR 2020 · 481 citations
- Thinking Like TransformersGail Weiss, Yoav Goldberg, Eran YahavICML 2021 · 183 citations
- On the Ability and Limitations of Transformers to Recognize Formal LanguagesSatwik Bhattamishra, Kabir Ahuja, Navin GoyalEMNLP 2020 · 7 citations
- Effects of Parameter Norm Growth During Transformer Training: Inductive Bias from Gradient DescentWilliam Merrill, Vivek Ramanujan, Yoav Goldberg, Roy Schwartz et al.EMNLP 2021 · 1 citation
Related papers
- How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit BiasRuiquan Huang, Yingbin Liang, Jing YangICML 2025
- A Formal Framework for Understanding Length Generalization in TransformersXinting Huang, Andy Yang, Satwik Bhattamishra, Yash Raj Sarrof et al.ICLR 2025
- Why are Sensitive Functions Hard for Transformers?Michael Hahn, Mark RofinACL 2024 · 3 citations
- Language Models Need Inductive Biases to Count InductivelyYingshan Chang, Yonatan BiskICLR 2025
- Quantitative Bounds for Length Generalization in TransformersZachary Izzo, Eshaan Nichani, Jason D. LeeICLR 2026 · 8 citations
