Abstract
This paper establishes a theoretical foundation for the versatility of Transformer models, proving that a single self-attention head with fixed weights can approximate a wide range of sparse attention patterns by varying its input. A key finding is that the required hidden dimension $d$ only needs to grow logarithmically with the sequence length $L$ ($d = O(\log L)$), explaining how these models remain expressive even when the internal representation is significantly smaller than the sequence itself.
Introduction
The self-attention mechanism is the cornerstone of modern AI, enabling breakthroughs in natural language processing, computer vision, and beyond. In practice, attention matrices are observed to be both sparse (tokens attend to a few others) and dynamic (patterns vary based on input). However, a theoretical gap remained: how can fixed-weight modules represent such diverse patterns, and how does the hidden dimension $d$ scale with sequence length $L$?
Theoretical Framework
The authors employ a constructive proof to demonstrate the expressive capacity of self-attention, showing exactly how to build inputs that produce target patterns.
Random and Orthogonal Projections
The proof leverages the Johnson-Lindenstrauss (JL) Lemma, which posits that high-dimensional data can be projected into a lower-dimensional space while nearly preserving pairwise distances. The authors extend this by deriving concentration bounds for orthogonal (Stiefel) projections, proving they offer superior mathematical properties compared to standard i.i.d. Gaussian projections.
Constructing Attention Patterns
By carefully selecting the input matrix $X$, the authors show it is possible to "steer" fixed weight matrices ($W_Q$ and $W_K$) to approximate any target "k-nonzero-bounded" matrix—matrices where each row and column has at most $k$ non-zero elements.
Key Insights
- Logarithmic Scaling Law: The most significant result is that $d$ needs only to scale as $O(\log L)$, rather than linearly. This explains why Transformers remain computationally viable for extremely long sequences.
- Fixed Weights, Infinite Patterns: The mechanism's "intelligence" lies in its ability to map different inputs to vastly different attention maps using the same set of weights.
- Sparsity as a Prerequisite: The theoretical guarantees specifically apply to sparse matrices, aligning with empirical observations like the "Lottery Ticket Hypothesis" and the behavior of real-world models.
Empirical Validation
The theory was validated through synthetic simulations testing the $O(\log L)$ scaling across sequence lengths from 512 to 3072. Additionally, qualitative analysis of pre-trained DistilBERT models confirmed that real-world attention matrices exhibit the predicted sparse and dynamic properties, as seen in the varying patterns across different inputs and heads.
Conclusion and Future Work
The paper formally proves that for any sparse, right-stochastic matrix, there exists an input $X$ that allows a fixed-weight self-attention head to approximate it with high probability. While the analysis focuses on single heads, it provides a rigorous basis for the success of Transformers. Future research may explore how these insights can inform the design of more efficient architectures that explicitly leverage this logarithmic scaling.
Summary updated