In-Context Learning with Transformers: Softmax Attention Adapts to Function Lipschitzness
Liam Collins, Advait Parulekar, Aryan Mokhtari, Sujay Sanghavi, Sanjay Shakkottai
TL;DR
The paper investigates why softmax-attention in transformers supports in-context learning (ICL) beyond prior linear-attention analyses. It shows that pretraining calibrates the attention window by learning a bandwidth parameter $w_{KQ}$ such that the attention acts like a Nadaraya–Watson estimator with bandwidth $w_{KQ}$, scaling with the Lipschitz constant $L$, label noise $\sigma^2$, and context size $n$; hence the window widens for smaller $L$ and larger noise and narrows with larger $n$. It further demonstrates directional adaptivity in low-rank settings: for function classes with nonzero Lipschitzness only in a subspace spanned by $\mathbf{B}$, the pretrained $\mathbf{M}$ aligns with $\mathbf{B}\mathbf{B}^\top$, effectively projecting inputs onto the informative subspace. The work shows softmax is essential for this adaptivity, as linear attention cannot replicate the same ICL performance, and provides generalization bounds linking downstream Lipschitzness to pretraining. Together, these results illuminate how softmax-attention captures task structure during pretraining and enables robust ICL across related downstream tasks.
Abstract
A striking property of transformers is their ability to perform in-context learning (ICL), a machine learning framework in which the learner is presented with a novel context during inference implicitly through some data, and tasked with making a prediction in that context. As such, that learner must adapt to the context without additional training. We explore the role of softmax attention in an ICL setting where each context encodes a regression task. We show that an attention unit learns a window that it uses to implement a nearest-neighbors predictor adapted to the landscape of the pretraining tasks. Specifically, we show that this window widens with decreasing Lipschitzness and increasing label noise in the pretraining tasks. We also show that on low-rank, linear problems, the attention unit learns to project onto the appropriate subspace before inference. Further, we show that this adaptivity relies crucially on the softmax activation and thus cannot be replicated by the linear activation often studied in prior theoretical analyses.
