English

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

Formal Languages and Automata Theory 2024-10-31 v4 Machine Learning Logic in Computer Science

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.

Keywords

Cite

@article{arxiv.2310.13897,
  title  = {Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languages},
  author = {Andy Yang and David Chiang and Dana Angluin},
  journal= {arXiv preprint arXiv:2310.13897},
  year   = {2024}
}

Comments

NeurIPS 2024

R2 v1 2026-06-28T12:57:27.357Z