The Counting Power of Transformers

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Sälzer, Marco, Köcher, Chris, Kozachinskiy, Alexander, Zetzsche, Georg, Lin, Anthony Widjaja
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866911477187739648
author Sälzer, Marco
Köcher, Chris
Kozachinskiy, Alexander
Zetzsche, Georg
Lin, Anthony Widjaja
author_facet Sälzer, Marco
Köcher, Chris
Kozachinskiy, Alexander
Zetzsche, Georg
Lin, Anthony Widjaja
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2505_11199
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle The Counting Power of Transformers
Sälzer, Marco
Köcher, Chris
Kozachinskiy, Alexander
Zetzsche, Georg
Lin, Anthony Widjaja
Computation and Language
Formal Languages and Automata Theory
Machine Learning
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.
title The Counting Power of Transformers
topic Computation and Language
Formal Languages and Automata Theory
Machine Learning
url https://arxiv.org/abs/2505.11199