Attention with Markov: A Curious Case of Single-layer Transformers

Ashok Vardhan Makkuva, Marco Bondaschi, Adway Girish, Alliot Nagle, Martin Jaggi, Hyeji Kim, Michael Gastpar

TL;DR

While multi-layer transformers effortlessly learn simple bigram patterns in data, single-layer versions often fail, getting trapped in "unigram" local minima where they only learn overall token frequencies. This paper provides a theoretical framework to explain this "curious case," proving that architectural choices like weight-tying and data properties like high switching probabilities create these optimization traps.

The Problem: A Curious Case of Single-Layer Models

Transformers have revolutionized sequence modeling, but we still lack a complete understanding of the mechanics behind how they learn simple statistical structures. To probe this, researchers often use Markov chains—where the next token depends only on the current one—as a "hydrogen atom" for studying these models.

Previous work found that transformers with two or more layers consistently develop "induction heads" to solve these tasks, easily learning the conditional probabilities (the bigram distribution). However, single-layer models, which are theoretically capable of representing the exact same solution (the Markov kernel), frequently fail in practice. Instead, they get stuck predicting the average frequency of tokens (the unigram distribution).

Test loss comparison across transformer depths

The authors set out to map the "loss landscape" of these models to understand why single-layer architectures get stuck and how architectural choices influence their ability to escape these traps.

Methods and Datasets

The authors introduce a principled mathematical framework to analyze single-layer transformers trained on first-order Markovian data. Their approach involves:

  • Loss Landscape Characterization: Analyzing the cross-entropy loss function to identify stationary points.
  • Hessian Analysis: Calculating the second derivatives (the Hessian matrix) at specific points to prove whether a "unigram" solution is a stable local minimum (a trap) or a saddle point (an escape route).
  • Architectural Comparison: Comparing weight-tied models (where the input embedding and output linear layer share weights, a common practice in LLMs) against non-weight-tied models.

The study relies on synthetic datasets generated from first-order Markov chains, primarily focusing on binary sequences (0s and 1s) where transition probabilities are defined by $p$ (probability of $0 \to 1$) and $q$ (probability of $1 \to 0$). A key metric used is the switching factor, $p+q$, which represents how often the data switches states.

Key Insights: Weight Tying and the Switching Factor

Impact of weight-tying and switching factor on test loss
  • Weight Tying is an Optimization Hazard: In single-layer models, tying the input and output weights creates "bad" local minima. When weights are tied, the model's ability to represent different transitions is constrained, making the simple unigram solution look like a stable valley in the loss landscape.
  • The "Switching Factor" Threshold: The authors prove that for binary data, if $p+q > 1$ (meaning the chain flips states more often than it stays), a bad local minimum is guaranteed to exist in weight-tied models.
  • Saddle Points as Escape Hatches: Interestingly, if you remove weight tying, that same bad local minimum becomes a saddle point. This means the optimizer (like SGD or Adam) can find a direction to "slide off" the plateau and eventually reach the global bigram minimum.
  • Depth as a Regularizer: The most striking observation is that adding just one more layer (moving to a 2-layer transformer) allows the model to escape these minima even with weight tying. Depth seems to fundamentally change the curvature of the loss landscape, making it easier for the model to "see" the better bigram solution.

Key Results

  • Theoretical Proofs: The authors provide explicit constructions for both the global minimum (bigram) and the bad local minimum (unigram), delineating the exact regimes (based on $p$ and $q$) where they occur.
  • Empirical Congruence: Experiments perfectly match the theory. In the $p+q > 1$ regime with weight tying, 1-layer models hit a test loss plateau corresponding to the unigram entropy. Without weight tying, or with more layers, they reach the lower entropy rate of the bigram model.
  • Low-Rank Solutions: Even when they succeed, single-layer models tend to learn "low-rank" weight matrices, suggesting they find the simplest possible way to represent the Markov kernel.

Limitations and Future Work

  • Higher-Order Chains: The current theory focuses on first-order Markov chains. Real-world language has much longer dependencies, and extending this analysis to higher-order Markov processes is a logical next step.
  • The "Why" of Depth: While the paper shows that 2-layer models escape the traps, it doesn't provide a full theoretical proof of why the second layer changes the Hessian so favorably. The authors highlight this as a key open problem.
  • Scaling: The study uses very small models ($d=4$). While this is necessary for rigorous theory, it remains to be seen how these specific landscape properties evolve as models scale to billions of parameters.

Summary updated

BibTeX
@inproceedings{makkuva2025attention,
  author = {Ashok Vardhan Makkuva and Marco Bondaschi and Adway Girish and Alliot Nagle and Martin Jaggi and Hyeji Kim and Michael Gastpar},
  title = {{Attention with Markov: A Curious Case of Single-layer Transformers}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=SqZ0KY4qBD},
}
Figure