Overcoming a Theoretical Limitation of Self-Attention
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 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.
62 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
- What Algorithms can Transformers Learn? A Study in Length Generalization cites Thinking Like Transformers
- What Algorithms can Transformers Learn? A Study in Length Generalization cites On the Ability and Limitations of Transformers to Recognize Formal Languages
- Thinking Like Transformers cites On the Ability and Limitations of Transformers to Recognize Formal Languages
- Thinking Like Transformers cites Are Transformers universal approximators of sequence-to-sequence functions?
- Effects of Parameter Norm Growth During Transformer Training: Inductive Bias from Gradient Descent cites On the Ability and Limitations of Transformers to Recognize Formal Languages
- Effects of Parameter Norm Growth During Transformer Training: Inductive Bias from Gradient Descent cites Are Transformers universal approximators of sequence-to-sequence functions?
- On the Ability and Limitations of Transformers to Recognize Formal Languages cites Are Transformers universal approximators of sequence-to-sequence functions?
- Exposing Attention Glitches with Flip-Flop Language Modeling cites On the Ability and Limitations of Transformers to Recognize Formal Languages
Cited by top-tier papers62
- 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
- Transformer Working Memory Enables Regular Language Reasoning And Natural Language Length ExtrapolationTa-Chung Chi, Ting-Han Fan, Alexander Rudnicky, Peter J. RamadgeEMNLP Findings 2023 · 1 citation
- Language Models Need Inductive Biases to Count InductivelyYingshan Chang, Yonatan BiskICLR 2025
