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

Aditya Varre, Gizem Yüce, Nicolas Flammarion
8/18/2025
cs.LG

No confident code implementation found for this paper.

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 \leq 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-$n$-grams are near-stationary points of the population cross-entropy loss}, offering theoretical insight into widely observed phenomena such as stage-wise 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.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{varre2025learning,
  title  = {Learning In-context n-grams with Transformers: Sub-n-grams Are Near-stationary Points},
  author = {Aditya Varre and Gizem Yüce and Nicolas Flammarion},
  year   = {2025},
  eprint = {2508.12837},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2508.12837v2},
  journal = {ICML 2025 2025}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2508.12837.svg)](https://codeofpaper.com/paper/2508.12837)

Discussion