Lune

ICLR2025Top-tier venue

Transformers are Universal In-context Learners

Takashi Furuya, Maarten V. de Hoop, Gabriel Peyré

Abstract

Transformers are deep architectures that define "in-context mappings" which enable predicting new tokens based on a given set of tokens (such as a prompt in NLP applications or a set of patches for a vision transformer). In this work, we study in particular the ability of these architectures to handle an arbitrarily large number of context tokens. To mathematically, uniformly address their expressivity, we consider the case that the mappings are conditioned on a context represented by a probability distribution of tokens which becomes discrete for a finite number of these. The relevant notion of smoothness then corresponds to continuity in terms of the Wasserstein distance between these contexts. We demonstrate that deep transformers are universal and can approximate continuous in-context mappings to arbitrary precision, uniformly over compact token domains. A key aspect of our results, compared to existing findings, is that for a fixed precision, a single transformer can operate on an arbitrary (even infinite) number of tokens. Additionally, it operates with a fixed embedding dimension of tokens (this dimension does not increase with precision) and a fixed number of heads (proportional to the dimension). The use of MLPs between multi-head attention layers is also explicitly controlled. We consider both unmasked attentions (as used for the vision transformer) and masked causal attentions (as used for NLP and time series applications). We tackle the causal setting leveraging a space-time lifting to analyze causal attention as a mapping over probability distributions of tokens.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

19 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Approximation Theory for Lipschitz Continuous Transformers cites Are Transformers universal approximators of sequence-to-sequence functions?
  • Transformers learn to implement preconditioned gradient descent for in-context learning cites Language Models are Few-Shot Learners
  • The emergence of clusters in self-attention dynamics cites Are Transformers universal approximators of sequence-to-sequence functions?
  • An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale cites Language Models are Few-Shot Learners
  • Clustering in Deep Stochastic Transformers cites The emergence of clusters in self-attention dynamics
  • Clustering in Deep Stochastic Transformers cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Universal Approximation with Softmax Attention cites Language Models are Few-Shot Learners
  • Universal Approximation with Softmax Attention cites Are Transformers universal approximators of sequence-to-sequence functions?
  • In-Context Algorithm Emulation in Fixed-Weight Transformers cites Transformers learn to implement preconditioned gradient descent for in-context learning
  • In-Context Algorithm Emulation in Fixed-Weight Transformers cites Universal Approximation with Softmax Attention
  • In-Context Algorithm Emulation in Fixed-Weight Transformers cites Language Models are Few-Shot Learners
  • In-Context Algorithm Emulation in Fixed-Weight Transformers cites Are Transformers universal approximators of sequence-to-sequence functions?
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers19

  1. Universal Approximation with Softmax AttentionJerry Yao-Chieh Hu, Hude Liu, Hong-Yu Chen, Weimin Wu et al.ICML 2026 · 9 citations
  2. Autoregressive Language Models are Secretly Energy-Based Models: Insights into the Lookahead Capabilities of Next-Token PredictionMathieu Blondel, Michael Sander, Germain Vivier-Ardisson, Tianlin Liu et al.ICML 2026 · 8 citations
  3. Clustering in Deep Stochastic TransformersLev Fedorov, Michael Sander, Romuald Elie, Pierre Marion et al.ICML 2026 · 7 citations
  4. In-Context Algorithm Emulation in Fixed-Weight TransformersJerry Yao-Chieh Hu, Hude Liu, Jennifer Yuntong Zhang, Han LiuICLR 2026 · 7 citations
  5. Approximation Theory for Lipschitz Continuous TransformersTakashi Furuya, Davide Murari, Carola-Bibiane SchönliebICML 2026 · 4 citations

Builds on11

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn et al.ICLR 2021 · 21,477 citations
  3. Are Transformers universal approximators of sequence-to-sequence functions?Chulhee Yun, Srinadh Bhojanapalli, Ankit Singh Rawat, Sashank J. Reddi et al.ICLR 2020 · 481 citations
  4. Transformers learn to implement preconditioned gradient descent for in-context learningKwangjun Ahn, Xiang Cheng, Hadi Daneshmand, Suvrit SraNeurIPS 2023 · 324 citations
  5. The emergence of clusters in self-attention dynamicsBorjan Geshkovski, Cyril Letrouit, Yury Polyanskiy, Philippe RigolletNeurIPS 2023 · 163 citations

Related papers

  1. Prompting a Pretrained Transformer Can Be a Universal ApproximatorAleksandar Petrov, Philip Torr, Adel BibiICML 2024 · 19 citations
  2. Universality and Limitations of Prompt TuningYihan Wang, Jatin Chauhan, Wei Wang, Cho-Jui HsiehNeurIPS 2023 · 48 citations
  3. Towards Understanding the Universality of Transformers for Next-Token PredictionMichael Eli Sander, Gabriel PeyréICLR 2025
  4. Timer-XL: Long-Context Transformers for Unified Time Series ForecastingYong Liu, Guo Qin, Xiangdong Huang, Jianmin Wang et al.ICLR 2025
  5. Are Transformers with One Layer Self-Attention Using Low-Rank Weight Matrices Universal Approximators?Tokio Kajitsuka, Issei SatoICLR 2024 · 31 citations
Dusk over the sea between two cliffs drawn in fine vertical lines