TL;DR
Is the "probabilistic" nature of softmax attention actually necessary for Transformers? This paper argues that softmax's success isn't due to its sum-to-one normalization or sparsity, but rather its implicit regularization of the attention matrix's Frobenius norm. By replacing softmax with properly scaled polynomial activations (like $x^3$), the authors achieve competitive or superior performance across vision, language, and physics tasks, effectively debunking the long-held belief that attention must be non-negative and sparse.
What Problem Does This Paper Address?
Since the introduction of the Transformer, the softmax function has been the undisputed king of attention mechanisms. Researchers generally assume that three properties of softmax are essential:
- Non-negativity: Attention weights are always positive.
- Normalization: Rows sum to one, allowing them to be interpreted as a probability distribution.
- Sparsity: The mechanism naturally focuses on a few key tokens.
However, these assumptions are largely based on empirical success rather than rigorous theory. This paper asks a fundamental question: Do we actually need these properties? If we can find a simpler mathematical alternative that performs just as well, it suggests our understanding of why Transformers work might be incomplete.
Methods
The authors shift the focus from "probability" to "regularization." They provide a theoretical analysis showing that softmax implicitly keeps the Frobenius norm of the attention matrix bounded by $O(\sqrt{N})$, where $N$ is the sequence length. This bound is crucial because it prevents gradients from exploding or vanishing during training.
Motivated by this, they propose Polynomial Attention. Instead of softmax, they use a simple power function: $$\phi(x) = \frac{1}{k}x^p$$ Specifically, they focus on the cubic polynomial ($x^3$). The "secret sauce" is the scaling factor $k$. Their theory dictates that to maintain training stability similar to softmax, $k$ should be proportional to $\sqrt{N}$. They test two versions:
- Fixed scale: $k$ is set based on the sequence length at the start.
- Dynamic scale: $k$ is a learnable parameter initialized at the theoretical value.
Datasets
The authors validated their approach across a diverse set of benchmarks:
- Image Classification: ImageNet-1k and Tiny-ImageNet.
- Object Detection & Segmentation: COCO 2017.
- Long-Range Dependencies: The Long Range Arena (LRA) benchmark, including tasks like ListOps, Text Classification, and Pathfinder.
- Physics-Based Modeling: Solving partial differential equations (PDEs) like the Convection and 1D-Reaction equations using PINNsformer.
Key Insights and Ideas
- The Frobenius Norm is Key: The paper demonstrates that as long as the attention matrix's norm is controlled, the specific activation function matters less than we thought. As seen in Figure 2, scaling the $x^3$ activation by $1/16$ (for a sequence length of 256) brings its Frobenius norm down to levels comparable to softmax, stabilizing the training.
- Scaling is Non-Negotiable: Without proper scaling, polynomial activations fail miserably. Figure 1 shows a "Goldilocks zone" for the scale factor $k$; if $k$ is too small or too large, accuracy drops to zero due to training instability.
- Interpretability without Sparsity: Even though $x^3$ attention allows for negative weights and isn't sparse, it still learns meaningful patterns. Heatmaps in Figures 4 and 5 show that polynomial attention still learns to focus on relevant patches (like rows in an image) just as effectively as softmax.
Key Results
- ImageNet-1k: Polynomial attention with a dynamic scale matched or slightly outperformed softmax across four major architectures (ViT, DeiT, Swin, and XCiT). For example, on XCiT-M, $x^3$ achieved 82.9% accuracy vs. softmax's 82.7%.
- Object Detection: On COCO, the $x^3$ dynamic scale model achieved 45.1 AP, outperforming the softmax baseline of 44.9 AP.
- Long Range Arena: The polynomial models were consistently better than softmax across all five LRA tasks, showing particular strength in handling long sequences where traditional softmax can struggle.
- Physics Modeling: In solving PDEs, polynomial activations achieved lower relative Mean Absolute Error (rMAE) than softmax, proving their utility beyond standard CV and NLP tasks.
Limitations and Future Work
- Architecture Scope: The theoretical framework is currently specific to dot-product self-attention. It's unclear if these findings translate directly to additive attention or more complex kernelized approximations.
- Model Scale: The experiments were conducted on models with up to 100 million parameters. While significant, the authors acknowledge that testing on "Large Language Model" scales (billions of parameters) is a necessary next step to ensure the scaling laws hold.
- Initialization Sensitivity: The theory relies on the assumption that weights are i.i.d. normal at initialization. While this holds for standard training, different initialization schemes might require different scaling strategies.
Summary updated