cs.LGFeb 19, 2026
SaveIn-Context Learning in Linear vs. Quadratic Attention Models: An Empirical Study on Regression Tasks
Organizations: University of California, Berkeley
Abstract
Recent work has demonstrated that transformers and linear attention models can perform in-context learning (ICL) on simple function classes, such as linear regression. In this paper, we empirically study how these two attention mechanisms differ in their ICL behavior on the canonical linear-regression task of Garg et al. We evaluate learning quality (MSE), convergence, and generalization behavior of each architecture. We also analyze how increasing model depth affects ICL performance. Our results illustrate both the similarities and limitations of linear attention relative to quadratic attention in this setting.
Figures & tables
| Config | Params | Train Loss | Test Loss | Anisotropic Test Loss |
|---|---|---|---|---|
| 1-layer | 13.7 M | 0.7976 ± 0.0543 | 0.8183 ± 0.0688 | 0.8446 ± 0.0656 |
| 3-layer | 15.2 M | 0.0502 ± 0.0063 | 0.0894 ± 0.0097 | 0.0936 ± 0.0112 |
| 6-layer | 17.6 M | 0.0203 ± 0.0016 | 0.0365 ± 0.0041 | 0.0398 ± 0.0059 |
Table 1: Quadratic Attention Transformer performance
Figure 1: Training and Testing loss. Top row shows shallower networks (1 and 3 layers), while the bottom row shows the deeper 6-layer model.
| Config | Params | Train Loss | Test Loss | Anisotropic Test Loss |
|---|---|---|---|---|
| 1-layer | 0.8 M | 0.5946 ± 0.0483 | 0.7430 ± 0.0671 | 0.7867 ± 0.0488 |
| 3-layer | 2.38 M | 0.0366 ± 0.0021 | 0.0959 ± 0.0026 | 0.1080 ± 0.0035 |
| 6-layer | 4.75 M | 0.0102 ± 0.0012 | 0.0302 ± 0.0034 | 0.0328 ± 0.0030 |
Table 2: Linear Attention Transformer performance
Figure 2: Training and Testing loss for the Linear Attention Transformer
Figure 3: Isotropic vs. anisotropic performance across depths.
| Model | Batch Size | Steps to 90% | Samples to 90% |
|---|---|---|---|
| Quadratic 1 Layer | 32 | 7000 | 224,000 |
| Quadratic 3 Layer | 32 | 21,500 | 688,000 |
| Quadratic 6 Layer | 32 | 25,000 | 800,000 |
| Linear 1 Layer | 64 | 4000 | 256,000 |
| Linear 3 Layer | 64 | 4000 | 256,000 |
| Linear 6 Layer | 64 | 7500 | 480,000 |
Table 3: Steps and equivalent samples seen to reach 90% convergence for each architecture and depth.
Explore similar work
Pre-trained transformers are able to learn from examples provided as part of the prompt without any weight updates, a remarkable ability known as in-context learning (ICL). Despite its demonstrated efficacy across various domains, the theoretical understanding of ICL is still developing. Whereas most existing theory has focused on linear models, we study ICL in the nonlinear regression setting. Through the interaction mechanism in attention, we explicitly construct transformer networks to realize nonlinear features, such as polynomial or spline bases, which span a wide class of functions. Based on this construction, we establish a framework to analyze end-to-end in-context nonlinear regression with the constructed features. Our theory provides finite-sample generalization error bounds in terms of context length and training set size. We numerically validate the theory on synthetic regression tasks.
What can linear attention learn from nonlinear teachers in-context?
Linear attention is a tractable model for understanding the mechanisms governing in-context learning in transformers. For linear regression tasks, recent asymptotic analyses have characterised its learning and generalisation behaviour. We extend this theory to nonlinear single-index targets, . Our main result establishes a nonlinearity-noise equivalence: linear attention extracts only the linear Hermite component of , while the remaining nonlinear structure contributes to the generalisation error as effective noise. This reduction allows results from the corresponding linear theory to be transferred to nonlinear tasks. We illustrate its implications for finite pretraining data and for the transition from task memorisation to task generalisation as task diversity increases. These results identify a limitation of the reduced linear-attention model and provide a tractable starting point for studying nonlinear in-context learning.
In-context learning of closed form solution to simple linear regression task using transformer with linear self-attention
In-context learning is a remarkable property of transformers and has recently received a lot of interest. In many studies of in-context learning, it has been shown that transformers are capable of implementing solver for linear and non-linear regression problems, in which the most of them implement gradient descent algorithm. However, it is still unclear whether those implementations have actually been acquired through training. In this paper, we construct a transformer with linear self-attention, which in-context learns the least squares estimate in a simple regression task. The point here is that the closed form (analytical) solution is approximately obtained by using layer normalization rather than an approximate solution based on gradient descent algorithm. Then, we show an experimental example, in which our implementation is mainly used in the transformer trained with l1 regularization when the target output is the least squares estimate.