Learning Linear Regression with Low-Rank Tasks in-Context

Kaito Takanami, Takashi Takahashi, Yoshiyuki Kabashima

TL;DR

This paper provides a precise mathematical characterization of how transformers perform in-context learning (ICL) when tasks share a common, low-rank structure. By analyzing a linear attention model in the high-dimensional limit, the authors reveal that ICL acts as a context-dependent noise-reduction mechanism, stabilized by an implicit regularization born from finite training data fluctuations, and exhibits a sharp capability phase transition governed by task structure.

What Problem Does This Paper Address?

In-Context Learning (ICL)—the ability of large language models to learn new tasks purely from a few examples in a prompt without updating their weights—is incredibly powerful, but its theoretical mechanics are still poorly understood.

Most existing theoretical studies analyze ICL under the assumption that tasks are completely independent. However, in the real world, tasks are rarely independent; they usually share an underlying structure (e.g., different languages sharing grammatical rules, or different medical imaging tasks sharing visual features). This paper addresses this gap by investigating how transformers learn to exploit a shared low-rank structure across linear regression tasks, and how this structure impacts generalization performance.

Methods

The authors analyze a single-layer linear attention transformer trained on linear regression tasks that share a low-dimensional latent subspace. To make the complex behavior of the transformer mathematically tractable, they analyze the model in the high-dimensional asymptotic limit (where the number of features, tasks, and examples all scale to infinity at fixed ratios).

They employ the replica method—a technique borrowed from statistical physics—to derive exact analytical expressions for the model's predictions and generalization errors. To ensure their findings aren't just artifacts of linear simplifications, they also conduct numerical experiments using both linear attention and non-linear softmax self-attention architectures.

Datasets

Because this is a theoretical study aimed at proving fundamental mathematical principles, the authors use synthetically generated datasets rather than standard empirical benchmarks:

  • Task Generation: Task vectors are generated by mapping low-dimensional latent vectors through a shared, r-dimensional orthonormal feature matrix into a higher D-dimensional space.
  • Evaluation Protocols: The model is evaluated across three distinct task distributions:
  • Task Memorization (TM): Tasks randomly sampled from the pre-training pool.
  • In-Distribution Generalization (IDG): Unseen tasks that still share the same low-rank structure.
  • Out-of-Distribution Generalization (ODG): Isotropic Gaussian tasks that completely lack the low-rank structure.

Key Insights and Ideas

  • ICL as Noise Reduction: The transformer's prediction can be broken down into a deterministic algorithmic signal (a two-step process that estimates the task and projects it onto the learned low-rank subspace) and two suppressible noise terms (memorization noise and structural noise). ICL works by using the prompt context to actively suppress these noises.
  • The Paradox of Perfect Data: Counter-intuitively, training a model on "perfect," noise-free data with infinite context length actually makes the learning problem ill-posed and unstable, leading to poor generalization.
  • Data Fluctuations as a Regularizer: The statistical imperfections and fluctuations inherent to finite pre-training datasets act as an implicit regularizer. This natural noise breaks the flat directions in the optimization landscape, stabilizing the model's ability to execute low-rank tasks.
  • Structural Phase Transitions: The model's capabilities undergo a sharp phase transition determined by the balance between task difficulty (subspace dimensionality) and task diversity.

Key Results

  • Error Decomposition: The authors mapped out how longer context lengths consistently reduce algorithmic and structural errors, but can paradoxically increase memorization noise due to task-overfitting in in-distribution settings.
Decomposition of generalization error across TM, IDG, and ODG protocols.
  • Finite Data Stability: Theoretical and numerical results confirm that models trained with finite sample ratios ($\alpha$) achieve stable, robust generalization, whereas models trained in the idealized infinite-data limit fail to generalize when the task subspace is low-rank ($\rho < 1$).
Comparison of generalization error between finite sample ratios and the idealized infinite-data limit.
  • Sharp Phase Transition: The paper proves that a sharp phase transition occurs at a critical point where task difficulty matches task diversity ($\rho = \kappa$). In the task-rich regime ($\rho < \kappa$), the model perfectly captures the in-distribution structure (lowering TM and IDG errors) but becomes highly specialized, causing out-of-distribution (ODG) error to climb.
Figure 3: Phase transition in the model’s capa- bilities. Generalization errors (ETM, EIDG, EODG) as a function of the task difficulty ρ. The results con- firm the predicted phase transition in generalization errors at ρ = κ. The error bars represent the standard errors of the mean over 5 trials per point. Parame- ters: α = 200 (solid lines), α →∞(dashed lines), ˜α = 4.0, γ = 8.0, κ = 0.5, σ = 0, D = 40.
  • Softmax Validation: Qualitative experiments show that non-linear softmax attention models replicate the same structural dependencies and performance plateaus predicted by the linear attention theory.
Generalization errors of a one-layer softmax self-attention model.

Limitations and Future Work

While foundational, this work relies on a single-layer linear attention mechanism to achieve exact mathematical proofs, which simplifies the multi-layer, non-linear reality of modern LLMs. Additionally, the analysis is restricted to linear regression tasks.

The authors note that extending this high-dimensional asymptotic framework to multi-layer architectures and more complex, non-linear task structures (such as classification or hierarchical language tasks) represents a promising and necessary direction for future research.

Summary updated

BibTeX
@inproceedings{takanami2026learning,
  author = {Kaito Takanami and Takashi Takahashi and Yoshiyuki Kabashima},
  title = {{Learning Linear Regression with Low-Rank Tasks in-Context}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2026},
  url = {https://openreview.net/forum?id=bkhqasdf2u},
}
Figure