Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languages

Andy Yang, David Chiang, Dana Angluin
2/12/2026

No confident code implementation found for this paper. 1 possible match can be shown below.

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.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. 1 weaker match is hidden by default — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{yang2026masked,
  title  = {Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languages},
  author = {Andy Yang and David Chiang and Dana Angluin},
  year   = {2026},
  eprint = {2310.13897},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2310.13897},
  journal = {NEURIPS 2023 2023}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2310.13897.svg)](https://codeofpaper.com/paper/2310.13897)

Discussion