Transformers have revolutionized artificial intelligence, powering everything from large language models like GPT-4 to advanced Vision Transformers (ViT). While their empirical success is undeniable, their mathematical foundations have remained somewhat mysterious. Specifically, in high-dimensional spaces—such as long sequences of text or high-resolution images—statistical models typically fall victim to the "curse of dimensionality," where the data required to learn a function grows exponentially with the number of dimensions.
In their ICML 2023 paper, Approximation and Estimation Ability of Transformers for Sequence-to-Sequence Functions with Infinite Dimensional Input, researchers Shokichi Takakura and Taiji Suzuki provide a rigorous theoretical explanation for this immunity. They demonstrate that Transformers are uniquely equipped to isolate the "signal" from the "noise" in infinite-dimensional data.
The Mathematical Mystery
In classical statistics, learning a function with $d$ input variables usually results in an error rate that scales poorly as $d$ increases. Transformers, however, routinely process thousands of tokens, each represented by a high-dimensional vector, effectively operating in a regime of "infinite" dimensions.
Previous theoretical work on neural networks (like CNNs or standard feed-forward networks) showed they could bypass this curse if the data lived on a low-dimensional manifold or if the target function exhibited specific "smoothness." However, these theories often assumed fixed input lengths and failed to account for the dynamic nature of Transformers—specifically, the reality that the "important" features in a sentence or image change depending on the input itself.
A New Theoretical Framework
To understand how Transformers approximate and estimate a "true" function, the authors utilize non-parametric regression. They introduce two key mathematical frameworks to model the data:
- Anisotropic and Mixed Smoothness: This assumes the target function is highly sensitive to a small subset of "important" features, while remaining largely unaffected by the surrounding high-dimensional noise.
- Piecewise Smoothness: Representing the paper's most novel contribution, this concept models the idea that important features are not static. For instance, in one image of a zebra, the stripes on the left might be the critical feature; in another, it might be the head on the right.
The study analyzes a specific Transformer architecture equipped with sliding window self-attention (to handle local context), sinusoidal positional encodings (to maintain shift-equivariance), and deep feed-forward layers (to process extracted features).
How Transformers Extract Signal from Noise
The paper identifies three core mechanisms that allow Transformers to succeed where other models fail:
- Dynamic Feature Extraction: Self-attention is not merely a static filter; it acts as a dynamic importance estimator. The initial layers of the Transformer approximate an "importance function," while subsequent layers use the softmax mechanism to dynamically select the most relevant tokens for that specific input.
- The Power of Parameter Sharing: Because Transformers apply the same weights across different positions in a sequence, the model's complexity—and consequently its learning error—does not explode as the sequence length increases.
- Memory via Orthogonality: To extract multiple important features sequentially, the authors propose that Transformers utilize a "basis coding" technique. By leveraging approximately orthonormal vectors in the positional encoding, the model can "remember" which tokens it has already attended to, allowing it to systematically move on to the next most important feature.
To ground their theory, the authors include a numerical experiment using ImageNet-1k (specifically zebra images) and a pre-trained ViT-Base. This experiment verifies the "piecewise smoothness" assumption, demonstrating that the model's predictions remain stable even when 90% of the "unimportant" image patches are masked.
Key Results: Dimension-Independent Learning
The theoretical analysis yields several profound results regarding the learning efficiency of Transformers:
- Optimal Convergence Rates: The researchers proved that the estimation error of a Transformer scales at a rate of $n^{-2a^\dagger / (2a^\dagger + 1)}$, where $n$ is the number of samples and $a^\dagger$ represents the smoothness (or complexity) of the task.
- Dimension Independence: Crucially, this convergence rate is entirely independent of the input and output dimensions. Whether the input consists of 100 tokens or 1,000,000 tokens, the learning efficiency remains constant, provided the underlying task complexity is unchanged.
- Near-Minimax Optimality: For certain classes of functions, this rate matches the theoretical "speed limit" (the minimax optimal rate) for any possible machine learning model. This proves that Transformers are nearly as statistically efficient as mathematically possible.
Limitations and Future Directions
While the paper establishes a robust theoretical foundation, the authors note a few caveats. First, the proofs rely on the Empirical Risk Minimizer (ERM) assumption—assuming the optimization process can find the absolute best set of weights. In practice, models are trained via gradient descent, which can get stuck in local minima. Second, the analysis focuses on sliding window attention rather than the global attention used in models like GPT-4, though the authors suggest their framework could be extended. Finally, the theory relies on "smoothness priors," assuming the target function has a sparse structure where only a few features matter. While applicable to text and images, this may not hold for more chaotic data types.
Future work aims to bridge the gap between this approximation theory and the actual optimization dynamics of how Transformers learn via backpropagation, further unraveling the mathematical magic behind modern AI.
Summary updated