Transformers Represent Belief State Geometry in their Residual Stream

Adam Shai, Lucas Teixeira, Alexander Gietelink Oldenziel, Sarah Marzen, Paul M. Riechers

Introduction: Beyond the Stochastic Parrot

The "stochastic parrot" versus "world model" debate remains central to modern AI. While Large Language Models (LLMs) are explicitly trained only to predict the next token, they frequently exhibit sophisticated reasoning capabilities. The gap in our understanding lies in how the statistical properties of training data translate into specific computational structures inside the model.

This paper tackles this mystery by asking: What is the optimal way to predict the future of a process, and do transformers actually implement it? Leveraging computational mechanics—a field that describes the "meta-dynamics" of belief updating—the authors investigate whether transformers build internal representations of the world. When an optimal observer sees a sequence of tokens, they maintain a "belief state," which is a probability distribution over the possible hidden states of the data-generating process.

Probability Simplex

The researchers hypothesize that transformers represent these mathematical belief states linearly within their internal activations (the "residual stream").

Experimental Approach

To test this, the researchers used a highly controlled experimental setup:

  1. Data Generation: They used Hidden Markov Models (HMMs) to create synthetic datasets where the "ground truth" hidden states and optimal belief updates are mathematically known.
  2. Model Training: Small transformer models were trained on these HMM-generated sequences using standard next-token prediction.
  3. Linear Probing: To see if the models learned the theoretical belief states, the team used linear regression to find a mapping between the high-dimensional activations in the transformer's residual stream and the theoretical probability simplex (the "belief state geometry").
Emergence of Fractal Belief Geometry

The study utilized three primary synthetic processes designed to test different aspects of prediction, including the Zero-One-Random (Z1R) process for initial validation, the Mess3 Process (which generates a highly non-trivial fractal belief geometry), and the Random-Random-XOR (RRXOR) process to test if models keep track of information useful only for the distant future.

Key Findings

  • Linearity is King: One of the most striking findings is that complex Bayesian belief updates are represented linearly in the residual stream. The "geometry of thought" in transformers is structured such that simple linear transformations can extract sophisticated probabilistic information.
  • Fractals in the Machine: For the Mess3 process, the transformer didn't just learn a rough approximation; it reconstructed the intricate fractal geometry of the optimal belief states. The belief geometry isn't present at initialization; it emerges gradually and becomes more refined as training progresses.
  • Looking Beyond the Next Token: In the RRXOR experiments, the model maintained distinct representations for states that had identical immediate next-token probabilities. The correlation ($R^2$) between the model's represented distances and the ground-truth belief distances was 0.95, compared to just 0.31 for immediate next-token probabilities. This proves transformers learn to preserve information about the entire future.
  • Distributed Representations: While some information is localized in the final layer, "degenerate" information (useful only for the far future) is often spread across the residual streams of multiple layers, requiring a concatenation of activations to fully recover the belief state.

Limitations and Future Work

While groundbreaking, the study focused on small-scale HMMs (3-5 states). Real-world language has a vastly higher state dimensionality. The authors acknowledge that in LLMs, these belief simplices might be too large for the residual stream, necessitating compressed representations.

Furthermore, while the paper shows the representation exists, it doesn't definitively prove causal use by the transformer, though strong correlations suggest it does. Moving from synthetic HMMs to the non-stationary nature of human language is the next major hurdle, potentially explaining why LLMs represent concepts like "days of the week" in circular geometries.

Summary updated

BibTeX
@inproceedings{shai2024transformers,
  author = {Adam Shai and Lucas Teixeira and Alexander Gietelink Oldenziel and Sarah Marzen and Paul M. Riechers},
  title = {{Transformers Represent Belief State Geometry in their Residual Stream}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=YIB7REL8UC},
}
Figure