Unveiling the Hidden Structure of Self-Attention via Kernel Principal Component Analysis
Rachel S. Y. Teo, Tan M. Nguyen
Abstract
The remarkable success of transformers in sequence modeling tasks, spanning various applications in natural language processing and computer vision, is attributed to the critical role of self-attention. Similar to the development of most deep learning models, the construction of these attention mechanisms relies on heuristics and experience. In our work, we derive self-attention from kernel principal component analysis (kernel PCA) and show that self-attention projects its query vectors onto the principal component axes of its key matrix in a feature space. We then formulate the exact formula for the value matrix in self-attention, theoretically and empirically demonstrating that this value matrix captures the eigenvectors of the Gram matrix of the key vectors in self-attention. Leveraging our kernel PCA framework, we propose Attention with Robust Principal Components (RPC-Attention), a novel class of robust attention that is resilient to data contamination. We empirically demonstrate the advantages of RPC-Attention over softmax attention on the ImageNet-1K object classification, WikiText-103 language modeling, and ADE20K image segmentation task. The code is publicly available at https://github.com/rachtsy/KPCA_code .
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
8 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Transformer Meets Twicing: Harnessing Unattended Residual Information cites Elliptical Attention
- Transformer Meets Twicing: Harnessing Unattended Residual Information cites Equivariant Neural Functional Networks for Transformers
- Equivariant Neural Functional Networks for Transformers cites Transformer Meets Twicing: Harnessing Unattended Residual Information
- Transformer Meets Twicing: Harnessing Unattended Residual Information cites Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
- Transformer Meets Twicing: Harnessing Unattended Residual Information cites Learning Transferable Visual Models From Natural Language Supervision
- Rethinking PCA Through Duality cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Rethinking PCA Through Duality cites Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
- Rethinking PCA Through Duality cites Language Models are Few-Shot Learners
- Rethinking PCA Through Duality cites Learning Transferable Visual Models From Natural Language Supervision
- Elliptical Attention cites Equivariant Neural Functional Networks for Transformers
- Equivariant Neural Functional Networks for Transformers cites Elliptical Attention
- Elliptical Attention cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Elliptical Attention cites Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
- Elliptical Attention cites Learning Transferable Visual Models From Natural Language Supervision
- Equivariant Neural Functional Networks for Transformers cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Equivariant Neural Functional Networks for Transformers cites Tight Clusters Make Specialized Experts
- Equivariant Neural Functional Networks for Transformers cites Learning Transferable Visual Models From Natural Language Supervision
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale cites Language Models are Few-Shot Learners
- Tight Clusters Make Specialized Experts cites Transformer Meets Twicing: Harnessing Unattended Residual Information
- Tight Clusters Make Specialized Experts cites Elliptical Attention
- Tight Clusters Make Specialized Experts cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Tight Clusters Make Specialized Experts cites Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
- Swin Transformer: Hierarchical Vision Transformer using Shifted Windows cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Swin Transformer: Hierarchical Vision Transformer using Shifted Windows cites Learning Transferable Visual Models From Natural Language Supervision
- Learning Transferable Visual Models From Natural Language Supervision cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Learning Transferable Visual Models From Natural Language Supervision cites Language Models are Few-Shot Learners
Cited by top-tier papers8
- Elliptical AttentionStefan K. Nielsen, Laziz U. Abdullaev, Rachel S. Y. Teo, Tan NguyenNeurIPS 2024 · 12 citations
- Transformer Meets Twicing: Harnessing Unattended Residual InformationLaziz U. Abdullaev, Tan Minh NguyenICLR 2025
- Rethinking PCA Through DualityJan Quan, Johan A. K. Suykens, Panagiotis PatrinosNeurIPS 2025
- Equivariant Neural Functional Networks for TransformersHoang V. Tran, Thieu Vo, An Nguyen The, Tho Tran Huu et al.ICLR 2025
- Tight Clusters Make Specialized ExpertsStefan K. Nielsen, Rachel S. Y. Teo, Laziz U. Abdullaev, Tan Minh NguyenICLR 2025
Builds on44
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
- Learning Transferable Visual Models From Natural Language SupervisionAlec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh et al.ICML 2021 · 47,906 citations
- Swin Transformer: Hierarchical Vision Transformer using Shifted WindowsZe Liu, Yutong Lin, Yue Cao, Han Hu et al.ICCV 2021 · 31,683 citations
- An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn et al.ICLR 2021 · 21,477 citations
- Towards Evaluating the Robustness of Neural NetworksNicholas Carlini, David A. WagnerS&P 2017 · 9,786 citations
Related papers
- Designing Robust Transformers using Robust Kernel Density EstimationXing Han, Tongzheng Ren, Tan Nguyen, Khai Nguyen et al.NeurIPS 2023 · 14 citations
- Rethinking Decoders for Transformer-based Semantic Segmentation: A Compression PerspectiveQishuai Wen, Chun-Guang LiNeurIPS 2024 · 8 citations
- Improving Robustness of Vision Transformers by Reducing Sensitivity to Patch CorruptionsYong Guo, David Stutz, Bernt SchieleCVPR 2023
- Can CNNs Be More Robust Than Transformers?Zeyu Wang, Yutong Bai, Yuyin Zhou, Cihang XieICLR 2023 · 14 citations
- A Primal-Dual Framework for Transformers and Neural NetworksTan Minh Nguyen, Tam Minh Nguyen, Nhat Ho, Andrea L. Bertozzi et al.ICLR 2023 · 2 citations
