NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Concise One-Layer Transformers Can Do Function Evaluation (Sometimes)

Lena Strobl, Dana Angluin, Robert FrankarXiv 2025 · DOI

Introduction

The meteoric rise of Large Language Models (LLMs) has outpaced our theoretical understanding of their underlying architecture. While transformers demonstrate remarkable capabilities, the specific computational limits of their components—particularly the relationship between depth, width, and expressive capacity—remain partially obscured. This research investigates these limits by focusing on a fundamental computational primitive: function evaluation.

Function evaluation, or "dictionary lookup," involves retrieving a value $f(i^*)$ given a target key $i^*$ and a set of key-value pairs $(i, f(i))$. While seemingly simple, this task serves as a rigorous benchmark for understanding how transformers process and move information across sequences.

The Problem: Data Presentation and Conciseness

The difficulty of function evaluation for a transformer depends heavily on how the data is "presented" in the input sequence. The researchers categorize these into five distinct presentation cases:

  1. No keys: Values are in a fixed order.
  2. Fixed keys: Keys are present but in a static order.
  3. Bundled pairs: Keys and values are stored in the same input position (e.g., as part of the same token embedding).
  4. Consecutive positions: Keys and values are in adjacent slots.
  5. Split and Shuffled: Keys and values are in separate consecutive positions, and the pairs themselves are shuffled randomly across the sequence.

A central theme of the paper is conciseness. The authors define a "concise" model as one where the communication size (c-size)—a metric involving the number of heads, embedding dimensions, and bit precision—grows only poly-logarithmically with the input length $n$. A model that requires its size to grow linearly with $n$ is considered inefficient for the task.

Methodology

The study employs a dual approach combining formal proofs with empirical deep learning experiments:

  • Theoretical Proofs: The authors use communication complexity to establish lower bounds. By treating the transformer as a communication protocol between different parts of the sequence, they determine the minimum information transfer required to solve the task. They also establish upper bounds by constructing theoretical 1-layer and 2-layer models using hard attention and integer representation on a unit circle.
  • Empirical Validation: To ensure theoretical possibility translates to practical learnability, the authors trained small encoder-only transformers using the Adam optimizer. These models were tested on synthetic datasets of random functions $f: [n] \to [n]$ with sequence lengths up to $n=100$.

Key Findings: The 1-Layer Wall

The research reveals a sharp divide in the capabilities of 1-layer transformers based on how information is distributed.

The "Bundling" Advantage

When keys and values are "bundled" in the same position (Case 3), 1-layer transformers are exceptionally efficient. Theorems 3.1–3.3 prove that a 1-layer model can solve Cases 1 through 4 using a constant number of heads and embedding dimensions, requiring only logarithmic precision relative to the sequence length. In these scenarios, the model can easily associate a key with its value because they are local to a single position or a fixed offset.

The Case 5 Failure

The complexity shifts dramatically in Case 5, where keys and values are split across positions and shuffled. Theorem 3.6 establishes a lower bound showing that a 1-layer transformer cannot solve this task concisely. To succeed, a 1-layer model would require a size of at least $\Omega(n \log n)$, meaning the model size must grow linearly with the input sequence length.

The Power of Depth

The "wall" encountered by 1-layer models is bypassed by adding a second layer. A 2-layer transformer can solve Case 5 concisely. This provides a formal demonstration of how depth allows for more sophisticated information routing—specifically, the ability to first identify the location of a key and then, in a subsequent step, retrieve the associated value from a different location. This computational advantage cannot be easily replicated by simply increasing the width (embedding size) of a 1-layer model.

Empirical Results

The experimental data strongly supports the theoretical predictions:

  • Cases 1-4 Success: 1-layer models consistently achieved near 100% accuracy once the token embedding dimension reached a modest size (8 or 16).
  • Case 5 Failure/Recovery: 1-layer models struggled significantly as $n$ increased, with accuracy dropping toward chance levels for $n=20$. Conversely, 2-layer models maintained near-perfect accuracy across the same range, validating the necessity of depth for split-data lookups.

Discussion and Limitations

While the paper clarifies the limits of 1-layer models, it also highlights nuances in transformer design:

  • Positional Embeddings: For cases where keys are not explicitly provided, the model relies entirely on positional embeddings to "invent" keys. Without them, the model is mathematically incapable of the task.
  • Hard vs. Soft Attention: Most proofs utilize "hard" attention (selecting exactly one maximum). While the authors provide a construction for softmax attention in Case 5, it requires a very large MLP, suggesting that the practical success of 1-layer models may be limited by MLP capacity.
  • Learnability Gap: The researchers observed "bimodal behavior" during training—some runs hit 100% accuracy while others with identical settings stayed at 0%. This suggests that the optimization landscape for these tasks is complex and "hit-or-miss."

Conclusion

This work provides a rigorous mathematical foundation for why depth matters in transformer architectures. By showing that a 1-layer model hits a hard computational wall on a task as simple as shuffled dictionary lookups—a wall that a 2-layer model easily overcomes—the authors offer a clear example of how architectural depth enables efficient information processing that width alone cannot replicate.

Summary updated

BibTeX
@misc{strobl2025concise,
  author = {Lena Strobl and Dana Angluin and Robert Frank},
  title = {{Concise One-Layer Transformers Can Do Function Evaluation (Sometimes)}},
  year = {2025},
  eprint = {2503.22076},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.22076},
}
Figure