Lune

ICML2025Top-tier venue

Learning In-context n-grams with Transformers: Sub-n-grams Are Near-Stationary Points

Aditya Varre, Gizem Yüce, Nicolas Flammarion

Abstract

Motivated by empirical observations of prolonged plateaus and stage-wise progression during training, we investigate the loss landscape of transformer models trained on in-context next-token prediction tasks. In particular, we focus on learning in-context n-gram language models under cross-entropy loss, and establish a sufficient condition for parameter configurations to be stationary points. We then construct a set of parameter configurations for a simplified transformer model that represent k-gram estimators (for k ⩽ n), and show that the gradient of the population loss at these solutions vanishes in the limit of infinite sequence length and parameter norm. This reveals a key property of the loss landscape: sub-ngrams are near-stationary points of the population cross-entropy loss, offering theoretical insight into widely observed phenomena such as stagewise learning dynamics and emergent phase transitions. These insights are further supported by numerical experiments that illustrate the learning dynamics of n-grams, characterized by discrete transitions between near-stationary solutions.

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.

7 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

  • Transformers learn to implement preconditioned gradient descent for in-context learning cites Language Models are Few-Shot Learners
  • Transformers learn to implement preconditioned gradient descent for in-context learning cites Transformers Learn In-Context by Gradient Descent
  • Transformers learn to implement preconditioned gradient descent for in-context learning cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • What Happens During the Loss Plateau? Understanding Abrupt Learning in Transformers cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • Transformers Learn Latent Mixture Models In-Context via Mirror Descent cites Transformers learn to implement preconditioned gradient descent for in-context learning
  • Transformers Learn Latent Mixture Models In-Context via Mirror Descent cites Language Models are Few-Shot Learners
  • Transformers Learn Latent Mixture Models In-Context via Mirror Descent cites Birth of a Transformer: A Memory Viewpoint
  • Transformers Learn Latent Mixture Models In-Context via Mirror Descent cites Transformers Learn In-Context by Gradient Descent
  • Transformers Learn Latent Mixture Models In-Context via Mirror Descent cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • Saddle-to-Saddle Dynamics Explains A Simplicity Bias Across Neural Network Architectures cites Incremental Learning of Sparse Attention Patterns in Transformers
  • Incremental Learning of Sparse Attention Patterns in Transformers cites Saddle-to-Saddle Dynamics Explains A Simplicity Bias Across Neural Network Architectures
  • Saddle-to-Saddle Dynamics Explains A Simplicity Bias Across Neural Network Architectures cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • Incremental Learning of Sparse Attention Patterns in Transformers cites Transformers learn to implement preconditioned gradient descent for in-context learning
  • Incremental Learning of Sparse Attention Patterns in Transformers cites Transformers Learn Latent Mixture Models In-Context via Mirror Descent
  • Incremental Learning of Sparse Attention Patterns in Transformers cites Birth of a Transformer: A Memory Viewpoint
  • Incremental Learning of Sparse Attention Patterns in Transformers cites Transformers Learn In-Context by Gradient Descent
  • Incremental Learning of Sparse Attention Patterns in Transformers cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • Birth of a Transformer: A Memory Viewpoint cites Language Models are Few-Shot Learners
  • Birth of a Transformer: A Memory Viewpoint cites Transformers Learn In-Context by Gradient Descent
  • Transformers Learn In-Context by Gradient Descent cites Language Models are Few-Shot Learners
  • Transformers Learn In-Context by Gradient Descent cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites Language Models are Few-Shot Learners
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers7

  1. Saddle-to-Saddle Dynamics Explains A Simplicity Bias Across Neural Network ArchitecturesYedi Zhang, Andrew M. Saxe, Peter E. LathamICLR 2026 · 15 citations
  2. What Happens During the Loss Plateau? Understanding Abrupt Learning in TransformersPulkit Gopalani, Wei HuNeurIPS 2025 · 6 citations
  3. Transformers Learn Latent Mixture Models In-Context via Mirror DescentFrancesco D'Angelo, Nicolas FlammarionICLR 2026 · 2 citations
  4. Incremental Learning of Sparse Attention Patterns in TransformersOğuz YükselICML 2026 · 2 citations
  5. Length Generalization Bounds for TransformersAndy Yang, Pascal Bergsträßer, Georg Zetzsche, David Chiang et al.ICML 2026

Builds on21

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 citations
  3. Transformers Learn In-Context by Gradient DescentJohannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento et al.ICML 2023 · 729 citations
  4. Transformers learn to implement preconditioned gradient descent for in-context learningKwangjun Ahn, Xiang Cheng, Hadi Daneshmand, Suvrit SraNeurIPS 2023 · 324 citations
  5. Birth of a Transformer: A Memory ViewpointAlberto Bietti, Vivien Cabannes, Diane Bouchacourt, Hervé Jégou et al.NeurIPS 2023 · 182 citations

Related papers

  1. The Evolution of Statistical Induction Heads: In-Context Learning Markov ChainsEzra Edelman, Nikolaos Tsilivis, Benjamin L. Edelman, Eran Malach et al.NeurIPS 2024 · 140 citations
  2. Optimality and NP-Hardness of Transformers in Learning Markovian Dynamical FunctionsYanna Ding, Songtao Lu, Yingdong Lu, Tomasz Nowicki et al.NeurIPS 2025 · 1 citation
  3. Transformers Learn Nonlinear Features In Context: Nonconvex Mean-field Dynamics on the Attention LandscapeJuno Kim, Taiji SuzukiICML 2024 · 42 citations
  4. Attention with Markov: A Curious Case of Single-layer TransformersAshok Vardhan Makkuva, Marco Bondaschi, Adway Girish, Alliot Nagle et al.ICLR 2025
  5. In-context Convergence of TransformersYu Huang, Yuan Cheng, Yingbin LiangICML 2024 · 114 citations
Dusk over the sea between two cliffs drawn in fine vertical lines