Characterizing the Expressivity of Transformer Language Models

Jiaoda Li, Ryan Cotterell · DOI

Introduction

While Transformers have become the backbone of modern artificial intelligence, a rigorous theoretical understanding of their computational limits has remained elusive. Previous studies often analyzed idealized versions of the architecture, assuming infinite numerical precision or "hard" attention mechanisms. This paper provides the first exact theoretical characterization of fixed-precision Transformer language models using soft attention and no positional encodings (NoPE). The authors demonstrate that these realistic constraints significantly restrict the model's expressivity, aligning it with specific fragments of formal logic and automata theory.

Theoretical Framework: Logic and Automata Equivalence

The core contribution of this work is the proof that NoPE Transformers are mathematically equivalent to a specific fragment of linear temporal logic, LTL[P] (Linear Temporal Logic using only the "past" operator), and Partially Ordered Deterministic Finite Automata (PODFAs).

Extracted figure from page 2 of Characterizing the Expressivity of Transformer Language Models

The researchers established this connection through several key steps:

  1. Logic Equivalence: They introduced PFO²[<], a fragment of first-order logic with two variables restricted to the past, and proved its equivalence to LTL[P].
  2. Simulation Proofs: A constructive proof showed that any Transformer under these constraints can be translated into a PFO²[<] formula, and conversely, any LTL[P] formula can be simulated by a Transformer.
  3. Overcoming Underflow: To address the "limited attention span" caused by fixed-precision soft attention (where weights for distant tokens underflow to zero), the authors proposed a multi-layer "patching" strategy. This allows the model to aggregate information across layers to maintain a signal from the distant past.
  4. Algebraic Connections: The models were linked to $\mathcal{R}$-trivial monoids and left-deterministic polynomials, which are well-studied classes in algebraic automata theory.

Empirical Validation

To validate these theoretical findings, the authors tested Transformers on a suite of synthetic formal languages categorized by their complexity. These included Counter languages ($a^nb^n$), Regular languages (PARITY), Star-free languages (DYCK-1,1), and Left-deterministic polynomials (FIRST, PT-2).

Empirical results comparing Transformer and LSTM performance across various formal language classes.

The results, summarized in the table above, show a perfect alignment with the theory. Transformers achieved 100% accuracy on languages within the LTL[P] class (e.g., PT-2, FIRST) even when generalizing to sequences much longer than those seen during training. However, they consistently failed on languages outside this class, such as Parity or Dyck-1,1, where accuracy dropped to near-chance levels on long sequences. Notably, LSTMs outperformed Transformers on these specific tasks, highlighting the structural limitations of the attention mechanism without positional information.

Key Insights and Limitations

The equivalence to PODFAs provides an intuitive understanding of Transformer limitations: in a PODFA, once a state is exited, it can never be re-entered. This "no-return" rule implies that NoPE Transformers are fundamentally "forgetful" of cyclical patterns and struggle with tasks requiring state-tracking like parity checking or nested parentheses.

Furthermore, the study reveals that soft attention under fixed precision is actually less expressive than "unique hard attention." While hard attention can theoretically point to any single distant token, soft attention's "budget" is spread thin, eventually losing sight of distant tokens in long sequences.

Future Directions

This characterization focuses on decoder-only models without positional encodings. The authors suggest that the impressive capabilities of modern LLMs likely stem from the "numerical predicates" introduced by positional encodings (like RoPE or Alibi) or specific patterns in training data that bypass these theoretical bounds. Future work will aim to incorporate these encodings into the formal framework to better understand the full power of the Transformer architecture.

Summary updated

BibTeX
@inproceedings{li2025characterizing,
  author = {Jiaoda Li and Ryan Cotterell},
  title = {{Characterizing the Expressivity of Transformer Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=29LwAgLFpj},
}
Figure