In-Context Learning with Transformers: Softmax Attention Adapts to Function Lipschitzness

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.

Paper

Similar papers

Peer review

Reviewer ftLf8/10 · confidence 3/52024-07-05

Summary

This study examines the impact of softmax attention on ICL regression, advancing beyond the typical linear treatment of the topic. In particular, the authors find that 1) softmax attention leads the model to adapt to the target function's Lipschitz constant and 2) enables the model to recover low dimensional structure in the target.

Strengths

The paper is very well-written and easy to read. It's great to see work that pushes beyond the usual linear treatment of attention, and explicitly considers the role of the softmax nonlinearity. The connection to kernel smoothing is very neat, and the resulting interpretation of softmax attention as an adaptive process sensitive to the target's Lipschitz constant is very insightful. I was particularly surprised that Lipschitz adaptation is both necessary and sufficient to illustrate the role of softmax attention in ICL regression, and that swapping function classes did not matter so long as the Lipschitz constant remained the same. Very cool work overall. Well done!

Weaknesses

I found no substantive weaknesses in the analysis, but do have some follow-up question listed below. As with any theory paper, there's always more that can be done, but I think the level of work demonstrated in this paper is more than sufficient to merit a strong accept.

Questions

- Could your results transfer in any way to an ICL classification setting, for instance like the one in [Reddy 2024](https://arxiv.org/abs/2312.03002) among others? Your Lipschitz adaptation argument, particularly as it controls a "window size" over inputs, sounds obliquely related to the way softmax attention is sometimes discussed as implementing "selection" or "copy" operations over context examples in ICL classification. I'm curious if there could be a deeper connection here? - When you train models in practice, do you find that the QKV matrices of the final model become like the M-parameterization of the matrices you highlight in eq. 4?

Rating

8

Confidence

3

Soundness

4

Presentation

4

Contribution

4

Limitations

The authors adequately address their limitations.

Reviewer BJxR7/10 · confidence 3/52024-07-12

Summary

This paper analyzes how softmax attention learns to perform in-context learning (ICL) through pretraining. The authors show that softmax attention adapts its "attention window" based on the Lipschitzness and noise characteristics of the pretraining tasks. They provide theoretical analysis for affine and ReLU-based function classes, demonstrating that softmax attention learns an optimal trade-off between bias and variance. The paper also explores how softmax attention can recover low-dimensional structure in the input space. Experiments are conducted to validate the theoretical findings.

Strengths

- The paper addresses an important and timely topic in understanding the mechanisms behind in-context learning in transformer models. This is a crucial area of research given the widespread adoption of large language models. The paper makes a novel connection between softmax attention and nearest neighbor regression, providing an intuitive interpretation of how ICL works in this setting. - The analysis is clean and the main message is clear: softmax activation plays a critical role in enabling effective in-context learning. For example, Theorem 3.4 provides concrete bounds on how the attention window scales with task Lipschitzness, noise level, and context size. Also, I like Theorem 3.5, whose test data are any arbitrary L−Lipschitz task, which is pretty general ICL setting. - The experimental results generally support the theoretical analysis. Figure 3 nicely illustrates how the spectral norm of M (representing the inverse of the attention window size) increases with the Lipschitz constant L, aligning with the theory.

Weaknesses

- There's a potential gap between the paper's main message and practical ICL scenarios. The analysis is based on a nearest-neighbor interpretation, but in real-world applications, LLMs often perform well even when there are no "close" examples in the context. - Some of the experimental writing and presentation could be improved. Figures 4 and 5 are particularly hard to follow without careful reading of the appendix. It would be helpful to have more detailed captions and clearer explanations in the main text. - The theoretical analysis is limited to relatively simple function classes (affine and ReLU-based). While this provides valuable insights, it's not clear how well these results generalize to the more complex functions learned by large language models in practice.

Questions

- How do you think your analysis might extend to more complex, hierarchical function classes that might better represent the capabilities of large language models? How can it be generally applied when there is no neighbor data? - Have you considered how your findings might relate to or explain the emergent capabilities observed in large language models as they scale?

Rating

7

Confidence

3

Soundness

3

Presentation

2

Contribution

3

Limitations

The authors acknowledge some limitations in Section 5, including that their model only considers the output of a single layer of attention and that establishing a mathematical framework for priming effects in LLMs remains an open challenge. These are important limitations to note, as they highlight the gap between this analysis and the full complexity of modern language models.

Reviewer hHKc7/10 · confidence 5/52024-07-15

Summary

This paper explores how softmax attention in transformer models enables in-context learning (ICL), where a model can adapt to solve new tasks using only a few input examples without additional training. The authors focus specifically on regression tasks, where the model must predict a continuous value given some input features. They show that during pretraining on a distribution of ICL regression tasks, softmax attention learns to implement a nearest neighbors predictor that is adapted to properties of the pretraining task distribution. The key insight is that softmax attention learns an "attention window" - a neighborhood around each input query point that determines which other input points influence the prediction. The size and shape of this attention window adapts based on properties of the pretraining tasks, specifically their Lipschitzness (how quickly function values can change) and the amount of label noise. Importantly, the authors demonstrate that learning this adapted attention window is crucial for generalization. The authors also prove that softmax attention can learn to project inputs onto a relevant low-dimensional subspace when the pretraining tasks depend only on projections of the inputs onto this subspace. To validate their theoretical results, the authors conduct experiments on synthetic regression tasks with varying Lipschitzness, noise levels, and input dimensionality. Empirically, the authors demonstrate that softmax attention learns appropriate attention window scales across a range of nonlinear function classes, including ReLU networks and trigonometric functions.

Strengths

A first strength is that the paper is not only well written but also excellently presented, which helps in understanding its mathematical content and putting it into a better light. The clarity of exposition is therefore a first great point. In terms of originality, it starts off with the fairly known/commonplace insight that there exists a connection between self-attention and Nadaraya-Watson kernel regression, thus establishing that learning the bandwidth of that estimator across multiple tasks is a necessity for ICL. In this sense and if it stopped there, the contribution wouldn't be particularly novel, as this is intuitive (if thinking of self-attention as learning a summary of the autocovariance function of data and therefore of its characteristic length) and fairly well understood in the literature already (see the cited works of Tosatto et al). One can argue - as in the paper - that Tosatto et al only give an upper bound on the bias, and this work provides a lower bound as well. However where the paper takes off in my opinion is when these arguments move away from purely the 'frequency cutoff / Lipschitzness' length-related realm, to then move into the *directional*, via using concentration arguments on the hypersphere. This is Theorem 4.4 which formalizes the intuition that ICL in transformers identifies low-dimensional subspaces shared by training tasks, an argument more typically found in the analysis of (non-contrastive) self supervised learning. The mathematical method of proof is elegant as well. The authors derive novel concentration inequalities for functionals of points uniformly distributed on high-dimensional spheres, and use a careful symmetry argument to show that any non-zero component in the orthogonal subspace increases the loss. Overall this represents a standout technical contribution well worthy of publication in my view.

Weaknesses

- A small weakness in presentation is I believe that Theorem 4.4 should be emphasized, as to my knowledge this is the more novel part of the contribution. - Similarly, the theoretical guarantees are provided for relatively simple function classes (affine and ReLU-based), which may not represent the full range of tasks where ICL is effective. - The limited scope of experiments is understandable given theoretical assumptions (single-layer) but also important enough that it becomes a weakness, IMHO. - Finally, the paper could benefit from a more extensive comparison to other theoretical frameworks for understanding ICL.

Questions

Would there be (not extremely involved) ways of moving towards more realistic settings ? i.e. moving to infinite width settings ? Would classification tasks with a cross-entropy loss be somewhat tractable if making the right Gaussian (concentration) assumptions ?

Rating

7

Confidence

5

Soundness

4

Presentation

4

Contribution

3

Limitations

There are some obvious, if hard to tackle, limitations in this work: a. Simplicity of setting: The analysis focuses on single-layer models and synthetic tasks, which may limit its immediate applicability to more complex real-world scenarios. b. Gap to large language models: While insightful, the work doesn't fully explain emergent ICL in large language models trained on natural data.

Reviewer 3LPG6/10 · confidence 3/52024-07-17

Summary

The paper studies in-context learning (ICL) of one-layer attention-only transformers in a regression task. The paper argues that the product of query and key projection matrix is associated with the Liptchitzness of input data. The notion of attention windows is introduced based on this. The paper shows that attention windows will adapt to the Lipchitness and the noise level of data and perform dimensional reduction. Experiments are conducted to support theoretical claims.

Strengths

The paper provides a rigorous approach to the problem both with proof and empirical simulations.

Weaknesses

- Although explaining ICL is important, the setting seems to be less realistic (see question 1). - The approach of understanding ICL through the lens of function Lipschitzness is somewhat limiting. For example, Figure 5 demonstrates a decline in generalization error, which is primarily attributed to the function's structure. While the Lipschitz property of a function is indeed a valuable aspect in studying ICL, it doesn't provide a comprehensive explanation or solution for ICL as a whole.

Questions

- The assumption in Equation 4 can be understood as the optimal weights of values $W_V$ will ignore covariates $x$ while the attention will only consider covariates to decide where to attend in the sequence while disregarding predictor $f$. I wonder if this makes sense for hidden states of LLMs. In particular, there is no separation between covariates and predictors in LLMS. Also, why is the optimal $W_V$ in the proof of Lemma B.1 assumed to have first columns to be zeros (in between Line 577-578)? - I agree that $x^\top M y$ can be understood as the distance between $x$ and $y$. It might not straightforward to change $x^\top M y$ into $||x - y||$ like used in Appendix. Can you clarify this more on how to obtain Equation (8) in Appendix from Equation (ICL) in the main text.

Rating

6

Confidence

3

Soundness

2

Presentation

3

Contribution

2

Limitations

Please see above.

Reviewer BJxR2024-08-08

Thanks. Update score from 6 to 7

I have checked all the rebuttals. They address all my concerns well, and I have updated my score from 6 to 7.

Reviewer 3LPG2024-08-13

Thank you for clarification. I have raised the score accordingly.

Program Chairsdecision2024-09-25

Decision

Accept (spotlight)

© 2026 NYSGPT2525 LLC