The Geometry of Tokens in Internal Representations of Large Language Models
Karthik Viswanathan, Yuri Gardinazzi, Giada Panerai, Alberto Cazzaniga, Matteo Biagetti
TL;DR
Using a mean-field interpretation, the paper treats token embeddings across transformer layers as samples from an empirical measure $\mu=\frac{1}{n}\sum_{j=1}^n \delta_{x_j}$ and analyzes token geometry via intrinsic dimension $\hat{d}$, neighborhood overlap $\chi_k^{\ell,m}$, and cosine similarity to link geometry with next-token loss. Across Llama, Mistral, and Pythia on Pile-10K prompts, ID peaks appear in early-to-middle layers and grow with token shuffling, while cosine similarity increases and neighborhood coherence declines near the ID peak for shuffled data. A robust cross-model correlation between token-level ID and average cross-entropy loss is demonstrated, with theoretical framing tying ID to logits and contextual entropy through the softmax mechanism. The findings propose intrinsic dimension as a diagnostic tool for model behavior and training dynamics, enabling unsupervised interpretation of prompt processing in large language models.
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.
