Lune

ICLR2025Top-tier venue

Can In-context Learning Really Generalize to Out-of-distribution Tasks?

Qixun Wang, Yifei Wang, Xianghua Ying, Yisen Wang

Abstract

In this work, we explore the mechanism of in-context learning (ICL) on out-of-distribution (OOD) tasks that were not encountered during training. To achieve this, we conduct synthetic experiments where the objective is to learn OOD mathematical functions through ICL using a GPT-2 model. We reveal that Transformers may struggle to learn OOD task functions through ICL. Specifically, ICL performance resembles implementing a function within the pretraining hypothesis space and optimizing it with gradient descent based on the in-context examples. Additionally, we investigate ICL's well-documented ability to learn unseen abstract labels in context. We demonstrate that such ability only manifests in the scenarios without distributional shifts and, therefore, may not serve as evidence of new-task-learning ability. Furthermore, we assess ICL's performance on OOD tasks when the model is pretrained on multiple tasks. Both empirical and theoretical analyses demonstrate the existence of the low-test-error preference of ICL, where it tends to implement the pretraining function that yields low test error in the testing context. We validate this through numerical experiments. This new theoretical result, combined with our empirical findings, elucidates the mechanism of ICL in addressing OOD tasks.

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.

6 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

  • 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 Language Models are Few-Shot Learners
  • 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
  • An Explanation of In-context Learning as Implicit Bayesian Inference cites Language Models are Few-Shot Learners
  • Generalization vs Specialization under Concept Shift cites Transformers Learn In-Context by Gradient Descent
  • Generalization vs Specialization under Concept Shift cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • How Does the Pretraining Distribution Shape In-Context Learning? A Fundamental Trade-Off cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
  • How Does the Pretraining Distribution Shape In-Context Learning? A Fundamental Trade-Off cites An Explanation of In-context Learning as Implicit Bayesian Inference
  • How Does the Pretraining Distribution Shape In-Context Learning? A Fundamental Trade-Off cites Language Models are Few-Shot Learners
  • How Does the Pretraining Distribution Shape In-Context Learning? A Fundamental Trade-Off cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • Transformers Learn In-Context by Gradient Descent cites Language Models are Few-Shot Learners
  • 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
  • What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites Language Models are Few-Shot Learners
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers6

  1. Generalization vs Specialization under Concept ShiftAlex Nguyen, David J. Schwab, Vudtiwat NgampruetikornNeurIPS 2025 · 3 citations
  2. SAE as a Crystal Ball: Interpretable Features Predict Cross-domain Transferability of LLMs without TrainingQi Zhang, Yifei Wang, Xiaohan Wang, Jiajun Chai et al.ICLR 2026 · 1 citation
  3. Toward Robust In-Context Learning: Leveraging Out-of-distribution Proxies for Target Inaccessible Demonstration RetrievalHao Xu, Rite Bo, Fausto Giunchiglia, Yingji Li et al.ACL 2026
  4. Counterfactual-based Cognitive Alignment In-Context Learning for Relation ExtractionQibin Li, Shengyuan Bai, Nai Zhou, Nianmin YaoAAAI 2026
  5. How Does the Pretraining Distribution Shape In-Context Learning? A Fundamental Trade-OffWaïss Azizian, Ali HasanICML 2026

Builds on18

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. An Explanation of In-context Learning as Implicit Bayesian InferenceSang Michael Xie, Aditi Raghunathan, Percy Liang, Tengyu MaICLR 2022 · 1,030 citations
  3. What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 citations
  4. Transformers Learn In-Context by Gradient DescentJohannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento et al.ICML 2023 · 729 citations
  5. 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

  1. When can in-context learning generalize out of task distribution?Page C. Goddard, Lindsay M. Smith, Vudtiwat Ngampruetikorn, David J. SchwabICML 2025
  2. Pretrain–Test Task Alignment Governs Generalization in In-Context LearningMary Letey, Jacob A Zavatone-Veth, Yue M. Lu, Cengiz PehlevanICLR 2026 · 6 citations
  3. Dual Operating Modes of In-Context LearningZiqian Lin, Kangwook LeeICML 2024 · 50 citations
  4. In-Context Learning through the Bayesian PrismMadhur Panwar, Kabir Ahuja, Navin GoyalICLR 2024 · 79 citations
  5. How Do Transformers Learn In-Context Beyond Simple Functions? A Case Study on Learning with RepresentationsTianyu Guo, Wei Hu, Song Mei, Huan Wang et al.ICLR 2024 · 80 citations
Dusk over the sea between two cliffs drawn in fine vertical lines