Research map / Label-efficient and robust learning / OOD and anomaly detection
Can In-context Learning Really Generalize to Out-of-distribution Tasks?
Read the paperCheck your idea against 108,967 papers
AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.
Shows via synthetic GPT-2 experiments and theory that ICL on OOD function classes tends to implement pretraining function classes (with gradient descent-like behavior), only solves abstract-label classification in-distribution, and selects pretraining priors by low test error and input-distribution similarity.
Problem
Whether in-context learning can truly generalize to out-of-distribution tasks unseen during pretraining, and what mechanism governs ICL's behavior on OOD tasks.
Approach
ICL on OOD functions behaves like the pretraining function class optimized by gradient descent on the context; when pretrained on multiple tasks, ICL selects the pretraining function with lower test error on the context and the input distribution closest to the downstream one, backed by a theorem on a mixed-Gaussian pretraining model.
Key results
- On a new function class, GPT-2 ICL error approaches that of a same-class model trained by GD as context length grows.
- Llama-3-8B and Llama-2-7B perform near random (about 10%) on the synthetic OOD word classification task, while retrieval accuracy is significantly higher.
- A GPT-2 trained on mixed LR+QR+ReLU NN tasks performs comparably to the best single-task model on each OOD evaluation function.
Measured effects reported in the paper
| What was changed | Where | Measured | Effect |
|---|---|---|---|
| Use ICL on a function class not seen during pretraining | GPT-2 pretrained on linear, quadratic, or ReLU regression · Unseen mathematical function classes | test error | Mixed |
| Train on retrieval tasks with more diverse random label mappings (ablation) | Transformer retrieval model · Retrieval with OOD labels | test error | Helped |
| Train on the largest tested range of label mappings, s~U(100, 2000) (ablation) | Transformer on linear regression + retrieval · Unseen abstract labels | test error | Helped |
| Increase the number of in-distribution linear-regression training vectors (ablation) | GPT-2 pretrained on linear regression · Quadratic and ReLU NN regression | test error | No clear effect |
| Evaluate on an OOD quadratic-regression function instead of an ID linear-regression function (ablation) | Transformer pretrained on linear regression + retrieval · Quadratic regression + retrieval with OOD labels | test error | Hurt |
| Use synthetic OOD word classification rather than retrieval | Llama-3-8B · Synthetic word classification and retrieval | accuracy | Hurt |
| Pretrain GPT-2 on the same synthetic word-classification task | GPT-2 · Synthetic word classification | test error | Helped |
| Pretrain on a mixture of linear, quadratic, and ReLU regression tasks instead of one task (ablation) | GPT-2 · Square root, cubic, linear+quadratic, and 2-layer Sigmoid regression | test error | Helped |
| Use a pretraining function class with lower error on the downstream context | ICL algorithm selection · OOD tasks | test error | Helped |
| Use a pretraining input distribution closer to the downstream input distribution | ICL algorithm selection · OOD tasks | pretraining-task weight | Helped |
| Increase context length when classifying ambiguous sentences | Real-world LLMs · Ambiguous sentence classification | top-5 accuracy | Helped |
| Predict the reversed query word rather than the reversed target label | Llama-3-8B · Antonym, country-capital, English-French, and English-German | top-1 accuracy | Helped |
Surprising findings
- Abstract-label classification with ICL succeeds only when the underlying function is in-distribution; with quadratic regression test functions, ICL fails even when the target label appears in context.
- Training on up to about 1,000,000 in-distribution linear regression vectors does not enable generalization to OOD function classes.
Limitations
- Theory relies on a mixed Gaussian pretraining model and linear regression assumptions.
- Real-world LLM experiments are limited to synthetic word classification and a few tasks with Llama models.
Experimental setup
Datasets: synthetic Gaussian function-regression data SST-2-style abstract-label tasks Llama-3-8B word embeddings for synthetic word classification antonym, country-capital, English-French, English-German translation pairs
Benchmarks: synthetic OOD function regression (square root, cubic, linear+quadratic, 2-layer sigmoid) synthetic word classification with Llama embeddings ambiguous sentence classification (sentiment/type/location)
Metrics: test square error top-1 accuracy top-5 accuracy prefix matching score
Baselines: gradient descent-trained models of the pretraining function class single-task pretrained GPT-2 models Llama-2-7B Llama-3-8B
Builds on: Transformers learn in-context by gradient descent Bayesian ICL theory for mixed Gaussian pretraining what one-layer linear self-attention learns in context
Closest papers by meaning
- When can in-context learning generalize out of task distribution? (ICML 2025 · similarity 0.93)
- Technical Debt in In-Context Learning: Diminishing Efficiency in Long Context (NeurIPS 2025 · similarity 0.92)
- In-Context Learning through the Bayesian Prism (ICLR 2024 · similarity 0.91)
- Position: Do pretrained Transformers Learn In-Context by Gradient Descent? (ICML 2024 · similarity 0.91)
- Dual Operating Modes of In-Context Learning (ICML 2024 · similarity 0.91)
- How Do Transformers Learn In-Context Beyond Simple Functions? A Case Study on Learning with Representations (ICLR 2024 · similarity 0.91)
Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.
