On the Ability and Limitations of Transformers to Recognize Formal Languages
Not on the map. Why?
Abstract (arXiv)
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.
Key facts. Cited by 12 papers in the map (data through 7 Oct 2026). First posted on arXiv 23 Sep 2020.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2021: 4; 2022: 1; 2023: 1; 2024: 5; 2025: 0; 2026: 1.
12 papers.
- 2023Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selectioncited by 291
- 2021Self-Attention Networks Can Process Bounded Hierarchical Languagescited by 105
- 2021On the Expressive Power of Self-Attention Matricescited by 44
- 2024Language Models Need Inductive Biases to Count Inductivelycited by 25
- 2024How Numerical Precision Affects Arithmetical Reasoning Capabilities of LLMscited by 24
- 2024In-Context Learning with Transformers: Softmax Attention Adapts to Function Lipschitznesscited by 22
- 2024Transformers Provably Learn Sparse Token Selection While Fully-Connected Nets Cannotcited by 21
- 2021Formal Language Theory Meets Modern NLPcited by 9
- 2022What Makes Instruction Learning Hard? An Investigation and a New Challenge in a Synthetic Environmentcited by 9
- 2021Learning Bounded Context-Free-Grammar via LSTM and the Transformer:Difference and Explanationscited by 7
- 2024Stability Analysis of Various Symbolic Rule Extraction Methods from Recurrent Neural Networkcited by 3
- 2026An expressivity analysis of hierarchical modelling in deep transformers via bounded-depth grammarscited by 1
- 2026An expressivity analysis of hierarchical modelling in deep transformers via bounded-depth grammars16 Jun 2026
- 2024How Numerical Precision Affects Arithmetical Reasoning Capabilities of LLMs17 Oct 2024
- 2024Transformers Provably Learn Sparse Token Selection While Fully-Connected Nets Cannot11 Jun 2024
- 2024Language Models Need Inductive Biases to Count Inductively30 May 2024
- 2024In-Context Learning with Transformers: Softmax Attention Adapts to Function Lipschitzness18 Feb 2024
- 2024Stability Analysis of Various Symbolic Rule Extraction Methods from Recurrent Neural Network4 Feb 2024
- 2023Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection7 Jun 2023
- 2022What Makes Instruction Learning Hard? An Investigation and a New Challenge in a Synthetic Environment19 Apr 2022
- 2021Learning Bounded Context-Free-Grammar via LSTM and the Transformer:Difference and Explanations16 Dec 2021
- 2021On the Expressive Power of Self-Attention Matrices7 Jun 2021
- 2021Self-Attention Networks Can Process Bounded Hierarchical Languages24 May 2021
- 2021Formal Language Theory Meets Modern NLP19 Feb 2021