Abstract
Recent advancements in Transformer architectures have traditionally attributed their expressive power to the combination of attention mechanisms and Feed-Forward Networks (FFNs). This paper challenges that paradigm by proving that softmax attention alone is a universal approximator. By introducing a novel "interpolation selection" technique, we demonstrate that a two-layer multi-head attention network can approximate any continuous sequence-to-sequence function, effectively performing complex computations without the need for FFNs.
Introduction
For years, the machine learning community has viewed the Transformer architecture as a two-part engine: the attention mechanism handles context ("where to look"), while the Feed-Forward Networks (FFNs) handle computation ("what to do"). However, the fundamental limits of the attention mechanism itself remained largely unexplored. In deep learning, "Universal Approximation" is the gold standard of expressive power—the mathematical proof that an architecture can learn any pattern given sufficient parameters. Previous proofs for Transformers relied on FFN layers to provide this power. This research seeks to determine if the attention mechanism is a standalone computer capable of approximating any continuous function.
Methodology: Interpolation Selection
The core contribution of this work is the Interpolation Selection technique. This method allows the attention mechanism to mimic the behavior of piecewise linear functions, such as those constructed by ReLU networks.
The process, as illustrated in the figure above, involves several key steps:
- Anchors and Mapping: The target function's output range is partitioned into a set of uniformly spaced "anchors" ($\tilde{L}_0, \dots, \tilde{L}_{p-1}$).
- Softmax as a Selector: The Key ($K$) and Query ($Q$) matrices are designed such that the Softmax operation acts as a "near-argmax" selector. It identifies the anchor point closest to the desired output for a given input.
- Value Retrieval: The Value ($V$) matrix retrieves the selected anchor.
- Approximation: By combining these steps, a single attention layer becomes a piecewise linear approximator. Since networks composed of ReLUs are known universal approximators, proving that attention can simulate this behavior establishes its universal approximation capability.
Experimental Validation
To validate these theoretical findings, the authors employed synthetic datasets:
- Truncated Linear Models: 1,000 samples were used to verify that approximation error decreases as the number of interpolation points (anchors) increases.
- Sequence-to-Sequence Mapping: 50,000 samples were generated by a "ground truth" two-layer ReLU network. The goal was to determine if an attention-only model could accurately mimic this complex, non-linear mapping.
The results confirmed the theoretical predictions. The Mean Squared Error (MSE) followed the predicted rates of $O(1/p)$ and $O(1/H)$, where $p$ is the number of interpolation points and $H$ is the number of heads. Heatmaps of attention weights further confirmed that the mechanism "locks on" to specific keys with high precision, behaving like a high-speed database query.
Key Insights
The Power of Softmax
Softmax is traditionally viewed as a probability generator. This research re-envisions it as a non-linear switch, enabling the model to perform complex logic and interpolation. This "one-hot" selection capability is what allows attention to simulate discrete lookups and continuous mappings.
Scaling and Precision
The paper provides concrete scaling laws. Precision improves at a rate of $O(1/(nH))$ for a sequence of length $n$ and $H$ heads. This implies that increasing the number of heads does more than just diversify context; it increases the "resolution" of the model's internal lookup table.
In-Context Optimization
A significant implication of this work is the proof that attention-only layers can approximate Gradient Descent. This provides a theoretical foundation for why Large Language Models (LLMs) can perform "In-Context Learning," solving new tasks within a prompt without weight updates.
Limitations and Conclusion
While the proof of universal approximation is a milestone, practical hurdles remain. The "curse of dimensionality" suggests that for high-dimensional functions, the number of attention heads required may grow exponentially. Furthermore, while the paper proves such weight configurations exist, it does not guarantee that standard training via Stochastic Gradient Descent (SGD) will converge to them.
In conclusion, this work elevates the attention mechanism from a data-shuffler to a powerful, standalone computational unit. By proving that two layers of attention are sufficient for universal approximation, the researchers have fundamentally changed our understanding of the Transformer's internal mechanics.
Summary updated