TL;DR
This paper establishes a precise theoretical equivalence between a specific type of transformer (masked hard-attention) and linear temporal logic (LTL), showing they both recognize exactly the "star-free" class of formal languages. This provides a powerful new lens for understanding transformer capabilities and opens the door to applying decades of formal language theory to neural network architectures.
What Problem Does This Paper Address?
Transformers, with their self-attention mechanisms, have revolutionized NLP and beyond. However, understanding their precise expressive power – what kinds of problems they can truly solve – remains a significant theoretical challenge. While many studies provide upper or lower bounds on transformer capabilities, exact characterizations are rare. This paper tackles this by focusing on simplified, yet theoretically significant, variants of transformers: those with "hard attention" (where attention focuses on a single position) and "strict future masking" (where a position can only attend to preceding positions). The authors aim to precisely define the class of languages these restricted transformers can recognize, connecting them to well-established formalisms like Linear Temporal Logic (LTL).
Methods
The core of the paper lies in establishing equivalences between three formalisms:
- Masked Hard-Attention Transformers: These are simplified transformers where each attention head focuses on exactly one position (hard attention) and can only attend to positions to its left (strict future masking). They also omit position embeddings and layer normalization in their base definition.
- Boolean RASP (B-RASP): A novel intermediate programming language designed to mimic transformer operations but restricted to Boolean values. B-RASP is crucial because it can be compiled into masked hard-attention transformers and vice-versa, acting as a bridge.
- Linear Temporal Logic (LTL): A formal logic used to describe properties of sequences over time. The paper specifically leverages LTL formulas that define star-free languages.
The authors prove bidirectional equivalences:
- B-RASP to Transformers: They show how to construct a masked hard-attention transformer that simulates any B-RASP program.
- Transformers to B-RASP: They demonstrate how to translate the computations of a masked hard-attention transformer into a B-RASP program.
- LTL to B-RASP: They provide a direct construction from LTL formulas (defining star-free languages) to B-RASP programs.
- B-RASP to LTL: They show that any B-RASP program can be represented by an LTL formula.
By establishing these chains of equivalences (LTL <=> B-RASP <=> Masked Hard-Attention Transformers), they achieve the main goal of characterizing the expressive power of these transformers. They also explore the impact of adding position embeddings, multi-head attention, and different masking strategies.
Datasets
Not discussed in the paper. The paper focuses on theoretical characterizations of formal language classes, not empirical evaluation on specific datasets.
Key Insights and Ideas
- Star-Free Languages as the Rosetta Stone: The paper reveals that the star-free languages, a well-understood class in formal language theory, are precisely what masked hard-attention transformers (without position embeddings) can recognize. This is a significant theoretical result, providing an exact characterization.
- B-RASP as a Powerful Intermediate: The introduction of Boolean RASP proves to be a highly effective tool. Its ability to be compiled to and from transformers, while being closely related to LTL, simplifies the complex proofs of equivalence.
- Hard Attention and Strict Masking are Key: The paper highlights that the combination of hard attention and strict future masking is what limits the expressive power to exactly the star-free languages. This suggests that these specific architectural choices have profound implications for what a model can learn.
- Position Embeddings Unlock More Power: Adding position embeddings, even simple ones, significantly increases the expressive power of these transformers, allowing them to recognize more complex language classes, including regular languages and even languages definable by LTL with monadic predicates.
- Depth Matters (and is Hierarchical): The paper demonstrates that increasing the depth (number of layers) of these transformers strictly increases their expressive power, establishing a clear hierarchy.
Key Results
- Exact Equivalence: Masked hard-attention transformers with strict future masking (and no position embeddings) are shown to be exactly equivalent in expressive power to Linear Temporal Logic (LTL) formulas that define star-free languages.
- B-RASP Equivalence: Boolean RASP programs are shown to be equivalent to both LTL and masked hard-attention transformers.
- Impact of Position Embeddings:
- With rational sinusoidal position embeddings, transformers recognize exactly the regular languages in AC⁰.
- With arbitrary finite-image position embeddings, they are equivalent to LTL with monadic predicates.
- Depth Hierarchy: Adding more layers to masked hard-attention transformers strictly increases their expressive power.
- Non-strict Masking Reduces Expressivity: Transformers with non-strict masking recognize only stutter-invariant star-free languages, a subset of the star-free languages.
Limitations and Future Work
- Focus on Simplified Transformers: The results are for highly simplified transformer variants (hard attention, strict masking, no position embeddings in the base case). The authors acknowledge that these results do not directly apply to standard softmax-attention transformers or transformers with unmasked attention.
- Standard Definition of Position Embeddings: The paper's restriction of sinusoidal position embeddings to rational angles deviates slightly from the standard definition, though they argue it doesn't fundamentally change the characterization for AC⁰.
- Future Work: The authors suggest that their work provides a foundation for understanding softmax-attention transformers and transformers with unmasked attention. They also highlight the interesting parallels between how strict masking in hard attention and the addition of BOS tokens in soft attention enable distinguishing positions, suggesting this is a fruitful area for future investigation. The paper also opens avenues for applying formal language theory results to understand transformer behavior more broadly.
Summary updated