In the world of deep learning, the Transformer is king. Its dominance in Natural Language Processing (NLP) and its rapid takeover of Computer Vision (CV) are usually attributed to one "magic" ingredient: self-attention. But what if we could achieve the same breakthroughs using something much simpler?
In their paper Pay Attention to MLPs, researchers from Google Research introduce gMLP, an architecture built entirely out of Multi-Layer Perceptrons (MLPs) equipped with a clever gating mechanism. Their findings challenge the status quo, suggesting that the "necessity" of self-attention might be overstated.
TL;DR
The authors propose gMLP, a simple architecture based on MLPs with a Spatial Gating Unit (SGU) that performs as well as Transformers in both vision and language tasks. It scales just as effectively as Transformers and proves that static spatial projections can often replace the dynamic, compute-heavy self-attention mechanism.
What Problem Does This Paper Address?
Since the landmark Attention is All You Need paper, the research community has largely moved away from Recurrent Neural Networks (RNNs) and Convolutions in favor of Transformers. The core belief is that self-attention provides a necessary "inductive bias"—the ability to dynamically weight interactions between different tokens (words in a sentence or patches in an image) based on their content.
However, self-attention is computationally expensive (scaling quadratically with sequence length) and architecturally complex. The authors ask a fundamental question: Is this dynamic, content-dependent interaction actually essential for high performance and scalability? Or can we get the same results with static, linear projections?
Methods: The gMLP Block and SGU
The authors introduce the gMLP block. Unlike a standard Transformer block, which alternates between an MLP and a self-attention layer, a gMLP block relies entirely on standard dense layers and a novel gating mechanism.
The block consists of:
- Channel Projections: Standard linear layers that operate independently on individual tokens.
- Spatial Gating Unit (SGU): The core innovation. It captures spatial interactions across tokens using a static linear projection.
In an SGU, the input is split into two parts along the channel dimension. One part is normalized and passed through a linear projection that operates across the spatial (sequence) dimension. The result is then multiplied element-wise with the second part of the input.
Crucially, this spatial projection is static: the weights do not change based on the input content, unlike self-attention. To ensure stability during training, the authors initialize these spatial weights to be near-zero. This means the model starts by treating tokens independently and gradually learns how they should interact.
Datasets
The model was rigorously tested across two major domains:
- Computer Vision: Evaluated on ImageNet-1K (classification without extra data).
- Language Modeling: Pretrained on the C4 dataset (English) using the Masked Language Modeling (MLM) objective, similar to BERT.
- NLP Downstream Tasks: Evaluated on the GLUE benchmark (including SST-2 for sentiment and MNLI for inference) and SQuAD (v1.1 and v2.0) for question answering.
Key Insights and Ideas
- Scaling Laws Apply to MLPs: One of the most significant findings is that gMLP scales just as well as Transformers. As data and compute increase, the performance gap between the two remains narrow or non-existent.
- Self-Attention is Overkill for Vision: On ImageNet, gMLP achieves parity with DeiT (a strong Transformer baseline). This suggests that for image classification, the "dynamic" nature of attention isn't doing much that a well-tuned static projection can't handle.
- The "Tiny Attention" Hybrid: While pure gMLP is powerful, it slightly lags behind Transformers on tasks requiring complex cross-sentence alignment (like MNLI). However, adding a tiny, single-head self-attention module (with a head size of just 64) into the gMLP block makes it outperform BERT-large while remaining more parameter-efficient.
- Learned Locality: When visualizing the learned spatial weights, the authors found that gMLP naturally learns "filters" that exhibit locality and shift-invariance—properties usually hard-coded into Convolutions, but here learned entirely from scratch.
Key Results
- Vision: As shown above, gMLP-B (73M params) achieved 81.6% Top-1 accuracy on ImageNet, matching DeiT-B and significantly outperforming the previous MLP-Mixer (which scored 76.4% in a similar setup).
- Language Pretraining: gMLP matched BERT's perplexity during pretraining, proving that MLPs are just as capable of learning the statistical structure of language.
- SQuAD Performance: A large gMLP model achieved 89.5% F1 on SQuAD v1.1 without any self-attention, nearly matching the original BERT-large.
- Efficiency: The hybrid "aMLP" (gMLP + tiny attention) outperformed BERT-large on SQuAD v2.0 by +4.4% F1, showing that a little bit of attention goes a very long way.
Limitations and Future Work
The authors acknowledge that while gMLP is highly competitive, Transformers still hold a "practical advantage" in certain NLP tasks involving sentence pairs (like MNLI), unless the gMLP model is scaled significantly larger (roughly 3x the parameters).
Future work may involve exploring how gMLP performs in even more complex tasks like machine translation or long-form generation. Additionally, researchers might investigate whether the static nature of the SGU can be further optimized for specialized hardware, potentially providing a massive speed advantage over the dynamic, memory-intensive computations required by Transformers.
Summary updated