How Transformers Learn In-Context Recall Tasks? Optimality, Training Dynamics and Generalization
Not on the map. Why?
Abstract (arXiv)
We study the approximation capabilities, convergence speeds and on-convergence behaviors of transformers trained on in-context recall tasks -- which requires to recognize the positional association between a pair of tokens from in-context examples. Existing theoretical results only focus on the in-context reasoning behavior of transformers after being trained for the one gradient descent step. It remains unclear what is the on-convergence behavior of transformers being trained by gradient descent and how fast the convergence rate is. In addition, the generalization of transformers in one-step in-context reasoning has not been formally investigated. This work addresses these gaps. We first show that a class of transformers with either linear, ReLU or softmax attentions, is provably Bayes-optimal for an in-context recall task. When being trained with gradient descent, we show via a finite-sample analysis that the expected loss converges at linear rate to the Bayes risks. Moreover, we show that the trained transformers exhibit out-of-distribution (OOD) generalization, i.e., generalizing to samples outside of the population distribution. Our theoretical findings are further supported by extensive empirical validations, showing that without proper parameterization, models with larger expressive power surprisingly fail to generalize OOD after being trained by gradient descent.
Key facts. Cited by 1 paper in the map (data through 14 Oct 2026). Builds on 27 of its 33 references that are in the map. First posted on arXiv 21 May 2025.
Builds on
27 of 33 references.
References · 27
- 2017Attention Is All You Needcited by 60,361
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2023GPT-4 Technical Reportcited by 18,396
- 2021On the Opportunities and Risks of Foundation Modelscited by 4,033
- 2022Locating and Editing Factual Associations in GPTcited by 2,691
- 2020Transformer Feed-Forward Layers Are Key-Value Memoriescited by 1,336
- 2022Interpretability in the Wild: a Circuit for Indirect Object Identification in GPT-2 smallcited by 1,165
- 2023Trained Transformers Learn Linear Models In-Contextcited by 337
- 2023One Step of Gradient Descent is Provably the Optimal In-Context Learner with One Layer of Linear Self-Attentioncited by 170
- 2023Birth of a Transformer: A Memory Viewpointcited by 161
- 2023In-Context Convergence of Transformerscited by 115
- 2023Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformercited by 102
15 more
- 2023Linear attention is (maybe) all you need (to understand transformer optimization)cited by 98
- 2023Transformers as Support Vector Machinescited by 74
- 2023Transformers Implement Functional Gradient Descent to Learn Non-Linear Functions In Contextcited by 63
- 2023Max-Margin Token Selection in Attention Mechanismcited by 58
- 2023JoMA: Demystifying Multilayer Transformers via JOint Dynamics of MLP and Attentioncited by 52
- 2024Understanding Factual Recall in Transformers via Associative Memoriescited by 51
- 2023On the Optimization and Generalization of Multi-head Attentioncited by 37
- 2024Mechanics of Next Token Prediction with Self-Attentioncited by 34
- 2024Implicit Bias and Fast Convergence Rates for Self-attentioncited by 31
- 2024Superiority of Multi-Head Attention in In-Context Linear Regressioncited by 17
- 2024Implicit Optimization Bias of Next-Token Prediction in Linear Modelscited by 14
- 2024Non-asymptotic Convergence of Training Transformers for Next-token Predictioncited by 13
- 2024Distributional Associations vs In-Context Reasoning: A Study of Feed-forward and Attention Layerscited by 12
- 2025How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit Biascited by 11
- 2022Astral Space: Convex Analysis at Infinitycited by 6
Built on by
Citing papers per year: 2025: 1.
1 paper.
Similar, not cited
Close in wording, no citation either way
- 2024Context-Scaling versus Task-Scaling in In-Context Learning
- 2025Illusion or Algorithm? Investigating Memorization, Emergence, and Symbolic Processing in In-Context Learning
- 2026Implicit Statistical Inference in Transformers: Approximating Likelihood-Ratio Tests In-Context
- 2026Understanding Contextual Recall in Transformers: How Finetuning Enables In-Context Reasoning over Pretraining Knowledge
- 2026Transformers as In-Context Samplers: From Closed-Form Diffusion to Estimation-Free Sampling
- 2023The Transient Nature of Emergent In-Context Learning in Transformers
- 2026Mixture of Chapters: Scaling Learnt Memory in Transformers
- 2023Transformers Learn to Achieve Second-Order Convergence Rates for In-Context Linear Regression