Lune

EMNLP2020Top-tier venue

On the Ability and Limitations of Transformers to Recognize Formal Languages

Satwik Bhattamishra, Kabir Ahuja, Navin Goyal

Abstract

Transformers have supplanted recurrent models in a large number of NLP tasks. However, the differences in their abilities to model different syntactic properties remain largely unknown. Past works suggest that LSTMs generalize very well on regular languages and have close connections with counter languages. In this work, we systematically study the ability of Transformers to model such languages as well as the role of its individual components in doing so. We first provide a construction of Transformers for a subclass of counter languages, including well-studied languages such as n-ary Boolean Expressions, Dyck-1, and its generalizations. In experiments, we find that Transformers do well on this subclass, and their learned mechanism strongly correlates with our construction. Perhaps surprisingly, in contrast to LSTMs, Transformers do well only on a subset of regular languages with degrading performance as we make languages more complex according to a well-known measure of complexity. Our analysis also provides insights on the role of self-attention mechanism in modeling certain behaviors and the influence of positional encoding schemes on the learning and generalization abilities of the model.

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.

109 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

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 What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • Thinking Like Transformers cites A Formal Hierarchy of RNN Architectures
  • Thinking Like Transformers cites Are Transformers universal approximators of sequence-to-sequence functions?
  • Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection cites Thinking Like Transformers
  • Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection cites Are Transformers universal approximators of sequence-to-sequence functions?
  • Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • Learning to Encode Position for Transformer with Continuous Dynamical Model cites Are Transformers universal approximators of sequence-to-sequence functions?
  • Towards Revealing the Mystery behind Chain of Thought: A Theoretical Perspective cites Thinking Like Transformers
  • Towards Revealing the Mystery behind Chain of Thought: A Theoretical Perspective cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
  • Towards Revealing the Mystery behind Chain of Thought: A Theoretical Perspective cites Are Transformers universal approximators of sequence-to-sequence functions?
  • Towards Revealing the Mystery behind Chain of Thought: A Theoretical Perspective cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites Thinking Like Transformers
  • What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites Are Transformers universal approximators of sequence-to-sequence functions?
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers109

  1. What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 citations
  2. Towards Revealing the Mystery behind Chain of Thought: A Theoretical PerspectiveGuhao Feng, Bohang Zhang, Yuntian Gu, Haotian Ye et al.NeurIPS 2023 · 470 citations
  3. Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm SelectionYu Bai, Fan Chen, Huan Wang, Caiming Xiong et al.NeurIPS 2023 · 356 citations
  4. What Algorithms can Transformers Learn? A Study in Length GeneralizationHattie Zhou, Arwen Bradley, Etai Littwin, Noam Razin et al.ICLR 2024 · 189 citations
  5. Thinking Like TransformersGail Weiss, Yoav Goldberg, Eran YahavICML 2021 · 183 citations

Builds on3

  1. 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
  2. Learning to Encode Position for Transformer with Continuous Dynamical ModelXuanqing Liu, Hsiang-Fu Yu, Inderjit S. Dhillon, Cho-Jui HsiehICML 2020 · 139 citations
  3. A Formal Hierarchy of RNN ArchitecturesWilliam Merrill, Gail Weiss, Yoav Goldberg, Roy Schwartz et al.ACL 2020 · 6 citations

Related papers

  1. Simplicity Bias in Transformers and their Ability to Learn Sparse Boolean FunctionsSatwik Bhattamishra, Arkil Patel, Varun Kanade, Phil BlunsomACL 2023 · 7 citations
  2. How Can Self-Attention Networks Recognize Dyck-n Languages?Javid Ebrahimi, Dhruv Gelda, Wei ZhangEMNLP Findings 2020 · 13 citations
  3. Not all quantifiers are equal: Probing Transformer-based language models' understanding of generalised quantifiersTharindu Madusanka, Iqra Zahid, Hao Li, Ian Pratt-Hartmann et al.EMNLP 2023 · 2 citations
  4. Characterizing the Expressivity of Fixed-Precision Transformer Language ModelsJiaoda Li, Ryan CotterellNeurIPS 2025 · 18 citations
  5. Separations in the Representational Capabilities of Transformers and Recurrent ArchitecturesSatwik Bhattamishra, Michael Hahn, Phil Blunsom, Varun KanadeNeurIPS 2024 · 36 citations
Dusk over the sea between two cliffs drawn in fine vertical lines