Learning Bounded Context-Free-Grammar via LSTM and the Transformer:Difference and Explanations
Not on the map. Why?
Abstract (arXiv)
Long Short-Term Memory (LSTM) and Transformers are two popular neural architectures used for natural language processing tasks. Theoretical results show that both are Turing-complete and can represent any context-free language (CFL).In practice, it is often observed that Transformer models have better representation power than LSTM. But the reason is barely understood. We study such practical differences between LSTM and Transformer and propose an explanation based on their latent space decomposition patterns. To achieve this goal, we introduce an oracle training paradigm, which forces the decomposition of the latent representation of LSTM and the Transformer and supervises with the transitions of the Pushdown Automaton (PDA) of the corresponding CFL. With the forced decomposition, we show that the performance upper bounds of LSTM and Transformer in learning CFL are close: both of them can simulate a stack and perform stack operation along with state transitions. However, the absence of forced decomposition leads to the failure of LSTM models to capture the stack and stack operations, while having a marginal impact on the Transformer model. Lastly, we connect the experiment on the prototypical PDA to a real-world parsing task to re-verify the conclusions
Key facts. Cited by 7 papers in the map (data through 7 Oct 2026). Builds on 21 of its 34 references that are in the map. First posted on arXiv 16 Dec 2021.
Builds on
21 of 34 references.
References · 21
- 2017Attention Is All You Needcited by 59,932
- 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2014Sequence to Sequence Learning with Neural Networkscited by 2,974
- 2017Multi-Task Learning Using Uncertainty to Weigh Losses for Scene Geometry and Semanticscited by 1,345
- 2014Neural Turing Machinescited by 630
- 2018Universal Transformerscited by 613
- 2019Theoretical Limitations of Self-Attention in Neural Sequence Modelscited by 286
- 2019On the Turing Completeness of Modern Neural Network Architecturescited by 129
- 2018On the Practical Computational Power of Finite Precision RNNs for Language Recognitioncited by 117
- 2015Inferring Algorithmic Patterns with Stack-Augmented Recurrent Netscited by 76
- 2020RNNs can generate bounded hierarchical languages with optimal memorycited by 59
9 more
- 2019LSTM Networks Can Perform Dynamic Countingcited by 45
- 2019On the Computational Power of RNNscited by 35
- 2019Memory-Augmented Recurrent Neural Networks Can Learn Generalized Dyck Languagescited by 31
- 2020On the Practical Ability of Recurrent Neural Networks to Recognize Hierarchical Languagescited by 22
- 2018Evaluating the Ability of LSTMs to Learn Context-Free Grammarscited by 16
- 2018Connecting Weighted Automata and Recurrent Neural Networks through Spectral Learningcited by 15
- 2018Context-Free Transductions with Neural Stackscited by 14
- 2020On the Ability and Limitations of Transformers to Recognize Formal Languagescited by 12
- 2019Representing Formal Languages: A Comparison Between Finite Automata and Recurrent Neural Networkscited by 9
Built on by
Citing papers per year: 2022: 1; 2023: 3; 2024: 1; 2025: 2.
7 papers.
- 2023Physics of Language Models: Part 1, Learning Hierarchical Language Structurescited by 83
- 2024A Survey on Compositional Learning of AI Models: Theoretical and Experimental Practicescited by 15
- 2023In-Context Learning Dynamics with Random Binary Sequencescited by 13
- 2023LUNA: A Model-Based Universal Analysis Framework for Large Language Modelscited by 4
- 2022Everyone's Preference Changes Differently: Weighted Multi-Interest Retrieval Modelcited by 2
- 2025On the Existence of Universal Simulators of Attentioncited by 1
- 2025Rethinking Memorization Measures and their Implications in Large Language Modelscited by 1
- 2025Rethinking Memorization Measures and their Implications in Large Language Models20 Jul 2025
- 2025On the Existence of Universal Simulators of Attention23 Jun 2025
- 2024A Survey on Compositional Learning of AI Models: Theoretical and Experimental Practices13 Jun 2024
- 2023In-Context Learning Dynamics with Random Binary Sequences26 Oct 2023
- 2023LUNA: A Model-Based Universal Analysis Framework for Large Language Models22 Oct 2023
- 2023Physics of Language Models: Part 1, Learning Hierarchical Language Structures23 May 2023
- 2022Everyone's Preference Changes Differently: Weighted Multi-Interest Retrieval Model14 Jul 2022