Lune

ICLR2024Top-tier venue

Logical Languages Accepted by Transformer Encoders with Hard Attention

Pablo Barceló, Alexander Kozachinskiy, Anthony Widjaja Lin, Vladimir V. Podolskii

Abstract

We contribute to the study of formal languages that can be recognized by transformer encoders. We focus on two self-attention mechanisms: (1) UHAT (Unique Hard Attention Transformers) and (2) AHAT (Average Hard Attention Transformers). UHAT encoders are known to recognize only languages inside the circuit complexity class AC0{\sf AC}^0, i.e., accepted by a family of poly-sized and depth-bounded boolean circuits with unbounded fan-ins. On the other hand, AHAT encoders can recognize languages outside AC0{\sf AC}^0), but their expressive power still lies within the bigger circuit complexity class TC0{\sf TC}^0, i.e., AC0{\sf AC}^0-circuits extended by majority gates. We first show a negative result that there is an AC0{\sf AC}^0-language that cannot be recognized by an UHAT encoder. On the positive side, we show that UHAT encoders can recognize a rich fragment of AC0{\sf AC}^0-languages, namely, all languages definable in first-order logic with arbitrary unary numerical predicates. This logic, includes, for example, all regular languages from AC0{\sf AC}^0. We then show that AHAT encoders can recognize all languages of our logic even when we enrich it with counting terms. We apply these results to derive new results on the expressive power of UHAT and AHAT up to permutation of letters (a.k.a. Parikh images).

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

20 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Characterizing the Expressivity of Fixed-Precision Transformer Language Models cites Overcoming a Theoretical Limitation of Self-Attention
  • Characterizing the Expressivity of Fixed-Precision Transformer Language Models cites Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languages
  • Characterizing the Expressivity of Fixed-Precision Transformer Language Models cites Self-Attention Networks Can Process Bounded Hierarchical Languages
  • Characterizing the Expressivity of Fixed-Precision Transformer Language Models cites On the Ability and Limitations of Transformers to Recognize Formal Languages
  • Characterizing the Expressivity of Fixed-Precision Transformer Language Models cites Tighter Bounds on the Expressivity of Transformer Encoders
  • Knee-Deep in C-RASP: A Transformer Depth Hierarchy cites Thinking Like Transformers
  • Knee-Deep in C-RASP: A Transformer Depth Hierarchy cites On the Ability and Limitations of Transformers to Recognize Formal Languages
  • Knee-Deep in C-RASP: A Transformer Depth Hierarchy cites Tighter Bounds on the Expressivity of Transformer Encoders
  • Softmax Transformers are Turing-Complete cites Thinking Like Transformers
  • Softmax Transformers are Turing-Complete cites Overcoming a Theoretical Limitation of Self-Attention
  • Thinking Like Transformers cites Self-Attention Networks Can Process Bounded Hierarchical Languages
  • Thinking Like Transformers cites On the Ability and Limitations of Transformers to Recognize Formal Languages
  • The Power of Hard Attention Transformers on Data Sequences: A formal language theoretic perspective cites Tighter Bounds on the Expressivity of Transformer Encoders
  • Overcoming a Theoretical Limitation of Self-Attention cites Thinking Like Transformers
  • Overcoming a Theoretical Limitation of Self-Attention cites On the Ability and Limitations of Transformers to Recognize Formal Languages
  • Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languages cites Thinking Like Transformers
  • Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languages cites Overcoming a Theoretical Limitation of Self-Attention
  • Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languages cites On the Ability and Limitations of Transformers to Recognize Formal Languages
  • Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languages cites Tighter Bounds on the Expressivity of Transformer Encoders
  • Tighter Bounds on the Expressivity of Transformer Encoders cites Thinking Like Transformers
  • Tighter Bounds on the Expressivity of Transformer Encoders cites Overcoming a Theoretical Limitation of Self-Attention
  • Tighter Bounds on the Expressivity of Transformer Encoders cites On the Ability and Limitations of Transformers to Recognize Formal Languages
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers20

  1. Masked Hard-Attention Transformers Recognize Exactly the Star-Free LanguagesAndy Yang, David Chiang, Dana AngluinNeurIPS 2024 · 58 citations
  2. Characterizing the Expressivity of Fixed-Precision Transformer Language ModelsJiaoda Li, Ryan CotterellNeurIPS 2025 · 18 citations
  3. Knee-Deep in C-RASP: A Transformer Depth HierarchyAndy Yang, Michaël Cadilhac, David ChiangNeurIPS 2025 · 15 citations
  4. Softmax Transformers are Turing-CompleteHongjian Jiang, Michael Hahn, Georg Zetzsche, Anthony W. LinICLR 2026 · 12 citations
  5. The Power of Hard Attention Transformers on Data Sequences: A formal language theoretic perspectivePascal Bergsträßer, Chris Köcher, Anthony Widjaja Lin, Georg ZetzscheNeurIPS 2024 · 7 citations

Builds on5

  1. Thinking Like TransformersGail Weiss, Yoav Goldberg, Eran YahavICML 2021 · 183 citations
  2. Tighter Bounds on the Expressivity of Transformer EncodersDavid Chiang, Peter Cholak, Anand PillayICML 2023 · 80 citations
  3. On the Ability and Limitations of Transformers to Recognize Formal LanguagesSatwik Bhattamishra, Kabir Ahuja, Navin GoyalEMNLP 2020 · 7 citations
  4. Overcoming a Theoretical Limitation of Self-AttentionDavid Chiang, Peter CholakACL 2022
  5. Self-Attention Networks Can Process Bounded Hierarchical LanguagesShunyu Yao, Binghui Peng, Christos H. Papadimitriou, Karthik NarasimhanACL 2021

Related papers

  1. Revisiting Padded Transformer Expressivity: Which Architectural Choices Matter and Which Don'tAnej Svete, William Merrill, Ryan Cotterell, Ashish SabharwalICML 2026 · 3 citations
  2. A Logic for Expressing Log-Precision TransformersWilliam Merrill, Ashish SabharwalNeurIPS 2023 · 87 citations
  3. Learning Linear Attention in Polynomial TimeMorris Yau, Ekin Akyürek, Jiayuan Mao, Joshua B. Tenenbaum et al.NeurIPS 2025 · 7 citations
  4. Exact Expressive Power of Transformers with PaddingWilliam Merrill, Ashish SabharwalNeurIPS 2025 · 21 citations
  5. Characterizing the Expressivity of Local Attention in TransformersJiaoda Li, Ryan CotterellACL 2026 · 2 citations
Dusk over the sea between two cliffs drawn in fine vertical lines