mlsanityData to 14 Oct 2026

The Counting Power of Transformers

arXiv 2505.11199 ↗First posted 16 May 2025cs.CL cs.FL cs.LGcited by 9

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

  1. 2017Attention Is All You Needcited by 60,361
  2. 2019Theoretical Limitations of Self-Attention in Neural Sequence Modelscited by 288
  3. 2022Neural Networks and the Chomsky Hierarchycited by 217
  4. 2022Exploring Length Generalization in Large Language Modelscited by 206
  5. 2023What Algorithms can Transformers Learn? A Study in Length Generalizationcited by 199
  6. 2022The Parallelism Tradeoff: Limitations of Log-Precision Transformerscited by 193
  7. 2023What Formal Languages Can Transformers Express? A Surveycited by 124
  8. 2022Overcoming a Theoretical Limitation of Self-Attentioncited by 113
  9. 2022Formal Language Recognition by Hard Attention Transformers: Perspectives from Circuit Complexitycited by 93
  10. 2024Why are Sensitive Functions Hard for Transformers?cited by 74
  11. 2022A Logic for Expressing Log-Precision Transformerscited by 67
  12. 2023Masked Hard-Attention Transformers Recognize Exactly the Star-Free Languagescited by 49
6 more
  1. 2024A Formal Framework for Understanding Length Generalization in Transformerscited by 45
  2. 2024Counting Like Transformers: Compiling Temporal Counting Logic Into Softmax Transformerscited by 39
  3. 2023Logical Languages Accepted by Transformer Encoders with Hard Attentioncited by 38
  4. 2024Simulating Hard Attention Using Soft Attentioncited by 15
  5. 2018Text Similarity in Vector Space Models: A Comparative Studycited by 13
  6. 2024Transformer Encoder Satisfiability: Complexity and Impact on Formal Reasoningcited by 5

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 2; 2026: 7.

9 papers.