The Counting Power of Transformers
Not on the map. Why?
Abstract (arXiv)
Counting properties (e.g. determining whether certain tokens occur more than other tokens in a given input text) have played a significant role in the study of expressiveness of transformers. In this paper, we provide a formal framework for investigating the counting power of transformers. We argue that all existing results demonstrate transformers' expressivity only for (semi-)linear counting properties, i.e., which are expressible as a boolean combination of linear inequalities. Our main result is that transformers can express counting properties that are highly nonlinear. More precisely, we prove that transformers can capture all semialgebraic counting properties, i.e., expressible as a boolean combination of arbitrary multivariate polynomials (of any degree). Among others, these generalize the counting properties that can be captured by C-RASP softmax transformers, which capture only linear counting properties. To complement this result, we exhibit a natural subclass of (softmax) transformers that completely characterizes semialgebraic counting properties. Through connections with the Hilbert's tenth problem, this expressivity of transformers also yields a new undecidability result for analyzing an extremely simple transformer model -- surprisingly with neither positional encodings (i.e. NoPE-transformers) nor masking. We also experimentally validate trainability of such counting properties.
Key facts. Cited by 9 papers in the map (data through 14 Oct 2026). Builds on 18 of its 33 references that are in the map. First posted on arXiv 16 May 2025.
Builds on
18 of 33 references.
References · 18
- 2017Attention Is All You Needcited by 60,361
- 2019Theoretical Limitations of Self-Attention in Neural Sequence Modelscited by 288
- 2022Neural Networks and the Chomsky Hierarchycited by 217
- 2022Exploring Length Generalization in Large Language Modelscited by 206
- 2023What Algorithms can Transformers Learn? A Study in Length Generalizationcited by 199
- 2022The Parallelism Tradeoff: Limitations of Log-Precision Transformerscited by 193
- 2023What Formal Languages Can Transformers Express? A Surveycited by 124
- 2022Overcoming a Theoretical Limitation of Self-Attentioncited by 113
- 2022Formal Language Recognition by Hard Attention Transformers: Perspectives from Circuit Complexitycited by 93
- 2024Why are Sensitive Functions Hard for Transformers?cited by 74
- 2022A Logic for Expressing Log-Precision Transformerscited by 67
- 2023Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languagescited by 49
6 more
- 2024A Formal Framework for Understanding Length Generalization in Transformerscited by 45
- 2024Counting Like Transformers: Compiling Temporal Counting Logic Into Softmax Transformerscited by 39
- 2023Logical Languages Accepted by Transformer Encoders with Hard Attentioncited by 38
- 2024Simulating Hard Attention Using Soft Attentioncited by 15
- 2018Text Similarity in Vector Space Models: A Comparative Studycited by 13
- 2024Transformer Encoder Satisfiability: Complexity and Impact on Formal Reasoningcited by 5
Built on by
Citing papers per year: 2025: 2; 2026: 7.
9 papers.
- 2025Transformers are Inherently Succinctcited by 4
- 2026Length Generalization Bounds for Transformerscited by 4
- 2026Indexing: the Beginning and the Endcited by 2
- 2025The Role of Logic and Automata in Understanding Transformerscited by 1
- 2026Synthesis and Verification of Transformer Programs (Technical Report)cited by 0
- 2026Rethinking the Role of Positional Encoding: Sliding-Window Transformers without PE Remain Turing Completecited by 0
- 2026Checking Leakage Witnesses versus Certifying Bounded Non-Leakagecited by 0
- 2026Repetition, Not Length: Isolating the Counting Failure in Neural Text-to-Speechcited by 0
- 2026Counting with Attention and LayerNorm: Norm Scaling and Representation Geometrycited by 0
- 2026Counting with Attention and LayerNorm: Norm Scaling and Representation Geometry12 Oct 2026
- 2026Repetition, Not Length: Isolating the Counting Failure in Neural Text-to-Speech29 Sep 2026
- 2026Checking Leakage Witnesses versus Certifying Bounded Non-Leakage26 Sep 2026
- 2026Indexing: the Beginning and the End24 Jul 2026
- 2026Rethinking the Role of Positional Encoding: Sliding-Window Transformers without PE Remain Turing Complete1 Jun 2026
- 2026Synthesis and Verification of Transformer Programs (Technical Report)18 Feb 2026
- 2026Length Generalization Bounds for Transformers13 Feb 2026
- 2025Transformers are Inherently Succinct22 Oct 2025
- 2025The Role of Logic and Automata in Understanding Transformers28 Sep 2025