[Theoretical Milestone] Attention is Turing Complete: Proving the Computational Hegemony of Transformers

Attention is Turing-Complete

2021-01-01
Jorge Pérez, Pablo Barceló, Javier Marinkovic
Summary
Problem
Method
Results
Takeaways
Abstract

The paper proves that the Transformer architecture is Turing complete by demonstrating its ability to simulate a Turing machine. It focuses on the "hard-attention" variant and shows that with arbitrary precision and positional encodings, Transformers can recognize any decidable language.

TL;DR

Is the Transformer just a powerful pattern matcher, or is it a universal computer? This seminal paper provides the mathematical proof: The Transformer is Turing Complete. By utilizing "hard-attention" and arbitrary precision, the authors demonstrate that a Transformer can simulate any Turing Machine, effectively placing it in the same league as Recurrent Neural Networks (RNNs) in the hierarchy of computation.

Background: The Order-Invariance Trap

Historically, Transformers were perceived as "weaker" than RNNs for certain tasks because the standard attention mechanism is order-invariant. If you permute the input sequence, the output remains the same (effectively treating the data as a "bag of words").

The authors point out a more severe limitation they call Proportion Invariance. Without positional encodings, a Transformer cannot distinguish between strings that have the same ratio of characters (e.g., "aabb" and "aaabbb"). This means a vanilla Transformer cannot even solve a simple "parity" problem—determining if the number of 'a's in a string is even.

The Breakthrough: Simulating the Tape

To prove Turing completeness, the authors constructed a specific Transformer instance that mimics the mechanics of a Turing Machine (TM). The key ingredients are:

  1. Arbitrary Precision: Storing state and tape information as rational numbers with no bit-limit.
  2. Positional Encodings: Using to allow the model to "index" specific memory cells.
  3. Hard Attention: Using a hardmax function instead of softmax to retrieve exactly one "cell" from the sequence at a time.

The Architecture of a Simulation

The authors designed a system where:

  • Encoder: Encodes the initial input string into a set of keys and values representing the TM tape.
  • Decoder Layers:
    • Layer 1: Simulates the TM's transition function , updating the internal state and the written symbol.
    • Layer 2: Computes the new head position ().
    • Layer 3: "Re-reads" the tape by attending to the last time steps to see what symbol was previously written at the current head position.

High-level structure of the decoder part of TransM

Deep Dive: Why "Hard" Attention?

Most practitioners use softmax (soft attention) for differentiability. However, for a formal proof of Turing Completeness, the model must be able to address a single, specific cell on the tape without "leakage" from neighboring cells. The paper uses a scoring function to ensure that the attention focuses solely on the index where the dot product is closest to zero.

Experiments & Symbolic Results

While this is a theoretical paper, the "results" are mathematical proofs (theorems).

  • Theorem 6: Formally states that Transformers with positional encodings are Turing Complete.
  • Corollary 12: Establishes that if we bound the precision to bits, the Transformer can capture the complexity class TIME(), including P and EXPTIME.

Critical Insight: Theory vs. Practice

The authors acknowledge a massive caveat: their proof relies on arbitrary precision. In the real world, hardware is limited to 16, 32, or 64-bit floats.

"If fixed precision is used, then positional encodings... just increase the size of the input alphabet... the Transformer with positional encodings and fixed precision is not Turing complete."

This highlights a fascinating friction between the "infinite" potential of the Transformer architecture and the "finite" constraints of the silicon it runs on.

Conclusion

This paper serves as the "Church-Turing Thesis" for the Transformer era. It proves that there is no algorithmic task too complex for the architecture to handle in principle. However, it also clarifies that the secret sauce of the Transformer—what makes it a "computer" rather than just a "calculator"—is its ability to manipulate internal dense representations and access them via attention.

The next frontier? Proving whether these properties hold under the more common, albeit theoretically "messier," softmax attention.

Find Similar Papers

Try Our Examples

  • Search for recent papers investigating the Turing completeness or computational limits of Transformers using soft-attention (softmax) instead of hard-attention.
  • Which paper first proposed the "Siegelmann and Sontag" framework for neural network Turing completeness, and how does this paper's simulation of a Turing machine tape differ from the original RNN simulation?
  • Explore research that applies the theoretical insights of Transformer Turing completeness to improve "Neural Execution Engines" or algorithmic reasoning tasks in practical AI models.
Contents
[Theoretical Milestone] Attention is Turing Complete: Proving the Computational Hegemony of Transformers
1. TL;DR
2. Background: The Order-Invariance Trap
3. The Breakthrough: Simulating the Tape
3.1. The Architecture of a Simulation
4. Deep Dive: Why "Hard" Attention?
5. Experiments & Symbolic Results
6. Critical Insight: Theory vs. Practice
7. Conclusion