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

Aditya Varre, Gizem Yüce, Nicolas Flammarion
Proceedings of the 42nd International Conference on Machine Learning, PMLR 267:60924-60963, 2025.

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.

Cite this Paper


BibTeX
@InProceedings{pmlr-v267-varre25a, title = {Learning In-context $n$-grams with Transformers: Sub-$n$-grams Are Near-Stationary Points}, author = {Varre, Aditya and Y\"{u}ce, Gizem and Flammarion, Nicolas}, booktitle = {Proceedings of the 42nd International Conference on Machine Learning}, pages = {60924--60963}, year = {2025}, editor = {Singh, Aarti and Fazel, Maryam and Hsu, Daniel and Lacoste-Julien, Simon and Berkenkamp, Felix and Maharaj, Tegan and Wagstaff, Kiri and Zhu, Jerry}, volume = {267}, series = {Proceedings of Machine Learning Research}, month = {13--19 Jul}, publisher = {PMLR}, pdf = {https://raw.githubusercontent.com/mlresearch/v267/main/assets/varre25a/varre25a.pdf}, url = {https://proceedings.mlr.press/v267/varre25a.html}, 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.} }
Endnote
%0 Conference Paper %T Learning In-context $n$-grams with Transformers: Sub-$n$-grams Are Near-Stationary Points %A Aditya Varre %A Gizem Yüce %A Nicolas Flammarion %B Proceedings of the 42nd International Conference on Machine Learning %C Proceedings of Machine Learning Research %D 2025 %E Aarti Singh %E Maryam Fazel %E Daniel Hsu %E Simon Lacoste-Julien %E Felix Berkenkamp %E Tegan Maharaj %E Kiri Wagstaff %E Jerry Zhu %F pmlr-v267-varre25a %I PMLR %P 60924--60963 %U https://proceedings.mlr.press/v267/varre25a.html %V 267 %X 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.
APA
Varre, A., Yüce, G. & Flammarion, N.. (2025). Learning In-context $n$-grams with Transformers: Sub-$n$-grams Are Near-Stationary Points. Proceedings of the 42nd International Conference on Machine Learning, in Proceedings of Machine Learning Research 267:60924-60963 Available from https://proceedings.mlr.press/v267/varre25a.html.

Related Material