A Theoretical Understanding of Shallow Vision Transformers: Learning, Generalization, and Sample Complexity
Hongkang Li, Meng Wang, Sijia Liu, Pin-Yu Chen
Abstract
Vision Transformers (ViTs) with self-attention modules have recently achieved great empirical success in many vision tasks. Due to non-convex interactions across layers, however, the theoretical learning and generalization analysis is mostly elusive. Based on a data model characterizing both label-relevant and label-irrelevant tokens, this paper provides the first theoretical analysis of training a shallow ViT, i.e., one self-attention layer followed by a two-layer perceptron, for a classification task. We characterize the sample complexity to achieve a zero generalization error. Our sample complexity bound is positively correlated with the inverse of the fraction of label-relevant tokens, the token noise level, and the initial model error. We also prove that a training process using stochastic gradient descent (SGD) leads to a sparse attention map, which is a formal verification of the general intuition about the success of attention. Moreover, this paper indicates that a proper token sparsification can improve the test performance by removing label-irrelevant and/or noisy tokens, including spurious correlations. Empirical experiments on synthetic data and CIFAR-10 dataset justify our theoretical results and generalize to deeper ViTs.
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.
67 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
- In-context Convergence of Transformers cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- In-context Convergence of Transformers cites Decision Transformer: Reinforcement Learning via Sequence Modeling
- In-context Convergence of Transformers cites Language Models are Few-Shot Learners
- In-context Convergence of Transformers cites Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer
- On the Role of Attention in Prompt-tuning cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- On the Role of Attention in Prompt-tuning cites Language Models are Few-Shot Learners
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale cites Language Models are Few-Shot Learners
- Decision Transformer: Reinforcement Learning via Sequence Modeling cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Decision Transformer: Reinforcement Learning via Sequence Modeling cites Language Models are Few-Shot Learners
- Swin Transformer: Hierarchical Vision Transformer using Shifted Windows cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- White-Box Transformers via Sparse Rate Reduction cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- White-Box Transformers via Sparse Rate Reduction cites Language Models are Few-Shot Learners
- Twins: Revisiting the Design of Spatial Attention in Vision Transformers cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Twins: Revisiting the Design of Spatial Attention in Vision Transformers cites Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
- Linear attention is (maybe) all you need (to understand Transformer optimization) cites On the Role of Attention in Prompt-tuning
- Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer cites On the Role of Attention in Prompt-tuning
- Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer cites Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
- Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer cites Language Models are Few-Shot Learners
Cited by top-tier papers67
- White-Box Transformers via Sparse Rate ReductionYaodong Yu, Sam Buchanan, Druv Pai, Tianzhe Chu et al.NeurIPS 2023 · 149 citations
- Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer TransformerYuandong Tian, Yiping Wang, Beidi Chen, Simon S. DuNeurIPS 2023 · 125 citations
- In-context Convergence of TransformersYu Huang, Yuan Cheng, Yingbin LiangICML 2024 · 114 citations
- Linear attention is (maybe) all you need (to understand Transformer optimization)Kwangjun Ahn, Xiang Cheng, Minhak Song, Chulhee Yun et al.ICLR 2024 · 92 citations
- On the Role of Attention in Prompt-tuningSamet Oymak, Ankit Singh Rawat, Mahdi Soltanolkotabi, Christos ThrampoulidisICML 2023 · 67 citations
Builds on29
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 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
- Decision Transformer: Reinforcement Learning via Sequence ModelingLili Chen, Kevin Lu, Aravind Rajeswaran, Kimin Lee et al.NeurIPS 2021 · 2,557 citations
- Twins: Revisiting the Design of Spatial Attention in Vision TransformersXiangxiang Chu, Zhi Tian, Yuqing Wang, Bo Zhang et al.NeurIPS 2021 · 1,388 citations
Related papers
- Tokens-to-Token ViT: Training Vision Transformers from Scratch on ImageNetLi Yuan, Yunpeng Chen, Tao Wang, Weihao Yu et al.ICCV 2021 · 2,462 citations
- Always Skip AttentionYiping Ji, Hemanth Saratchandran, Peyman Moghadam, Simon LuceyICCV 2025
- SPOT: Sparsification with Attention Dynamics via Token Relevance in Vision TransformersOded Schlesinger, Amirhossein Farzam, J. Matias Di Martino, Guillermo SapiroCVPR Findings 2026
- You Only Need Less Attention at Each Stage in Vision TransformersShuoxi Zhang, Hanpeng Liu, Stephen Lin, Kun HeCVPR 2024 · 19 citations
- Evo-ViT: Slow-Fast Token Evolution for Dynamic Vision TransformerYifan Xu, Zhijie Zhang, Mengdan Zhang, Kekai Sheng et al.AAAI 2022 · 288 citations
