TL;DR
This paper reveals that transformers, trained on next-token prediction, learn to represent the "belief state geometry" of the data-generating process within their residual streams. This geometry, which can be surprisingly complex and fractal, reflects how the model updates its understanding of the underlying world, going beyond simple next-token prediction to encode information about the entire future.
What Problem Does This Paper Address?
When we train large language models (LLMs) like transformers on next-token prediction, what internal computational structures do they actually learn? While it's intuitive that they might learn a "world model" to understand the data-generating process, it's not immediately clear how this translates into the model's internal workings, especially given the seemingly simple training objective. This paper tackles this by proposing and empirically verifying that transformers learn to represent the dynamics of "belief updating" over hidden states of the data-generating process, a concept formalized by computational mechanics. This belief updating process, when visualized, forms a geometric structure (a "belief state geometry") that the authors hypothesize is encoded within the transformer's activations.
Methods
The core of the paper's methodology lies in connecting computational mechanics with transformer architectures. They leverage the theory of optimal prediction and the mixed-state presentation (MSP), which formalizes how an optimal observer updates their beliefs about the hidden states of a data-generating process given observed tokens. This belief updating process can be visualized as points within a probability simplex, forming a "belief state geometry."
The authors then train transformer models on data generated by Hidden Markov Models (HMMs) with known ground-truth belief state geometries. They analyze the residual stream activations of these trained transformers. Using linear regression, they attempt to find an affine map from the high-dimensional residual stream activations to the lower-dimensional belief state geometry. The success of this mapping indicates whether the transformer has learned to represent this geometry. They investigate whether this representation is localized in the final layer or distributed across multiple layers.
Datasets
The paper uses synthetic datasets generated by Hidden Markov Models (HMMs). Specifically, they employ:
- Zero-One-Random (Z1R) process: A simple HMM with 3 states.
- Mess3 Process: A more complex HMM with 3 hidden states and a vocabulary of {A, B, C}, known to produce a belief state geometry with intricate fractal structure.
- Random-Random-XOR (RRXOR) process: An HMM with 36 distinct belief states that exhibit degeneracies in their optimal next-token predictions, making it a challenging test case.
These datasets are designed to have specific, known underlying structures that allow for the verification of the learned representations.
Key Insights and Ideas
- Belief State Geometry as a Learned Structure: Transformers trained on next-token prediction don't just learn to predict the next token; they learn to represent the geometric structure of belief updating over the data-generating process's hidden states.
- Linear Representation in Residual Stream: This belief state geometry is found to be linearly represented in the residual stream activations, even when the geometry itself is highly complex and fractal. This is a significant finding, as it suggests a direct mapping from internal activations to this abstract concept.
- Beyond Next-Token Prediction: The learned representations capture information about the entire future, not just the immediate next token. This is evidenced by the fact that distinct belief states can have the same next-token prediction but are still distinguishable in the transformer's activations.
- Fractal Geometries are Learnable: The framework successfully predicts and finds complex, fractal belief state geometries within the transformer's activations, demonstrating the model's capacity to learn sophisticated underlying structures.
- Layer Distribution: The representation of belief state geometry can be localized in the final residual stream or distributed across multiple layers, depending on the complexity and degeneracies of the underlying data-generating process.
Key Results
- The paper demonstrates a strong linear correlation between the transformer's residual stream activations and the ground-truth belief state geometry for the Mess3 process, even for its intricate fractal structure.
- For the RRXOR process, which has next-token prediction degeneracies, the belief state geometry is not well-represented in the final residual stream alone but is found when activations from all layers are concatenated. This highlights how information can be spread across layers.
- The correlation between the learned belief state representation and the ground-truth belief state distances is high (R² = 0.95 for RRXOR, R² = 1.00 for Mess3), while the correlation with next-token prediction distances is significantly lower for RRXOR (R² = 0.31). This strongly suggests the representation is capturing more than just next-token probabilities.
- The study shows that the belief state geometry representation emerges gradually during training and is not an artifact of initialization.
Limitations and Future Work
- Scale: The current experiments are limited to small HMMs with few states and tokens. Extending the framework to the massive scale of modern LLMs (millions of tokens, vast vocabularies) is a significant challenge. The dimensionality of belief state simplices would exceed the residual stream dimension, implying that for realistic systems, the geometry must be represented in a compressed form.
- Intractability: For complex real-world data, explicitly computing ground-truth belief states becomes intractable. New methodologies will be needed to validate the framework in such settings.
- Feature Definition: The relationship between belief states and "features" in LLMs is not one-to-one and requires further investigation.
- Optimality: The current work assumes optimal prediction. Future work should explore how near-optimality and non-optimality influence belief state representations.
- Circuitry for Bayesian Updating: While the paper establishes the representation of belief states, it doesn't directly demonstrate that LLMs implement a "circuit" for Bayesian updating, which is a natural extension to explore.
- Generalization to Non-HMMs: The paper primarily uses HMMs. Investigating how the framework applies to data generated by non-HMM sources (e.g., natural language) is an important direction.
Summary updated