Uncovering hidden geometry in Transformers via disentangling position and context
Jiajun Song, Yiqiao Zhong
TL;DR
This paper tackles the opacity of transformer embeddings by introducing a mean-based decomposition that splits each hidden state into a global mean, a layer-specific positional basis, a context basis, and a residual term, enabling direct interpretation of how position and context shape representations. The authors show that the positional basis is typically low-rank and smooth, while the context basis forms clear topic-like clusters, and that these two factors are largely incoherent, which supports robust interpretability. They provide both empirical evidence across multiple models and datasets and theoretical justification (via smoothness implying low-rank/low-frequency structure) and further show that the learned weight matrices in self-attention align with the positional basis, enabling a decoupled, kernel-based view of attention. The results suggest that language naturally yields smooth, decoupled geometric structure in hidden states, which has implications for efficient attention, interpretability, and the design of diagnostics beyond attention visualizations. The work also delineates limits by showing nonsmooth patterns in arithmetic tasks, highlighting language-specific geometry and potential boundaries of the decomposition’s applicability.
Abstract
Transformers are widely used to extract semantic meanings from input tokens, yet they usually operate as black-box models. In this paper, we present a simple yet informative decomposition of hidden states (or embeddings) of trained transformers into interpretable components. For any layer, embedding vectors of input sequence samples are represented by a tensor $\boldsymbol{h} \in \mathbb{R}^{C \times T \times d}$. Given embedding vector $\boldsymbol{h}_{c,t} \in \mathbb{R}^d$ at sequence position $t \le T$ in a sequence (or context) $c \le C$, extracting the mean effects yields the decomposition \[ \boldsymbol{h}_{c,t} = \boldsymbolμ + \mathbf{pos}_t + \mathbf{ctx}_c + \mathbf{resid}_{c,t} \] where $\boldsymbolμ$ is the global mean vector, $\mathbf{pos}_t$ and $\mathbf{ctx}_c$ are the mean vectors across contexts and across positions respectively, and $\mathbf{resid}_{c,t}$ is the residual vector. For popular transformer architectures and diverse text datasets, empirically we find pervasive mathematical structure: (1) $(\mathbf{pos}_t)_{t}$ forms a low-dimensional, continuous, and often spiral shape across layers, (2) $(\mathbf{ctx}_c)_c$ shows clear cluster structure that falls into context topics, and (3) $(\mathbf{pos}_t)_{t}$ and $(\mathbf{ctx}_c)_c$ are mutually nearly orthogonal. We argue that smoothness is pervasive and beneficial to transformers trained on languages, and our decomposition leads to improved model interpretability.
