Lune

NeurIPS2023Top-tier venue

Max-Margin Token Selection in Attention Mechanism

Davoud Ataee Tarzanagh, Yingcong Li, Xuechen Zhang, Samet Oymak

Abstract

Attention mechanism is a central component of the transformer architecture which led to the phenomenal success of large language models. However, the theoretical principles underlying the attention mechanism are poorly understood, especially its nonconvex optimization dynamics. In this work, we explore the seminal softmax-attention model f(X)=⟨Xv,softmax(XWp)⟩f(\boldsymbol{X})=\langle \boldsymbol{Xv}, \texttt{softmax}(\boldsymbol{XWp})\rangle, where X\boldsymbol{X} is the token sequence and (v,W,p)(\boldsymbol{v},\boldsymbol{W},\boldsymbol{p}) are trainable parameters. We prove that running gradient descent on p\boldsymbol{p}, or equivalently W\boldsymbol{W}, converges in direction to a max-margin solution that separates locally-optimal\textit{locally-optimal} tokens from non-optimal ones. This clearly formalizes attention as an optimal token selection mechanism. Remarkably, our results are applicable to general data and precisely characterize optimality\textit{optimality} of tokens in terms of the value embeddings Xv\boldsymbol{Xv} and problem geometry. We also provide a broader regularization path analysis that establishes the margin maximizing nature of attention even for nonlinear prediction heads. When optimizing v\boldsymbol{v} and p\boldsymbol{p} simultaneously with logistic loss, we identify conditions under which the regularization paths directionally converge to their respective hard-margin SVM solutions where v\boldsymbol{v} separates the input features based on their labels. Interestingly, the SVM formulation of p\boldsymbol{p} is influenced by the support vector geometry of v\boldsymbol{v}. Finally, we verify our theoretical findings via numerical experiments and provide insights.

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.

52 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers cites How Transformers Learn Causal Structure with Gradient Descent
  • Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers cites JoMA: Demystifying Multilayer Transformers via Joint Dynamics of MLP and Attention
  • Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers cites Language Models are Few-Shot Learners
  • Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers cites Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer
  • An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale cites Language Models are Few-Shot Learners
  • How Transformers Learn Causal Structure with Gradient Descent cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • How Transformers Learn Causal Structure with Gradient Descent cites JoMA: Demystifying Multilayer Transformers via Joint Dynamics of MLP and Attention
  • How Transformers Learn Causal Structure with Gradient Descent cites Language Models are Few-Shot Learners
  • How Transformers Learn Causal Structure with Gradient Descent cites Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer
  • JoMA: Demystifying Multilayer Transformers via Joint Dynamics of MLP and Attention cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • JoMA: Demystifying Multilayer Transformers via Joint Dynamics of MLP and Attention cites Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer
  • 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
  • Training data-efficient image transformers & distillation through attention cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Transformers Learn to Achieve Second-Order Convergence Rates for In-Context Linear Regression cites Language Models are Few-Shot Learners
  • 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 Language Models are Few-Shot Learners
  • Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer cites Learning Transferable Visual Models From Natural Language Supervision
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers52

  1. Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer TransformerYuandong Tian, Yiping Wang, Beidi Chen, Simon S. DuNeurIPS 2023 · 125 citations
  2. How Transformers Learn Causal Structure with Gradient DescentEshaan Nichani, Alex Damian, Jason D. LeeICML 2024 · 117 citations
  3. Transformers Learn to Achieve Second-Order Convergence Rates for In-Context Linear RegressionDeqing Fu, Tianqi Chen, Robin Jia, Vatsal SharanNeurIPS 2024 · 54 citations
  4. JoMA: Demystifying Multilayer Transformers via Joint Dynamics of MLP and AttentionYuandong Tian, Yiping Wang, Zhenyu Zhang, Beidi Chen et al.ICLR 2024 · 49 citations
  5. Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in TransformersSiyu Chen, Heejune Sheen, Tianhao Wang, Zhuoran YangNeurIPS 2024 · 48 citations

Builds on41

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. Learning Transferable Visual Models From Natural Language SupervisionAlec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh et al.ICML 2021 · 47,906 citations
  3. Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
  4. 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
  5. Training data-efficient image transformers & distillation through attentionHugo Touvron, Matthieu Cord, Matthijs Douze, Francisco Massa et al.ICML 2021 · 8,974 citations

Related papers

  1. Attention with Trained Embeddings Provably Selects Important TokensDiyuan Wu, Aleksandr Shevchenko, Samet Oymak, Marco MondelliNeurIPS 2025
  2. Unraveling the Gradient Descent Dynamics of TransformersBingqing Song, Boran Han, Shuai Zhang, Jie Ding et al.NeurIPS 2024 · 13 citations
  3. Softmax as Linear Attention in the Large-Prompt Regime: a Measure-based PerspectiveEtienne Boursier, Claire BoyerICML 2026 · 4 citations
  4. Understanding Softmax Attention Layers: Exact Mean-Field Analysis on a Toy ProblemElvis DohmatobNeurIPS 2025 · 3 citations
  5. Limitations of Normalization in AttentionTimur Mudarisov, Mikhail Burtsev, Tatiana Petrova, Radu StateNeurIPS 2025
Dusk over the sea between two cliffs drawn in fine vertical lines