Asymptotic theory of in-context learning by linear attention
Year: 2025
Type: article
Abstract: Transformers have a remarkable ability to learn and execute tasks based on examples provided within the input itself, without explicit prior training. It has been argued that this capability, known as in-context learning (ICL), is a cornerstone of Transformers' success, yet questions about the necessary sample complexity, pretraining task diversity, and context length for successful ICL remain unresolved. Here, we provide a precise answer to these questions in an exactly solvable model of ICL of a linear regression task by linear attention. We derive sharp asymptotics for the learning curve in a phenomenologically rich scaling regime where the token dimension is taken to infinity; the context length and pretraining task diversity scale proportionally with the token dimension; and the number of pretraining examples scales quadratically. We demonstrate a double-descent learning curve with increasing pretraining examples, and uncover a phase transition in the model's behavior between low and high task diversity regimes: in the low diversity regime, the model tends toward memorization of training tasks, whereas in the high diversity regime, it achieves genuine ICL and generalization beyond the scope of pretrained tasks. These theoretical insights are empirically validated through experiments with both linear attention and full nonlinear Transformer architectures.
Institutions: Harvard University, Perimeter Institute
Language: English
Subfield: Artificial Intelligence
Field: Computer Science
Domain: Physical Sciences
Open Access status: hybrid
Awards: G1260225967, G2906497980, G3398237449, A Theory of Learned Representations in Artificial and Natural Neural Networks, CAREER: Developing Neural Network Theory for Uncovering How the Brain Learns, G4689434848, G5261598906, CIF: Small: Exploring and Exploiting the Universality Phenomenon in High-Dimensional Estimation, G6671297155, Kavli Institute for Theoretical Physics, Kavli Institute for Theoretical Physics, G877582935, G985207216
OpenAlex ID: W4412122873
