TL;DR
This paper provides the first formal theoretical analysis of transformers as sequence-to-sequence transducers (string-to-string mappers) rather than simple language recognizers. By introducing new variants of the RASP programming language as an intermediate bridge, the authors map out exactly how different transformer attention mechanisms align with classic formal language transducer hierarchies. Notably, they prove that average-hard attention transformers can compute highly complex polyregular functions, while unique-hard attention is strictly limited to simpler rational transductions.
What Problem Does This Paper Address?
Most theoretical work analyzing what transformers can and cannot compute treats them as recognizers of formal languages—essentially answering a binary "yes/no" or outputting a probability for a given string (e.g., checking if a sentence is grammatically correct). However, in the real world, transformers are almost exclusively used as transducers that map an input sequence to an output sequence, such as in machine translation, text summarization, or algorithmic chain-of-thought tasks.
To bridge this gap between theory and practice, the authors establish a formal framework to evaluate the sequence-to-sequence capacity of transformer encoders. They seek to answer: Which mathematical classes of string-to-string functions can different transformer architectures inherently express?
Methods
To avoid the messy linear algebra typically required to describe transformer weights directly, the authors leverage RASP (Restricted Access Sequence Processing), a domain-specific programming language designed to mimic how transformers "think." They extend RASP to handle sequence-to-sequence functions and introduce three distinct variants:
- B-RASP: A Boolean-restricted version of RASP, modified here to support "packed outputs" so it can output strings of different lengths than the input.
- B-RASP[pos]: Extends B-RASP by allowing explicit calculations on sequence positions (like clamped addition and subtraction).
- S-RASP: Further extends B-RASP[pos] by introducing a prefix sum operator, enabling more advanced arithmetic tracking across sequences.
The authors then mathematically prove the equivalence between these RASP variants, specific transformer attention mechanisms (unique-hard attention vs. average-hard attention), and classic transducer language classes (rational, regular, and polyregular).
Datasets
Not discussed in the paper. This is a purely theoretical paper containing mathematical proofs; no empirical datasets or deep learning benchmarks were used.
Key Insights and Ideas
- Attention Type Dictates Computational Power: The exact mechanism used to select attention targets fundamentally limits or unlocks what the transformer can compute.
- The Limits of Unique-Hard Attention: In unique-hard attention, each position can only attend to a single maximum-scoring element. The authors prove this matches the exact boundary of aperiodic rational transductions—meaning they can handle tasks like string rotation or basic incrementing, but nothing more complex.
- The Power of Average-Hard Attention: If a transformer uses average-hard attention (distributing attention equally across all maximum-scoring elements), it becomes vastly more capable. Combined with a prefix sum operator (S-RASP), it can compute polyregular transductions, allowing it to perform tasks with superlinear growth, such as duplicating a string a number of times equal to its own length.
- Position Arithmetic Breaks Traditional Hierarchies: Interestingly, giving a transformer the ability to do basic arithmetic on positions (
B-RASP[pos]) allows it to compute functions likecopy-first-half(copying exactly the first half of a string). Mathematically, this function falls completely outside of traditional regular or polyregular transducer classes, showing that transformers with position encodings don't perfectly fit into historical computer science language hierarchies.
Key Results
- B-RASP $\equiv$ Aperiodic Rational Transductions: The authors prove that B-RASP with packed outputs characterizes exactly the aperiodic rational transductions. Consequently, masked unique-hard attention transformers are exactly bounded by this class.
- B-RASP[pos] $\supset$ Aperiodic Regular Transductions: B-RASP[pos] can successfully compute all aperiodic regular transductions, such as reversing or duplicating specific substrings between markers.
- S-RASP $\equiv$ Average-Hard Attention: S-RASP can compute all aperiodic polyregular transductions. Crucially, the authors prove that any transduction computable by an S-RASP program can be simulated by a masked average-hard attention transformer encoder using standard position encodings ($i/n, (i/n)^2, 1/(i+2)$).
Limitations and Future Work
- Hard Attention Abstraction: The proofs rely on hard attention (discrete, maximized selection), which is a theoretical idealization of the continuous, soft-max attention functions used in practical models like GPT-4 or BERT.
- Incomplete Characterization of Position Variants: While the authors proved that B-RASP[pos] and S-RASP contain regular and polyregular classes respectively, they actually compute more than those classes due to position arithmetic. Fully characterizing the exact upper bounds of these position-aware variants remains an open question.
- Length-Dependent Encodings: The simulation of average-hard attention relies on position encodings that scale with the total sequence length $n$. Exploring how these proofs hold up under relative or length-agnostic position encodings is a suggested path for future research.
Summary updated