Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languages
Andy Yang, David Chiang, Dana Angluin
TL;DR
This work provides exact characterizations of transformer expressivity under hard attention and masking by establishing an equivalence with $LTL$ and the class of $star-free$ regular languages, using $B$-$RASP$ as a practical intermediate representation. By proving mutual translations between BRASP, masked hard-attention transformers, and $LTL$, the authors transfer decades of logical and automata-theoretic results to transformer architectures, enabling depth and position-embedding analyses. Key contributions include a depth-preserving correspondence, a depth hierarchy showing increasing power with layers, and precise results for variant settings such as strict vs. non-strict masking and sinusoidal versus arbitrary position embeddings. The findings illuminate the limits and capabilities of transformer-like models for formal-language tasks, with implications for architectural design and theoretical understanding of expressivity in sequence modeling.
Abstract
The expressive power of transformers over inputs of unbounded size can be studied through their ability to recognize classes of formal languages. In this paper, we establish exact characterizations of transformers with hard attention (in which all attention is focused on exactly one position) and attention masking (in which each position only attends to positions on one side). With strict masking (each position cannot attend to itself) and without position embeddings, these transformers are expressively equivalent to linear temporal logic (LTL), which defines exactly the star-free languages. A key technique is the use of Boolean RASP as a convenient intermediate language between transformers and LTL. We then take numerous results known for LTL and apply them to transformers, showing how position embeddings, strict masking, and depth all increase expressive power.
