Mechanics of Next Token Prediction with Self-Attention
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
- 2017Attention Is All You Needcited by 59,932
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2023GPT-4 Technical Reportcited by 18,132
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
- 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,304
- 2021Decision Transformer: Reinforcement Learning via Sequence Modelingcited by 1,528
- 2021An Explanation of In-context Learning as Implicit Bayesian Inferencecited by 915
- 2022Transformers learn in-context by gradient descentcited by 714
- 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 700
- 2022What learning algorithm is in-context learning? Investigations with linear modelscited by 671
- 2017The Implicit Bias of Gradient Descent on Separable Datacited by 649
- 2021Attention is Not All You Need: Pure Attention Loses Rank Doubly Exponentially with Depthcited by 411
32 more
- 2019Are Transformers universal approximators of sequence-to-sequence functions?cited by 404
- 2016Using the Output Embedding to Improve Language Modelscited by 266
- 2018Characterizing Implicit Bias in Terms of Optimization Geometrycited by 259
- 2023Transformers as Algorithms: Generalization and Stability in In-context Learningcited by 220
- 2019Towards Explaining the Regularization Effect of Initial Large Learning Rate in Training Neural Networkscited by 162
- 2022ProGen2: Exploring the Boundaries of Protein Language Modelscited by 156
- 2021Inductive Biases and Variable Creation in Self-Attention Mechanismscited by 144
- 2019Implicit regularization for deep neural networks driven by an Ornstein-Uhlenbeck like processcited by 123
- 2023In-Context Convergence of Transformerscited by 112
- 2023Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformercited by 101
- 2022Vision Transformers provably learn spatial structurecited by 92
- 2023How Do Transformers Learn Topic Structure: Towards a Mechanistic Understandingcited by 85
- 2019Generative Pre-Training for Speech with Autoregressive Predictive Codingcited by 82
- 2020O(n) Connections are Expressive Enough: Universal Approximability of Sparse Transformerscited by 82
- 2018Risk and parameter convergence of logistic regressioncited by 81
- 2023A Theoretical Understanding of Shallow Vision Transformers: Learning, Generalization, and Sample Complexitycited by 77
- 2021Label-Imbalanced and Group-Sensitive Classification under Overparameterizationcited by 74
- 2024Training Dynamics of Multi-Head Softmax Attention for In-Context Learning: Emergence, Convergence, and Optimalitycited by 71
- 2023Transformers as Support Vector Machinescited by 67
- 2020Gradient descent follows the regularization path for general lossescited by 57
- 2023On the Role of Attention in Prompt-tuningcited by 49
- 2020The Implicit Bias for Adaptive Optimization Algorithms on Homogeneous Neural Networkscited by 43
- 2023What can a Single Attention Layer Learn? A Study Through the Random Features Lenscited by 39
- 2024An Information-Theoretic Analysis of In-Context Learningcited by 39
- 2024Attention with Markov: A Framework for Principled Analysis of Transformers via Markov Chainscited by 39
- 2023On the Optimization and Generalization of Multi-head Attentioncited by 37
- 2024How Do Nonlinear Transformers Learn and Generalize in In-Context Learning?cited by 35
- 2024From Self-Attention to Markov Models: Unveiling the Dynamics of Generative Transformerscited by 34
- 2024In-Context Learning with Transformers: Softmax Attention Adapts to Function Lipschitznesscited by 22
- 2024Provably learning a multi-head attention layercited by 21
- 2019The Implicit Bias of AdaGrad on Separable Datacited by 15
- 2024Towards Understanding the Word Sensitivity of Attention Layers: A Study via Random Featurescited by 5
Built on by
Citing papers per year: 2024: 12; 2025: 13; 2026: 9.
34 papers.
Sort:
By area:
- 2024TS-Reasoner: Domain-Oriented Time Series Inference Agents for Reasoning and Automated Analysiscited by 28
- 2024Do LLMs dream of elephants (when told not to)? Latent concept association and associative memory in transformerscited by 14
- 2024Training Nonlinear Transformers for Chain-of-Thought Inference: A Theoretical Generalization Analysiscited by 14
- 2024Non-asymptotic Convergence of Training Transformers for Next-token Predictioncited by 13
- 2024Next-token prediction capacity: general upper bounds and a lower bound for transformerscited by 11
- 2025Gating is Weighting: Understanding Gated Linear Attention through In-context Learningcited by 11
- 2025How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit Biascited by 10
- 2025Generalization or Hallucination? Understanding Out-of-Context Reasoning in Transformerscited by 10
- 2024Optimizing Attention with Mirror Descent: Generalized Max-Margin Token Selectioncited by 9
- 2025Sequential keypoint density estimator: an overlooked baseline of skeleton-based video anomaly detectioncited by 7
- 2024On the Learn-to-Optimize Capabilities of Transformers in In-Context Sparse Recoverycited by 6
- 2025Decoupling Positional and Symbolic Attention Behavior in Transformerscited by 6
22 more
- 2024On Mesa-Optimization in Autoregressively Trained Transformers: Emergence and Capabilitycited by 5
- 2024On the Power of Convolution Augmented Transformercited by 5
- 2025FloorPlan-DeepSeek (FPDS): A multimodal approach to floorplan generation using vector-based next room predictioncited by 3
- 2025Facts in Stats: Impacts of Pretraining Diversity on Language Model Generalizationcited by 3
- 2025Dynamics of Spontaneous Topic Changes in Next Token Prediction with Self-Attentioncited by 2
- 2026Unlabeled Data Can Provably Enhance In-Context Learning of Transformerscited by 2
- 2026Breaking the Reversal Curse in Autoregressive Language Models via Identity Bridgecited by 2
- 2026REAL: A Reasoning-Enhanced Graph Framework for Long-Term Memory Management of LLMscited by 2
- 2024Recent Advances in Federated Learning Driven Large Language Models: A Survey on Architecture, Performance, and Securitycited by 1
- 2024Reorganizing attention-space geometry with expressive attentioncited by 1
- 2025How Transformers Learn In-Context Recall Tasks? Optimality, Training Dynamics and Generalizationcited by 1
- 2025Towards Understanding Transformers in Learning Random Walkscited by 1
- 2026Transformers Provably Learn to Internalize Chain-of-Thoughtcited by 1
- 2024Large Investment Modelcited by 0
- 2025On Next-Token Prediction in LLMs: How End Goals Determine the Consistency of Decoding Algorithmscited by 0
- 2025Attention with Trained Embeddings Provably Selects Important Tokenscited by 0
- 2025Fighter: Unveiling the Graph Convolutional Nature of Transformers in Time Series Modelingcited by 0
- 2026The Illusion of Friendship: Why Generative AI Demands Unprecedented Ethical Vigilancecited by 0
- 2026SimReg: Achieving Higher Performance in the Pretraining via Embedding Similarity Regularizationcited by 0
- 2026Faster Query-Key Learning Sharpens Attention in Self-Attention Modelscited by 0
- 2026Linear RNN Scaling Laws: When Longer Sequences Beat More Sequencescited by 0
- 2026Information-Theoretic Analysis of Next-Token Prediction under Markovian Datacited by 0
- 2026Information-Theoretic Analysis of Next-Token Prediction under Markovian Data28 Sep 2026
- 2026Linear RNN Scaling Laws: When Longer Sequences Beat More Sequences23 Aug 2026
- 2026Faster Query-Key Learning Sharpens Attention in Self-Attention Models7 Aug 2026
- 2026REAL: A Reasoning-Enhanced Graph Framework for Long-Term Memory Management of LLMs9 Jun 2026
- 2026Transformers Provably Learn to Internalize Chain-of-Thought27 May 2026
- 2026SimReg: Achieving Higher Performance in the Pretraining via Embedding Similarity Regularization9 May 2026
- 2026Breaking the Reversal Curse in Autoregressive Language Models via Identity Bridge2 Feb 2026
- 2026Unlabeled Data Can Provably Enhance In-Context Learning of Transformers15 Jan 2026
- 2026The Illusion of Friendship: Why Generative AI Demands Unprecedented Ethical Vigilance12 Jan 2026
- 2025Towards Understanding Transformers in Learning Random Walks28 Nov 2025
- 2025Fighter: Unveiling the Graph Convolutional Nature of Transformers in Time Series Modeling20 Oct 2025
- 2025Facts in Stats: Impacts of Pretraining Diversity on Language Model Generalization17 Oct 2025
22 more
- 2025Decoupling Positional and Symbolic Attention Behavior in Transformers3 Oct 2025
- 2025Sequential keypoint density estimator: an overlooked baseline of skeleton-based video anomaly detection23 Jun 2025
- 2025FloorPlan-DeepSeek (FPDS): A multimodal approach to floorplan generation using vector-based next room prediction12 Jun 2025
- 2025Generalization or Hallucination? Understanding Out-of-Context Reasoning in Transformers12 Jun 2025
- 2025Attention with Trained Embeddings Provably Selects Important Tokens22 May 2025
- 2025How Transformers Learn In-Context Recall Tasks? Optimality, Training Dynamics and Generalization21 May 2025
- 2025On Next-Token Prediction in LLMs: How End Goals Determine the Consistency of Decoding Algorithms16 May 2025
- 2025How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit Bias2 May 2025
- 2025Gating is Weighting: Understanding Gated Linear Attention through In-context Learning6 Apr 2025
- 2025Dynamics of Spontaneous Topic Changes in Next Token Prediction with Self-Attention10 Jan 2025
- 2024Optimizing Attention with Mirror Descent: Generalized Max-Margin Token Selection18 Oct 2024
- 2024On the Learn-to-Optimize Capabilities of Transformers in In-Context Sparse Recovery17 Oct 2024
- 2024TS-Reasoner: Domain-Oriented Time Series Inference Agents for Reasoning and Automated Analysis5 Oct 2024
- 2024Training Nonlinear Transformers for Chain-of-Thought Inference: A Theoretical Generalization Analysis3 Oct 2024
- 2024Non-asymptotic Convergence of Training Transformers for Next-token Prediction25 Sep 2024
- 2024Large Investment Model12 Aug 2024
- 2024Reorganizing attention-space geometry with expressive attention26 Jul 2024
- 2024On the Power of Convolution Augmented Transformer8 Jul 2024
- 2024Do LLMs dream of elephants (when told not to)? Latent concept association and associative memory in transformers26 Jun 2024
- 2024Recent Advances in Federated Learning Driven Large Language Models: A Survey on Architecture, Performance, and Security14 Jun 2024
- 2024On Mesa-Optimization in Autoregressively Trained Transformers: Emergence and Capability27 May 2024
- 2024Next-token prediction capacity: general upper bounds and a lower bound for transformers22 May 2024
- 2024TS-Reasoner: Domain-Oriented Time Series Inference Agents for Reasoning and Automated Analysiscited by 28
- 2024Training Nonlinear Transformers for Chain-of-Thought Inference: A Theoretical Generalization Analysiscited by 14
- 2025Generalization or Hallucination? Understanding Out-of-Context Reasoning in Transformerscited by 10
- 2026Breaking the Reversal Curse in Autoregressive Language Models via Identity Bridgecited by 2
- 2026REAL: A Reasoning-Enhanced Graph Framework for Long-Term Memory Management of LLMscited by 2
- 2026Transformers Provably Learn to Internalize Chain-of-Thoughtcited by 1
- 2026REAL: A Reasoning-Enhanced Graph Framework for Long-Term Memory Management of LLMs9 Jun 2026
- 2026Transformers Provably Learn to Internalize Chain-of-Thought27 May 2026
- 2026Breaking the Reversal Curse in Autoregressive Language Models via Identity Bridge2 Feb 2026
- 2025Generalization or Hallucination? Understanding Out-of-Context Reasoning in Transformers12 Jun 2025
- 2024TS-Reasoner: Domain-Oriented Time Series Inference Agents for Reasoning and Automated Analysis5 Oct 2024
- 2024Training Nonlinear Transformers for Chain-of-Thought Inference: A Theoretical Generalization Analysis3 Oct 2024
- 2024Do LLMs dream of elephants (when told not to)? Latent concept association and associative memory in transformerscited by 14
- 2024Non-asymptotic Convergence of Training Transformers for Next-token Predictioncited by 13
- 2024Next-token prediction capacity: general upper bounds and a lower bound for transformerscited by 11
- 2025Gating is Weighting: Understanding Gated Linear Attention through In-context Learningcited by 11
- 2025How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit Biascited by 10
- 2024Optimizing Attention with Mirror Descent: Generalized Max-Margin Token Selectioncited by 9
- 2025Sequential keypoint density estimator: an overlooked baseline of skeleton-based video anomaly detectioncited by 7
- 2024On the Learn-to-Optimize Capabilities of Transformers in In-Context Sparse Recoverycited by 6
- 2025Decoupling Positional and Symbolic Attention Behavior in Transformerscited by 6
- 2024On Mesa-Optimization in Autoregressively Trained Transformers: Emergence and Capabilitycited by 5
- 2024On the Power of Convolution Augmented Transformercited by 5
- 2025FloorPlan-DeepSeek (FPDS): A multimodal approach to floorplan generation using vector-based next room predictioncited by 3
12 most cited of 26 All 26 (JSON)
- 2026Information-Theoretic Analysis of Next-Token Prediction under Markovian Data28 Sep 2026
- 2026Linear RNN Scaling Laws: When Longer Sequences Beat More Sequences23 Aug 2026
- 2026Faster Query-Key Learning Sharpens Attention in Self-Attention Models7 Aug 2026
- 2026Unlabeled Data Can Provably Enhance In-Context Learning of Transformers15 Jan 2026
- 2026The Illusion of Friendship: Why Generative AI Demands Unprecedented Ethical Vigilance12 Jan 2026
- 2025Towards Understanding Transformers in Learning Random Walks28 Nov 2025
- 2025Fighter: Unveiling the Graph Convolutional Nature of Transformers in Time Series Modeling20 Oct 2025
- 2025Facts in Stats: Impacts of Pretraining Diversity on Language Model Generalization17 Oct 2025
- 2025Decoupling Positional and Symbolic Attention Behavior in Transformers3 Oct 2025
- 2025Sequential keypoint density estimator: an overlooked baseline of skeleton-based video anomaly detection23 Jun 2025
- 2025FloorPlan-DeepSeek (FPDS): A multimodal approach to floorplan generation using vector-based next room prediction12 Jun 2025
- 2025Attention with Trained Embeddings Provably Selects Important Tokens22 May 2025
12 newest of 26 All 26 (JSON)