mlsanityData to 7 Oct 2026

Mechanics of Next Token Prediction with Self-Attention

arXiv 2403.08081 ↗First posted 12 Mar 2024cs.LG cs.AI cs.CLcited by 34

Not on the map. Why?

Abstract (arXiv)

Transformer-based language models are trained on large datasets to predict the next token given an input sequence. Despite this simple training objective, they have led to revolutionary advances in natural language processing. Underlying this success is the self-attention mechanism. In this work, we ask: textitWhat textitdoes textita textitsingle textitself-attention textitlayer textitlearn textitfrom textitnext-token textitprediction? We show that training self-attention with gradient descent learns an automaton which generates the next token in two distinct steps: (1) Hard retrieval: Given input sequence, self-attention precisely selects the textithigh-priority textitinput textittokens associated with the last input token. (2) Soft composition: It then creates a convex combination of the high-priority tokens from which the next token can be sampled. Under suitable conditions, we rigorously characterize these mechanics through a directed graph over tokens extracted from the training data. We prove that gradient descent implicitly discovers the strongly-connected components (SCC) of this graph and self-attention learns to retrieve the tokens that belong to the highest-priority SCC available in the context window. Our theory relies on decomposing the model weights into a directional component and a finite component that correspond to hard retrieval and soft composition steps respectively. This also formalizes a related implicit bias formula conjectured in [Tarzanagh et al. 2023]. We hope that these findings shed light on how self-attention processes sequential data and pave the path toward demystifying more complex architectures.

Key facts. Cited by 34 papers in the map (data through 7 Oct 2026). Builds on 44 of its 64 references that are in the map. First posted on arXiv 12 Mar 2024.

Builds on

44 of 64 references.

References · 44

  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. 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
  5. 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,304
  6. 2021Decision Transformer: Reinforcement Learning via Sequence Modelingcited by 1,528
  7. 2021An Explanation of In-context Learning as Implicit Bayesian Inferencecited by 915
  8. 2022Transformers learn in-context by gradient descentcited by 714
  9. 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 700
  10. 2022What learning algorithm is in-context learning? Investigations with linear modelscited by 671
  11. 2017The Implicit Bias of Gradient Descent on Separable Datacited by 649
  12. 2021Attention is Not All You Need: Pure Attention Loses Rank Doubly Exponentially with Depthcited by 411
32 more
  1. 2019Are Transformers universal approximators of sequence-to-sequence functions?cited by 404
  2. 2016Using the Output Embedding to Improve Language Modelscited by 266
  3. 2018Characterizing Implicit Bias in Terms of Optimization Geometrycited by 259
  4. 2023Transformers as Algorithms: Generalization and Stability in In-context Learningcited by 220
  5. 2019Towards Explaining the Regularization Effect of Initial Large Learning Rate in Training Neural Networkscited by 162
  6. 2022ProGen2: Exploring the Boundaries of Protein Language Modelscited by 156
  7. 2021Inductive Biases and Variable Creation in Self-Attention Mechanismscited by 144
  8. 2019Implicit regularization for deep neural networks driven by an Ornstein-Uhlenbeck like processcited by 123
  9. 2023In-Context Convergence of Transformerscited by 112
  10. 2023Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformercited by 101
  11. 2022Vision Transformers provably learn spatial structurecited by 92
  12. 2023How Do Transformers Learn Topic Structure: Towards a Mechanistic Understandingcited by 85
  13. 2019Generative Pre-Training for Speech with Autoregressive Predictive Codingcited by 82
  14. 2020O(n) Connections are Expressive Enough: Universal Approximability of Sparse Transformerscited by 82
  15. 2018Risk and parameter convergence of logistic regressioncited by 81
  16. 2023A Theoretical Understanding of Shallow Vision Transformers: Learning, Generalization, and Sample Complexitycited by 77
  17. 2021Label-Imbalanced and Group-Sensitive Classification under Overparameterizationcited by 74
  18. 2024Training Dynamics of Multi-Head Softmax Attention for In-Context Learning: Emergence, Convergence, and Optimalitycited by 71
  19. 2023Transformers as Support Vector Machinescited by 67
  20. 2020Gradient descent follows the regularization path for general lossescited by 57
  21. 2023On the Role of Attention in Prompt-tuningcited by 49
  22. 2020The Implicit Bias for Adaptive Optimization Algorithms on Homogeneous Neural Networkscited by 43
  23. 2023What can a Single Attention Layer Learn? A Study Through the Random Features Lenscited by 39
  24. 2024An Information-Theoretic Analysis of In-Context Learningcited by 39
  25. 2024Attention with Markov: A Framework for Principled Analysis of Transformers via Markov Chainscited by 39
  26. 2023On the Optimization and Generalization of Multi-head Attentioncited by 37
  27. 2024How Do Nonlinear Transformers Learn and Generalize in In-Context Learning?cited by 35
  28. 2024From Self-Attention to Markov Models: Unveiling the Dynamics of Generative Transformerscited by 34
  29. 2024In-Context Learning with Transformers: Softmax Attention Adapts to Function Lipschitznesscited by 22
  30. 2024Provably learning a multi-head attention layercited by 21
  31. 2019The Implicit Bias of AdaGrad on Separable Datacited by 15
  32. 2024Towards Understanding the Word Sensitivity of Attention Layers: A Study via Random Featurescited by 5

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2024: 12; 2025: 13; 2026: 9.

34 papers.

Sort:

By area:

  1. 2024TS-Reasoner: Domain-Oriented Time Series Inference Agents for Reasoning and Automated Analysiscited by 28
  2. 2024Do LLMs dream of elephants (when told not to)? Latent concept association and associative memory in transformerscited by 14
  3. 2024Training Nonlinear Transformers for Chain-of-Thought Inference: A Theoretical Generalization Analysiscited by 14
  4. 2024Non-asymptotic Convergence of Training Transformers for Next-token Predictioncited by 13
  5. 2024Next-token prediction capacity: general upper bounds and a lower bound for transformerscited by 11
  6. 2025Gating is Weighting: Understanding Gated Linear Attention through In-context Learningcited by 11
  7. 2025How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit Biascited by 10
  8. 2025Generalization or Hallucination? Understanding Out-of-Context Reasoning in Transformerscited by 10
  9. 2024Optimizing Attention with Mirror Descent: Generalized Max-Margin Token Selectioncited by 9
  10. 2025Sequential keypoint density estimator: an overlooked baseline of skeleton-based video anomaly detectioncited by 7
  11. 2024On the Learn-to-Optimize Capabilities of Transformers in In-Context Sparse Recoverycited by 6
  12. 2025Decoupling Positional and Symbolic Attention Behavior in Transformerscited by 6
22 more
  1. 2024On Mesa-Optimization in Autoregressively Trained Transformers: Emergence and Capabilitycited by 5
  2. 2024On the Power of Convolution Augmented Transformercited by 5
  3. 2025FloorPlan-DeepSeek (FPDS): A multimodal approach to floorplan generation using vector-based next room predictioncited by 3
  4. 2025Facts in Stats: Impacts of Pretraining Diversity on Language Model Generalizationcited by 3
  5. 2025Dynamics of Spontaneous Topic Changes in Next Token Prediction with Self-Attentioncited by 2
  6. 2026Unlabeled Data Can Provably Enhance In-Context Learning of Transformerscited by 2
  7. 2026Breaking the Reversal Curse in Autoregressive Language Models via Identity Bridgecited by 2
  8. 2026REAL: A Reasoning-Enhanced Graph Framework for Long-Term Memory Management of LLMscited by 2
  9. 2024Recent Advances in Federated Learning Driven Large Language Models: A Survey on Architecture, Performance, and Securitycited by 1
  10. 2024Reorganizing attention-space geometry with expressive attentioncited by 1
  11. 2025How Transformers Learn In-Context Recall Tasks? Optimality, Training Dynamics and Generalizationcited by 1
  12. 2025Towards Understanding Transformers in Learning Random Walkscited by 1
  13. 2026Transformers Provably Learn to Internalize Chain-of-Thoughtcited by 1
  14. 2024Large Investment Modelcited by 0
  15. 2025On Next-Token Prediction in LLMs: How End Goals Determine the Consistency of Decoding Algorithmscited by 0
  16. 2025Attention with Trained Embeddings Provably Selects Important Tokenscited by 0
  17. 2025Fighter: Unveiling the Graph Convolutional Nature of Transformers in Time Series Modelingcited by 0
  18. 2026The Illusion of Friendship: Why Generative AI Demands Unprecedented Ethical Vigilancecited by 0
  19. 2026SimReg: Achieving Higher Performance in the Pretraining via Embedding Similarity Regularizationcited by 0
  20. 2026Faster Query-Key Learning Sharpens Attention in Self-Attention Modelscited by 0
  21. 2026Linear RNN Scaling Laws: When Longer Sequences Beat More Sequencescited by 0
  22. 2026Information-Theoretic Analysis of Next-Token Prediction under Markovian Datacited by 0