Table of Contents
Fetching ...

The Counting Power of Transformers

Marco Sälzer, Chris Köcher, Alexander Kozachinskiy, Georg Zetzsche, Anthony Widjaja Lin

TL;DR

This paper proves that transformers can capture all semialgebraic counting properties, i.e., expressible as a boolean combination of arbitrary multivariate polynomials (of any degree) and exhibits a natural subclass of (softmax) transformers that completely characterizes semialgebraic counting properties.

Abstract

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.

The Counting Power of Transformers

TL;DR

This paper proves that transformers can capture all semialgebraic counting properties, i.e., expressible as a boolean combination of arbitrary multivariate polynomials (of any degree) and exhibits a natural subclass of (softmax) transformers that completely characterizes semialgebraic counting properties.

Abstract

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.
Paper Structure (40 sections, 15 theorems, 14 equations, 4 figures)

This paper contains 40 sections, 15 theorems, 14 equations, 4 figures.

Key Result

Theorem 1.1

Transformers can capture all semialgebraic counting properties, i.e., those expressible as a boolean combination of inequalities between multivariate polynomials, where each variable counts the number of occurrences of a specific token in the text.

Figures (4)

  • Figure 1: Visualization of our results.
  • Figure 2: Performance of softmax transformer classifiers for $L_k$ ($k=1$ to $5$). Validation Performance (Val. Perf.): BCEWithLogitsLoss on validation data. Test Performance (Test Perf.): BCEWithLogitsLoss and Accuracy (separated by /) on test data. Generalization Performance (Gen. Perf.): BCEWithLogitsLoss and Accuracy (separated by /) on generalization test set. The y-axis uses a logarithmic scale to accommodate the different orders of magnitude in the results.
  • Figure 3: Visualization of the proof of \ref{['lem:parallel']}.
  • Figure 4: Performance of softmax transformer classifiers for $L_{i,j}$ (for a selected set of $i$ and $j$ combinations). Validation Performance (Val. Perf.): BCEWithLogitsLoss on validation data. Test Performance (Test Perf.): BCEWithLogitsLoss and Accuracy (separated by /) on test data. Generalization Performance (Gen. Perf.): BCEWithLogitsLoss and Accuracy (separated by /) on generalization test set. The y-axis uses a logarithmic scale to accommodate the different orders of magnitude in the results.

Theorems & Definitions (25)

  • Theorem 1.1
  • Theorem 1.2
  • Theorem 1.3
  • Theorem 1.4
  • Example
  • Remark
  • Remark
  • Definition 2.1
  • Proposition 3.1
  • Proposition 4.1
  • ...and 15 more