mlsanityData to 7 Oct 2026

How Transformers Utilize Multi-Head Attention in In-Context Learning? A Case Study on Sparse Linear Regression

arXiv 2408.04532 ↗First posted 8 Aug 2024cs.LGcited by 13

Not on the map. Why?

Abstract (arXiv)

Despite the remarkable success of transformer-based models in various real-world tasks, their underlying mechanisms remain poorly understood. Recent studies have suggested that transformers can implement gradient descent as an in-context learner for linear regression problems and have developed various theoretical analyses accordingly. However, these works mostly focus on the expressive power of transformers by designing specific parameter constructions, lacking a comprehensive understanding of their inherent working mechanisms post-training. In this study, we consider a sparse linear regression problem and investigate how a trained multi-head transformer performs in-context learning. We experimentally discover that the utilization of multi-heads exhibits different patterns across layers: multiple heads are utilized and essential in the first layer, while usually only a single head is sufficient for subsequent layers. We provide a theoretical explanation for this observation: the first layer preprocesses the context data, and the following layers execute simple optimization steps based on the preprocessed context. Moreover, we demonstrate that such a preprocess-then-optimize algorithm can significantly outperform naive gradient descent and ridge regression algorithms. Further experimental results support our explanations. Our findings offer insights into the benefits of multi-head attention and contribute to understanding the more intricate mechanisms hidden within trained transformers.

Key facts. Cited by 13 papers in the map (data through 7 Oct 2026). Builds on 52 of its 57 references that are in the map. First posted on arXiv 8 Aug 2024.

Builds on

52 of 57 references.

References · 52

  1. 2017Attention Is All You Needcited by 59,932
  2. 2020Language Models are Few-Shot Learnerscited by 32,199
  3. 2023GPT-4 Technical Reportcited by 18,132
  4. 2022Training language models to follow instructions with human feedbackcited by 15,712
  5. 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
  6. 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 12,865
  7. 2019HuggingFace's Transformers: State-of-the-art Natural Language Processingcited by 2,201
  8. 2016Understanding intermediate layers using linear classifier probescited by 1,279
  9. 2016Pruning Filters for Efficient ConvNetscited by 1,129
  10. 2021An Explanation of In-context Learning as Implicit Bayesian Inferencecited by 915
  11. 2022Transformers learn in-context by gradient descentcited by 714
  12. 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 700
38 more
  1. 2022What learning algorithm is in-context learning? Investigations with linear modelscited by 671
  2. 2019Benign Overfitting in Linear Regressioncited by 544
  3. 2024ShortGPT: Layers in Large Language Models are More Redundant Than You Expectcited by 369
  4. 2023Trained Transformers Learn Linear Models In-Contextcited by 331
  5. 2023Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selectioncited by 291
  6. 2023Transformers learn to implement preconditioned gradient descent for in-context learningcited by 274
  7. 2023Physics of Language Models: Part 3.1, Knowledge Storage and Extractioncited by 264
  8. 2022Transformers Learn Shortcuts to Automatacited by 260
  9. 2023Looped Transformers as Programmable Computerscited by 224
  10. 2023Transformers as Algorithms: Generalization and Stability in In-context Learningcited by 220
  11. 2024The Unreasonable Ineffectiveness of the Deeper Layerscited by 219
  12. 2023What Algorithms can Transformers Learn? A Study in Length Generalizationcited by 198
  13. 2021Thinking Like Transformerscited by 182
  14. 2023One Step of Gradient Descent is Provably the Optimal In-Context Learner with One Layer of Linear Self-Attentioncited by 168
  15. 2020Benign overfitting in ridge regressioncited by 152
  16. 2023Physics of Language Models: Part 3.2, Knowledge Manipulationcited by 142
  17. 2024How Transformers Learn Causal Structure with Gradient Descentcited by 114
  18. 2023In-Context Convergence of Transformerscited by 112
  19. 2020Perturbed Masking: Parameter-free Probing for Analyzing and Interpreting BERTcited by 109
  20. 2023Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformercited by 101
  21. 2023Tracr: Compiled Transformers as a Laboratory for Interpretabilitycited by 99
  22. 2023How Many Pretraining Tasks Are Needed for In-Context Learning of Linear Regression?cited by 93
  23. 2023How Do Transformers Learn Topic Structure: Towards a Mechanistic Understandingcited by 85
  24. 2023How Do Transformers Learn In-Context Beyond Simple Functions? A Case Study on Learning with Representationscited by 72
  25. 2024Training Dynamics of Multi-Head Softmax Attention for In-Context Learning: Emergence, Convergence, and Optimalitycited by 71
  26. 2023Transformers as Support Vector Machinescited by 67
  27. 2023Transformers Implement Functional Gradient Descent to Learn Non-Linear Functions In Contextcited by 63
  28. 2023Are Transformers with One Layer Self-Attention Using Low-Rank Weight Matrices Universal Approximators?cited by 46
  29. 2023Learning Transformer Programscited by 40
  30. 2023Memorization Capacity of Multi-Head Attention in Transformerscited by 39
  31. 2021The Benefits of Implicit Regularization from SGD in Least Squares Problemscited by 32
  32. 2023Approximation and Estimation Ability of Transformers for Sequence-to-Sequence Functions with Infinite Dimensional Inputcited by 32
  33. 2024In-Context Learning of a Linear Transformer Block: Benefits of the MLP Component and One-Step GD Initializationcited by 30
  34. 2023CausalLM is not optimal for in-context learningcited by 26
  35. 2024How Well Can Transformers Emulate In-context Newton's Method?cited by 23
  36. 2024What Can Transformer Learn with Varying Depth? Case Studies on Sequence Learning Taskscited by 19
  37. 2023A Mechanism for Sample-Efficient In-Context Learning for Sparse Retrieval Taskscited by 17
  38. 2024Superiority of Multi-Head Attention in In-Context Linear Regressioncited by 17

50 most cited of 52 All 52 (JSON)

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2024: 2; 2025: 10; 2026: 1.

13 papers.

Sort:

By area: