Abstract
This paper investigates the evolution of token representations in Transformers by modeling them as continuous-time dynamical systems. We identify a fundamental dichotomy: tokens either collapse toward a single point or diverge toward infinity. We prove that token collapse leads to performance degradation, while divergence facilitates the formation of meaningful directional clusters. Furthermore, we analyze the impact of positional encodings, showing that Rotary Positional Encoding (RoPE) naturally resists collapse. Finally, we propose simple architectural modifications to encourage divergence, resulting in improved performance across language modeling and image recognition tasks.
Introduction
Despite the widespread success of Transformer architectures, a rigorous theoretical understanding of how token representations evolve through successive layers has remained elusive. Previous attempts to model Transformers as interacting particle systems often relied on restrictive assumptions. This work addresses this gap by employing a continuous-time limit approach, modeling the discrete steps of a Transformer's layers as a system of Ordinary Differential Equations (ODEs). By analyzing the stability of these systems, we uncover the underlying dynamics that govern token behavior and their impact on model performance.
The Dynamical Dichotomy: Collapse vs. Divergence
At the heart of our analysis is the characterization of the Transformer's self-attention mechanism through two key matrices: $W$ (the query-key interaction matrix, $QK^\top$) and $A$ (a combination of attention and value weights, $W(V^\top)^{-1}$). By examining the eigenvalues of these matrices, we derive sufficient conditions for two distinct regimes of token evolution.
In the "Collapse" Trap, model parameters meet specific negative definite conditions, causing tokens to move closer together and eventually converge toward zero. This process effectively erases the unique contextual information contained within individual tokens, leading to poor model performance. Conversely, we find that Divergence is Productive. When tokens diverge toward infinity, they do not do so chaotically; instead, they organize into distinct directional clusters. This "directional clustering" appears to be a hallmark of a well-functioning contextual representation.
The Role of Positional Encoding
A significant finding of this study is the impact of positional encoding schemes on these dynamics. We compare Absolute Positional Encoding (APE) with Rotary Positional Encoding (RoPE). Our analysis reveals that RoPE naturally inhibits token collapse. The rotation matrices introduced by RoPE make it mathematically much harder for the system to enter the convergence regime, providing a built-in stability mechanism that APE lacks.
Empirical Validation and Architectural Refinement
To validate our theoretical framework, we conducted experiments across WikiText-103, EnWik8, and ImageNet-1K. We observed a strong correlation between the dynamical regime and model performance. For instance, on WikiText-103, models in the divergence regime achieved a test perplexity of 32.07, significantly outperforming those forced into convergence (33.05). Analysis of pre-trained models like GPT-2 and Llama-2 further confirmed that "healthy" real-world models naturally reside in the divergence regime, with roughly 50% positive eigenvalues in their weight matrices.
Based on these insights, we propose a simple architectural tweak: adding a learnable regularization term ($\lambda I_D$ or $\lambda A$) to the query-key interaction matrix. This "nudges" the model's eigenvalues into the divergence regime. This minor adjustment yielded measurable gains, such as improving the Bits Per Character (BPC) on EnWik8 from 1.295 to 1.281 and increasing ImageNet-1K accuracy for the DeiT model to 71.96%.
Conclusion and Future Work
Our work demonstrates that the dynamical properties of tokens are a critical factor in Transformer performance. While our current proofs omit LayerNorm and Feed-Forward Networks (FFNs) for mathematical tractability, empirical evidence suggests our insights hold even in full-scale models. Future research will focus on extending this framework to include the "squashing" effects of LayerNorm, which prevents tokens from actually flying off to infinity in practice. Ultimately, understanding these particle-like interactions opens new avenues for designing more robust and efficient attention mechanisms.
Summary updated