Transformer Heads Looking for Order

Jasper van Doornmalen, Alexander Kozachinskiy, Corinna Mathwieser, Tomasz Steifer, Felipe Urrutia, José Verschae, Przemysław Andrzej WałȩgaarXiv 2026

TL;DR

This paper proves a strict theoretical separation in expressivity based on the number of attention heads in a transformer. The authors show that a 1-layer, 1-head transformer with an output MLP cannot determine if a binary string is ordered (i.e., all 0s appear before all 1s), whereas a 1-layer, 2-head transformer can easily solve this task.

What Problem Does This Paper Address?

While transformers have achieved massive empirical success, understanding their theoretical boundaries—specifically how architectural choices like the number of attention heads impact what they can compute—remains an active area of research.

Previous studies demonstrated that increasing the number of attention heads increases a model's capacity to solve tasks like computing parity. However, those older proofs focused on "attention-only" models that lacked the standard position-wise Feed-Forward Network (or output MLP). When an output MLP is included, those specific limitations disappear because the MLP can simply memorize the answers for fixed-length inputs.

This paper addresses this gap by analyzing a more realistic transformer model (one with an output MLP) evaluating an arbitrary-length language problem: ORDERED. The goal is to determine whether a binary sequence of any length is sorted (e.g., 000111 is ordered, but 001011 is not).

Methods

The authors approach the problem from both sides, providing an upper-bound construction and a lower-bound impossibility proof:

  • The 2-Head Upper Bound (Success): The authors constructively prove that two heads are sufficient. They design a 1-layer, 2-head transformer where Head 1 focuses on finding the position of the last 0 ($i_0$) and Head 2 finds the position of the first 1 ($i_1$). The output MLP then acts as a coordinator, verifying if the two positions are perfectly adjacent ($i_0 + 1 = i_1$) or handling uniform edge cases (all 0s or all 1s). This approach utilizes a simple, length-independent additive positional encoding ($i$ and $i^2$).
  • The 1-Head Lower Bound (Impossibility): To prove a single head fails, the authors embed the behavior of a 1-head transformer into the first-order theory of reals with addition and order $(\mathbb{R}, <, +)$. Crucially, they observe that because there is only one attention head, they can clear out the softmax denominators across linear inequalities without needing multiplication. They then apply a geometric lemma combined with the Ramsey theorem for hypergraphs to show that a 1-head model would require an infinite number of linear inequalities (halfspaces) to separate ordered vs. non-ordered binary vectors as the sequence length grows to infinity.

To illustrate how the lower bound handles structured sequences, the proof analyzes blocks of binary vectors to find matching patterns, as shown in the structural matrix below:

Extracted table showing the block structure of vectors used in the lower bound proof

Datasets

Not discussed in the paper. This is a purely theoretical mathematical paper and does not use empirical training datasets or benchmarks.

Key Insights and Ideas

  • Divide and Conquer via Attention Heads: The core "aha moment" is that checking for order requires identifying two distinct landmarks simultaneously (the boundary where 0 ends and 1 begins). A single head can only track one soft-max maximized landmark effectively across arbitrary lengths, whereas two heads can divide the labor.
  • The Simplification of Single-Head Proofs: In multi-head transformers, different heads produce different denominators in their attention mechanisms, forcing researchers to use complex polynomial multiplications to clear fractions in proofs. The authors realized that for a single head, there is only one common denominator, meaning multiplications can be completely avoided. This allows the use of simpler linear frameworks like the Ferrante and Rackoff quantifier elimination method.
  • Hypergraph Ramsey Theory Connection: The paper elegantly connects the geometric problem of separating vertices on a Boolean cube to hypergraph coloring, proving that the number of halfspaces needed to isolate ordered strings grows infinitely with the string length.

Key Results

  • Formal Separation: The paper successfully proves Theorem 1: The ORDERED language can be computed by a 2-head, 1-layer transformer but cannot be computed by a 1-head, 1-layer transformer when output MLPs are present.
  • Additive Embedding Sufficiency: The 2-head solution achieves its goal using standard, length-independent additive positional encodings, which are more aligned with practical implementations than the non-additive encodings used in alternative separation proofs.

Limitations and Future Work

The primary limitation is that this strict separation is only proven between $H=1$ and $H=2$ heads for 1-layer models. While other recent work (such as Steifer & Naskręcki, 2026) has shown separations for higher numbers of heads ($k$ vs $k-1$), those proofs relied on non-additive input embeddings. The authors note that extending the $k$ vs $k-1$ head separation to standard additive input embeddings remains an open and challenging problem for future research.

Summary updated

BibTeX
@misc{doornmalen2026transformer,
  author = {Jasper van Doornmalen and Alexander Kozachinskiy and Corinna Mathwieser and Tomasz Steifer and Felipe Urrutia and José Verschae and Przemysław Andrzej Wałȩga},
  title = {{Transformer Heads Looking for Order}},
  year = {2026},
  eprint = {2609.25588},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.25588},
}
Figure