Asymptotic theory of in-context learning by linear attention
Yue M. Lu, Mary I. Letey, Jacob A. Zavatone-Veth, Anindita Maiti, Cengiz Pehlevan
TL;DR
This work addresses the question of when in-context learning (ICL) emerges in Transformer-like architectures by analyzing an exactly solvable linear-attention model for linear regression. It develops a sharp joint-asymptotic theory in a scaling limit with $ rac{ℓ}{d}=oldsymbol{α}$, $ rac{k}{d}=oldsymbol{κ}$, and $ rac{n}{d^2}=oldsymbol{τ}$, deriving deterministic generalization-error curves $e^{ICL}(oldsymbol{τ},oldsymbol{α},oldsymbol{κ},ρ, ext{λ})$ and $e^{IDG}(oldsymbol{τ},oldsymbol{α},oldsymbol{κ},ρ, ext{λ})$ that reveal a double-descent phenomenon and a phase transition as task diversity grows. The results show memorization vs. genuine ICL behavior separated by a diversity threshold near $oldsymbol{κ}=1$, and demonstrate non-monotone dependence of errors on context length $oldsymbol{α}$, with sharp predictions confirmed by experiments on both linear and nonlinear Transformers. The findings provide mechanistic insight into how pretraining data size, context length, and task diversity control ICL and its generalization, and they suggest that similar scaling laws extend to full Transformer architectures. Overall, the work connects random-matrix theory to practical questions about pretraining and context-based learning, offering principled guidance for designing pretraining curricula to induce robust ICL. The conclusions indicate that in-context learning can arise without full Transformer complexity, while also showing when such capabilities robustly generalize to new tasks in a principled, scalable regime.
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 in-context learning 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.
