In-context Learning on Function Classes Unveiled for Transformers
Zhijie Wang, Bo Jiang, Shuai Li
Abstract
Transformer-based neural sequence models exhibit a remarkable ability to perform in-context learning. Given some training examples, a pretrained model can make accurate predictions on an unseen input. This paper studies why transformers can learn different types of function classes in-context. We first show by construction that there exists a family of transformers (with different activation functions) that implement approximate gradient descent on the parameters of neural networks, and we provide an upper bound for the number of heads, hidden dimensions, and layers of the transformer. We also show that a transformer can learn linear functions, the indicator function of a unit ball, and smooth functions in-context by learning neural networks that approximate them. The above instances mainly focus on a transformer pre-trained on single tasks. We also prove that when pre-trained on two tasks: linear regression and classification, a transformer can make accurate predictions on both tasks simultaneously. Our results move beyond linearity in terms of in-context learning instances and provide a comprehensive understanding of why transformers can learn many types of function classes through the bridge of neural networks.
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.
5 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection cites An Explanation of In-context Learning as Implicit Bayesian Inference
- Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection cites Transformers Learn In-Context by Gradient Descent
- Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical Evidence cites Transformers Learn In-Context by Gradient Descent
- Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical Evidence cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Can In-context Learning Really Generalize to Out-of-distribution Tasks? cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
- Can In-context Learning Really Generalize to Out-of-distribution Tasks? cites An Explanation of In-context Learning as Implicit Bayesian Inference
- Can In-context Learning Really Generalize to Out-of-distribution Tasks? cites Transformers Learn In-Context by Gradient Descent
- Can In-context Learning Really Generalize to Out-of-distribution Tasks? cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- An Explanation of In-context Learning as Implicit Bayesian Inference cites Finetuned Language Models are Zero-Shot Learners
- In-Context Deep Learning via Transformer Models cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
- In-Context Deep Learning via Transformer Models cites An Explanation of In-context Learning as Implicit Bayesian Inference
- In-Context Deep Learning via Transformer Models cites Transformers Learn In-Context by Gradient Descent
- In-Context Deep Learning via Transformer Models cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- In-Context Learning Is Provably Bayesian Inference: A Generalization Theory for Meta-Learning cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
- In-Context Learning Is Provably Bayesian Inference: A Generalization Theory for Meta-Learning cites An Explanation of In-context Learning as Implicit Bayesian Inference
- In-Context Learning Is Provably Bayesian Inference: A Generalization Theory for Meta-Learning cites Why In-Context Learning Models are Good Few-Shot Learners?
- In-Context Learning Is Provably Bayesian Inference: A Generalization Theory for Meta-Learning cites Transformers Learn In-Context by Gradient Descent
- In-Context Learning Is Provably Bayesian Inference: A Generalization Theory for Meta-Learning cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Why In-Context Learning Models are Good Few-Shot Learners? cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
- Why In-Context Learning Models are Good Few-Shot Learners? cites Transformers Learn In-Context by Gradient Descent
- Why In-Context Learning Models are Good Few-Shot Learners? cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Transformers Learn In-Context by Gradient Descent cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites An Explanation of In-context Learning as Implicit Bayesian Inference
Cited by top-tier papers5
- Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical EvidenceShaopeng Fu, Liang Ding, Jingfeng Zhang, Di WangNeurIPS 2025 · 15 citations
- In-Context Learning Is Provably Bayesian Inference: A Generalization Theory for Meta-LearningTomoya Wakayama, Taiji SuzukiICML 2026 · 12 citations
- Can In-context Learning Really Generalize to Out-of-distribution Tasks?Qixun Wang, Yifei Wang, Xianghua Ying, Yisen WangICLR 2025
- In-Context Deep Learning via Transformer ModelsWeimin Wu, Maojiang Su, Jerry Yao-Chieh Hu, Zhao Song et al.ICML 2025
- Why In-Context Learning Models are Good Few-Shot Learners?Shiguang Wu, Yaqing Wang, Quanming YaoICLR 2025
Builds on8
- Finetuned Language Models are Zero-Shot LearnersJason Wei, Maarten Bosma, Vincent Y. Zhao, Kelvin Guu et al.ICLR 2022 · 4,966 citations
- An Explanation of In-context Learning as Implicit Bayesian InferenceSang Michael Xie, Aditi Raghunathan, Percy Liang, Tengyu MaICLR 2022 · 1,030 citations
- What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 citations
- Transformers Learn In-Context by Gradient DescentJohannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento et al.ICML 2023 · 729 citations
- Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm SelectionYu Bai, Fan Chen, Huan Wang, Caiming Xiong et al.NeurIPS 2023 · 356 citations
Related papers
- Transformers Implement Functional Gradient Descent to Learn Non-Linear Functions In ContextXiang Cheng, Yuxin Chen, Suvrit SraICML 2024 · 64 citations
- What learning algorithm is in-context learning? Investigations with linear modelsEkin Akyürek, Dale Schuurmans, Jacob Andreas, Tengyu Ma et al.ICLR 2023 · 85 citations
- In-Context Learning through the Bayesian PrismMadhur Panwar, Kabir Ahuja, Navin GoyalICLR 2024 · 79 citations
- Understanding In-Context Learning in Transformers and LLMs by Learning to Learn Discrete FunctionsSatwik Bhattamishra, Arkil Patel, Phil Blunsom, Varun KanadeICLR 2024 · 77 citations
- Pretrained Transformer Efficiently Learns Low-Dimensional Target Functions In-ContextKazusato Oko, Yujin Song, Taiji Suzuki, Denny WuNeurIPS 2024 · 34 citations
