Transformers Learn Closed-Form Linear Regression In-Context

Zhengyang Zhuge, Hao Yu, Xin Wang, Zheng Li, Yizhong Cao, Dayiheng Liu, Jianwei Zhang· July 20, 2026 View original

Summary

This paper demonstrates that a transformer with linear self-attention can in-context learn the closed-form (analytical) solution for a simple linear regression task, rather than approximating it via gradient descent. The key insight is that layer normalization enables the approximate acquisition of the least squares estimate, particularly when trained with L1 regularization.

In-context learning is a highly studied property of transformers, where models can learn from examples provided within the input sequence without explicit weight updates. While many studies have shown transformers can act as solvers for regression problems, often implicitly implementing gradient descent, it has been less clear if they can acquire analytical, closed-form solutions. This research specifically investigates this by constructing a transformer equipped with linear self-attention. The study demonstrates that this specialized transformer can in-context learn the least squares estimate for a simple linear regression task. Crucially, the paper highlights that the approximate acquisition of this closed-form solution is facilitated by the use of layer normalization, rather than relying on an iterative gradient descent approximation. Experimental examples further illustrate this, particularly when the transformer is trained with L1 regularization and the target output is the least squares estimate, providing a deeper understanding of the mechanisms behind in-context learning for fundamental statistical tasks.

Why it matters

Understanding how transformers acquire in-context learning capabilities, especially for fundamental tasks like linear regression, can lead to more efficient, robust, and interpretable AI models, potentially reducing the need for extensive fine-tuning.

How to implement this in your domain

  1. 1Review current practices for in-context learning in transformer models and their reliance on gradient descent approximations.
  2. 2Explore the architectural implications of linear self-attention and layer normalization for specific tasks.
  3. 3Experiment with training transformer models using L1 regularization for tasks where closed-form solutions exist.
  4. 4Develop diagnostic tools to analyze how models arrive at solutions during in-context learning, distinguishing between analytical and iterative approaches.
  5. 5Apply these insights to design more efficient and interpretable few-shot learning systems.

Who benefits

AI/ML ResearchSoftware DevelopmentData ScienceEducationFinance

Key takeaways

  • Transformers can learn closed-form solutions for linear regression in-context.
  • Layer normalization is key to acquiring the least squares estimate analytically.
  • This differs from typical gradient descent approximations in in-context learning.
  • L1 regularization can support this analytical learning process.

Original post by Zhengyang Zhuge, Hao Yu, Xin Wang, Zheng Li, Yizhong Cao, Dayiheng Liu, Jianwei Zhang

"arXiv:2607.15810v1 Announce Type: new Abstract: Rollout generation is a major bottleneck in Reinforcement Learning (RL) for Mixture-of-Experts (MoE) Large Language Models, motivating low-precision rollout acceleration such as FP8. As an emerging low-precision format, NVFP4 combin…"

View on X

Originally posted by Zhengyang Zhuge, Hao Yu, Xin Wang, Zheng Li, Yizhong Cao, Dayiheng Liu, Jianwei Zhang on X · view source

Want to go deeper?

Turn these trends into skills with Learnijoy's hands-on AI & tech courses.

Explore courses