Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks

Tianyu He, Darshil Doshi, Aritra Das, Andrey Gromov
6/4/2024
cs.LGcond-mat.dis-nnhep-th

No official code found. Best implementation: ablghtianyi/ICL_Modular_Arithmetic (19 stars, MIT, last commit 2025-03-25).

Abstract

Large language models can solve tasks that were not present in the training set. This capability is believed to be due to in-context learning and skill composition. In this work, we study the emergence of in-context learning and skill composition in a collection of modular arithmetic tasks. Specifically, we consider a finite collection of linear modular functions $z = a \, x + b \, y \;\mathrm{mod}\; p$ labeled by the vector $(a, b) \in \mathbb{Z}_p^2$. We use some of these tasks for pre-training and the rest for out-of-distribution testing. We empirically show that a GPT-style transformer exhibits a transition from in-distribution to out-of-distribution generalization as the number of pre-training tasks increases. We find that the smallest model capable of out-of-distribution generalization requires two transformer blocks, while for deeper models, the out-of-distribution generalization phase is \emph{transient}, necessitating early stopping. Finally, we perform an interpretability study of the pre-trained models, revealing highly structured representations in both attention heads and MLPs; and discuss the learned algorithms. Notably, we find an algorithmic shift in deeper models, as we go from few to many in-context examples.

View on arXivView PDF

Code Implementations(1)

MIT
195Shell, PythonMay 26, 20241 years agoMIT

Similar Papers

Cite this paper

@article{he2024learning,
  title  = {Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks},
  author = {Tianyu He and Darshil Doshi and Aritra Das and Andrey Gromov},
  year   = {2024},
  eprint = {2406.02550},
  archivePrefix = {arXiv},
  doi    = {10.48550/arXiv.2406.02550},
  url    = {http://arxiv.org/abs/2406.02550v2},
  journal = {NEURIPS 2024 2024}
}

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/2406.02550.svg)](https://codeofpaper.com/paper/2406.02550)

Discussion