Abstract
We investigate the relationship between the geometry of token embeddings and their role in the next token prediction within transformer models. An important aspect of this connection uses the notion of empirical measure, which encodes the distribution of token point clouds across transformer layers and drives the evolution of token representations in the mean-field interacting picture. We use metrics such as intrinsic dimension, neighborhood overlap, and cosine similarity to observationally probe these empirical measures across layers. To validate our approach, we compare these metrics to a dataset where the tokens are shuffled, which disrupts the syntactic and semantic structure. Our findings reveal a correlation between the geometric properties of token embeddings and the cross-entropy loss of next token predictions, implying that prompts with higher loss values have tokens represented in higher-dimensional spaces.
Introduction
Despite the transformative success of Large Language Models (LLMs), the internal mechanisms by which they process information remain largely opaque. A promising approach to demystifying these "black boxes" is to analyze the geometric properties of their internal representations. Rather than focusing solely on individual token vectors, we can view the entire set of tokens in a prompt as a "particle cloud" or an empirical measure that evolves as it passes through the model's layers. This paper explores how the geometric complexity of these clouds relates to the model's primary objective: minimizing next-token prediction error.
Methodology and Geometric Probes
To characterize the evolution of token distributions, we employ three primary geometric metrics: intrinsic dimension (ID), neighborhood overlap (NO), and cosine similarity. ID, estimated using the GRIDE method, represents the minimum number of variables required to describe the token cloud. A higher ID indicates a more complex, less structured representation. NO tracks the stability of local relationships between consecutive layers, while cosine similarity measures the angular alignment of token vectors.
The Shuffling Algorithm
To isolate the impact of linguistic structure on these geometric properties, we developed a shuffling algorithm. This method progressively disrupts the order of tokens in a prompt while maintaining overall word frequency. By varying the "shuffle index" ($S$), we can observe how the destruction of meaning affects the geometry of the representations.
Key Findings: The Evolution of Token Geometry
Our analysis across models like Llama 3 8B and Mistral 7B reveals a consistent pattern in the evolution of token clouds.
The "ID Peak" and Structural Compression
A central discovery is the existence of an "ID peak" in the early-to-middle layers of all tested models. The intrinsic dimension of the token cloud initially rises, reaching a maximum before contracting in the final layers. Crucially, linguistic structure acts as a compression mechanism: shuffling tokens significantly increases the height of this peak, suggesting that models use internal layers to compress meaningful language into lower-dimensional manifolds.
Geometry as a Predictor of Performance
We found a strong statistical relationship between the intrinsic dimension of internal representations and the model's cross-entropy loss. Prompts that the model finds difficult (high loss) consistently exhibit higher intrinsic dimensions in their internal layers. This suggests that when a model is confident, it maps tokens to a more structured, lower-dimensional space. Furthermore, while shuffled tokens exhibit higher cosine similarity (pointing in similar directions), they occupy a more complex, higher-dimensional volume within that alignment.
Conclusion
Our research demonstrates that the geometric properties of token clouds are deeply linked to the linguistic structure of the input and the model's predictive performance. These findings suggest that geometric probes could serve as powerful, unsupervised tools for evaluating model behavior and understanding the internal dynamics of LLMs. Future work will extend these analyses to multiscale geometric properties and explore their implications for model training and monitoring.
Summary updated