What Formal Languages Can Transformers Express? A Survey

Lena Strobl, William Merrill, Gail Weiss, David Chiang, Dana Angluin

TL;DR

This paper surveys the theoretical expressivity of transformer models, specifically focusing on what formal languages they can recognize or generate. It provides a unified framework to understand diverse findings and highlights that while transformers with intermediate steps are Turing-complete, simpler variants are limited to classes like AC⁰ or TC⁰, depending on their attention mechanisms.

What Problem Does This Paper Address?

Transformers have revolutionized Natural Language Processing (NLP), but their theoretical underpinnings, particularly their expressive power, remain an active area of research. While many studies investigate what problems transformers can solve, these often make different assumptions about the transformer architecture (e.g., attention mechanisms, positional embeddings, precision of computations). This leads to a fragmented understanding and seemingly contradictory results. This survey aims to unify these findings by providing a common framework and documenting the diverse assumptions, thereby clarifying the theoretical capabilities and limitations of transformers in relation to established computational models like automata and circuit complexity classes.

Methods

The paper provides a comprehensive survey of existing theoretical work on transformer expressivity. It achieves this by:

  • Defining a Unified Framework: The authors establish a consistent terminology and framework for describing various transformer architectures, including different types of attention (e.g., softmax, average-hard, leftmost-hard), positional embeddings, layer normalization, and network structures (encoder-only, decoder-only, encoder-decoder).
  • Categorizing Formal Models: It reviews relevant formal models such as automata (finite automata, counter machines, Turing machines), circuit complexity classes (AC⁰, TC⁰, NC¹), and formal logics (FO, LTL).
  • Systematic Survey: The core of the paper is a systematic review of research papers, organizing their claims and assumptions within the defined framework. This allows for direct comparison of different transformer variants and their expressive power relative to the formal models.
  • Analyzing Assumptions: A key contribution is the detailed documentation of the diverse assumptions made in theoretical analyses, which often explain apparent contradictions in results.

Datasets

Not discussed in the paper. This paper is a theoretical survey and does not present new experimental results or datasets.

Key Insights and Ideas

  • Intermediate Steps are Key to Turing Completeness: Transformer decoders (or encoder-decoders) that are allowed to run for an arbitrary number of intermediate steps are Turing-complete, meaning they can simulate any Turing machine. This is a significant finding, highlighting the power of autoregressive generation with sufficient computational depth.
  • Attention Mechanism Dictates Expressivity: The type of attention mechanism is a crucial determinant of a transformer's expressive power. Leftmost-hard and rightmost-hard attention are significantly less powerful, typically limited to AC⁰, while average-hard and softmax attention enable counting and can reach TC⁰.
  • Formal Languages as Benchmarks: Formal languages (like Dyck languages, PARITY, MAJORITY) serve as critical test cases for understanding transformer expressivity, allowing researchers to precisely characterize what these models can and cannot compute.
  • Assumptions Matter Greatly: Seemingly minor differences in assumptions (e.g., precision of numbers, specific positional embeddings, strict vs. non-strict masking) can lead to vastly different conclusions about a transformer's capabilities.
  • Circuit Complexity and Logic are Powerful Tools: Circuit complexity and formal logic provide effective frameworks for analyzing transformer expressivity, offering a way to precisely compare them to established computational models.

Key Results

  • Transformer decoders with intermediate steps can recognize any recursively enumerable language (Turing-complete).
  • Transformers with leftmost-hard or rightmost-hard attention are limited to recognizing languages in AC⁰.
  • Transformers with average-hard or softmax attention can recognize languages in TC⁰, but likely not problems beyond it.
  • Specific languages like PARITY and MAJORITY are shown to be outside the capabilities of certain transformer variants (e.g., those with leftmost-hard attention).

Limitations and Future Work

  • Clarifying the Impact of Variants: The paper identifies several transformer variants (PEs, attention types, normalization, special tokens) whose precise impact on expressivity is not fully clarified and suggests this as a priority for future research.
  • Tighter Characterization of Softmax/Average-Hard Attention: The expressivity of transformers with softmax and average-hard attention is still not fully understood, and the paper calls for tighter characterizations, potentially through logic.
  • Insights into Decoder-Only Models: Given the practical importance of decoder-only transformers and techniques like "chain-of-thought," further research is needed to leverage circuits or logic to gain deeper insights into their capabilities.
  • Practical Implications of Theoretical Findings: The paper notes that while theoretical results often focus on unbounded lengths, practical applications are limited by finite context windows. Bridging this gap and understanding how theoretical limitations manifest in practice remains an open area.
  • Precision and Uniformity: The impact of numerical precision and parameter uniformity on expressivity is an area for future formalization and research.

Summary updated

BibTeX
@article{strobl2024what,
  author = {Lena Strobl and William Merrill and Gail Weiss and David Chiang and Dana Angluin},
  title = {{What Formal Languages Can Transformers Express? A Survey}},
  journal = {Trans. Assoc. Comput. Linguistics},
  year = {2024},
  doi = {10.1162/tacl\_a\_00663},
}
Figure