Transformers Meet In-Context Learning: A Universal Approximation Theory

Gen Li, Yuchen Jiao, Yu Huang, Yuting Wei, Yuxin Chen
6/5/2025
cs.LGmath.STstat.ML

No confident code implementation found for this paper.

Abstract

Large language models are capable of in-context learning, the ability to perform new tasks at test time using a handful of input-output examples, without parameter updates. We develop a universal approximation theory to elucidate how transformers enable in-context learning. For a general class of functions (each representing a distinct task), we demonstrate how to construct a transformer that, without any further weight updates, can predict based on a few noisy in-context examples with vanishingly small risk. Unlike prior work that frames transformers as approximators of optimization algorithms (e.g., gradient descent) for statistical learning tasks, we integrate Barron's universal function approximation theory with the algorithm approximator viewpoint. Our approach yields approximation guarantees that are not constrained by the effectiveness of the optimization algorithms being mimicked, extending far beyond convex problems like linear regression. The key is to show that (i) any target function can be nearly linearly represented, with small $\ell_1$-norm, over a set of universal features, and (ii) a transformer can be constructed to find the linear representation -- akin to solving Lasso -- at test time.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{li2025transformers,
  title  = {Transformers Meet In-Context Learning: A Universal Approximation Theory},
  author = {Gen Li and Yuchen Jiao and Yu Huang and Yuting Wei and Yuxin Chen},
  year   = {2025},
  eprint = {2506.05200},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2506.05200v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2506.05200.svg)](https://codeofpaper.com/paper/2506.05200)

Discussion