# A Survey on In-context Learning

Survey maps how in-context learning works and where it still falls short

Qingxiu Dong, Lei Li, Damai Dai, Ce Zheng, Jingyuan Ma, Rui Li and 8 more · arXiv · 2022-12-31

- **Problem** In-context learning shifts with the prompt template, the chosen demonstrations and their order. The mechanism behind these swings is unclear, so results are hard to predict.
- **Method** The authors survey in-context learning by training, prompt design and analysis.
- **Results** The top demonstration selector depends on the model. On GPT2, mdl averages 54.4 against 49.5 for topk, but on Llama3 topk leads with 71.5 against 70.9.

## Why ICL needs a shared map

In-context learning lets a language model handle a new task from a few examples placed in its prompt. The weights stay fixed, so the adaptation cost is a prompt rather than a training run. That convenience has a catch, because the prediction can swing with the template, the chosen demonstrations and their order. The mechanism behind those swings is also unclear, which makes them hard to predict.

The authors respond with one map of the field that covers training, prompt design and analysis.

The formal setup starts from a query x and a set of candidate answers Y. A demonstration set C holds an optional instruction I and k demonstrations, each written in natural language. Each candidate y\_j gets the score \\( P(y\_j \\mid x) \\) defined as \\( f\_M(y\_j, C, x) \\), and the prediction is the candidate with the highest score. ICL sits inside prompt tuning, since its demonstrations form part of the prompt.

Few-shot learning differs because it updates parameters, while ICL doesn't.

## Training before inference

Some gains come from training before inference, and the authors split this into pretraining and warmup. Pretraining reorganizes corpora by grouping related contexts, so the model learns to reason across earlier examples. Warmup is a later, optional stage that changes parameters before inference. Symbol tuning, one warmup method, swaps labels such as positive and negative for arbitrary symbols, so the model must learn the mapping from context.

Instruction tuning is another warmup route, and FLAN tuned a 137B LaMDA-PT model on over 60 datasets written as instructions. That tuning raised both zero-shot and few-shot ICL performance. Because every warmup method updates parameters, the authors read this as room for the original model to improve, and they recommend warmup even though ICL doesn't strictly need it.

## How demonstrations are picked and scored

Unsupervised selectors score candidate demonstrations with a fixed rule, and supervised selectors learn that rule from data. The simplest rule is nearest neighbors: KATE retrieves similar examples using a distance such as L2 or cosine similarity on sentence embeddings. Other unsupervised rules need no labelled data, such as mutual information, perplexity, or the LLM's own output scores.

mdl picks the best subset permutation of kNN examples by the code length needed to transmit the label given the input and the demonstrations.

Fixed rules are heuristic, so supervised methods learn the selection instead. EPR recalls similar candidates with an unsupervised method such as BM25, then trains a dense retriever on them. Zhang et al. (2022a) treat selection as a Markov decision process and use Q-learning, with validation accuracy as the reward.

Once demonstrations are chosen, a scoring function turns model outputs into answer likelihoods. The Direct method uses the conditional probability of answer tokens, but it requires those tokens to sit at the end of the input, which limits template design. PPL scores the whole sequence, including demonstrations, query and label, which removes the position limit but adds computation.

Channel reverses the direction and estimates the query given the label, which the authors expect to help under imbalanced training data.

## Which selector wins across models

The authors compared topk, votek and mdl on SST5, SST2, CommonsenseQA, SNLI and AG News. Each input got 8 demonstrations, and inference used the PPL-based approach. For SNLI and AG News, retrieval drew on 1000 training items and testing used the first 1000 test items. The four models were GPT2, GPT-J, Qwen2 and Llama3.

The winning selector changes with the model, and that is the core result here. On GPT2, mdl reaches an average of 54.4, compared to 49.5 for topk. On GPT-J, topk averages 63.9, compared to 63.5 for mdl. On Llama3, topk reaches 71.5, compared to 70.9 for mdl. So the authors read selector effectiveness as model-dependent, with mdl leading only on GPT2.

This check covers three selectors and one inference route, so it can't rank the other methods in the survey.

## Latency and stability of the scoring functions

PPL and Channel cost more time than Direct, because they score more of the input. Averaged over four models with 8 in-context examples, the latency ratio relative to Direct is 2.61 for PPL and 2.90 for Channel.

Stability asks whether scores move when the demonstrations change. The authors used a test set of size 10k, five random seeds, and 8 examples drawn from 5k training examples each time. Averaged over the four models, variance is 0.93 for Direct, 0.78 for PPL and 3.03 for Channel. Lower variance means steadier scores, so Channel is the least stable of the three here.

The takeaway favors Channel for imbalanced data, but these runs don't measure imbalance. The efficiency and stability runs are separate measurements, so their settings should be read separately.

## What the analyses say about the mechanism

Attention is the module that most studies of the ICL mechanism focus on. Olsson et al. (2022) identified induction heads, which copy earlier patterns to predict the next token, and the authors link them to ICL ability. Wang et al. (2023b) found that demonstration label words act as anchors that gather and spread information for the final prediction.

The Bayesian view treats ICL as identifying a shared latent concept among the examples. The gradient descent view finds that Transformer attention has a dual form with gradient descent, so GPT-based ICL resembles explicit fine-tuning. These links come from simplified regression settings, and their fit to real contexts is still debated.

On the factor side, Liu et al. (2022) found that demonstrations whose embeddings sit closer to the query usually perform better. Most analytical work, though, stays with simple tasks and small models.

## Limits of the survey and open problems

The survey admits it may have missed equally valuable contributions in demonstration design and analysis. Many covered papers used models that were not the newest, and the authors call for up-to-date work.

Efficiency and scalability remain open, since more demonstrations raise cost and use up the input length. Compressing demonstrations into vectors trades away performance or needs model parameters, which closed models like ChatGPT and Claude don't expose. Long-context ICL is also open, since more demonstrations don't always help and can even hurt.

LongICLBench reveals further weaknesses in how LLMs read extended demonstrations.

## Paper info

- **Authors**: Qingxiu Dong, Lei Li, Damai Dai, Ce Zheng, Jingyuan Ma, Rui Li, Heming Xia, Jingjing Xu, Zhiyong Wu, Tianyu Liu, Baobao Chang, Xu Sun, Lei Li, Zhifang Sui
- **Venue**: arXiv · Preprint
- **First published**: 2022-12-31
- **Added**: 2026-11-12
- **Updated**: 2024-10-5
- **Version**: v6
- **arXiv**: 2301.00234
- **Category**: cs.CL · cs.AI
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2301.00234v6) · [PDF ↗](https://arxiv.org/pdf/2301.00234v6)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Qingxiu Dong, Lei Li, Damai Dai, Ce Zheng, Jingyuan Ma, Rui Li, Heming Xia, Jingjing Xu, Zhiyong Wu, Tianyu Liu, Baobao Chang, Xu Sun, Lei Li, Zhifang Sui (2022). A Survey on In-context Learning. arXiv:2301.00234v6. https://arxiv.org/abs/2301.00234v6

**BibTeX**

```
@misc{dong2022survey,
  title = {{A Survey on In-context Learning}},
  author = {Qingxiu Dong and Lei Li and Damai Dai and Ce Zheng and Jingyuan Ma and Rui Li and Heming Xia and Jingjing Xu and Zhiyong Wu and Tianyu Liu and Baobao Chang and Xu Sun and Lei Li and Zhifang Sui},
  year = {2022},
  eprint = {2301.00234},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2301.00234v6}
}
```

## Other paper commentary

- [LaMDA: Language Models for Dialog Applications](https://refivu.com/en/papers/9474e307-9624-4203-a346-57d881b1a5d9-lamda-language-models-for-dialog-applications.md)
- [Cross-lingual Language Model Pretraining](https://refivu.com/en/papers/8d4c53c4-5c75-4330-9085-1b84a43703b6-cross-lingual-language-model-pretraining.md)
- [G-Eval: NLG Evaluation using GPT-4 with Better Human Alignment](https://refivu.com/en/papers/d14a3666-4caf-4371-83b0-d44fc50735f5-g-eval-nlg-evaluation-using-gpt-4-with.md)
- [Self-Refine: Iterative Refinement with Self-Feedback](https://refivu.com/en/papers/f8f8d11b-268b-4988-84b8-c616a701e2ba-self-refine-iterative-refinement-with-self-feedback.md)
- [Qwen2.5-Coder Technical Report](https://refivu.com/en/papers/8282ea88-f013-4a5f-832a-687a740c2ff3-qwen2-5-coder-technical-report.md)
- [Language Models (Mostly) Know What They Know](https://refivu.com/en/papers/ffe245df-5662-4bfb-8c0b-899a38b87412-language-models-mostly-know-what-they-know.md)
- [Probabilistic Latent Semantic Analysis](https://refivu.com/en/papers/2bb41f8f-b6cc-410c-9347-fd84aed3b2b4-probabilistic-latent-semantic-analysis.md)
- [Deep Learning for Sentiment Analysis : A Survey](https://refivu.com/en/papers/423bc94d-8ef5-42e2-a68f-87cb54c7636d-deep-learning-for-sentiment-analysis-a-survey.md)
- [Understanding Convolution for Semantic Segmentation](https://refivu.com/en/papers/c32b12c2-d4e5-4e10-b7c6-b643713776fc-understanding-convolution-for-semantic-segmentation.md)
- [InternVL3: Exploring Advanced Training and Test-Time Recipes for Open-Source Multimodal Models](https://refivu.com/en/papers/93e60b18-9322-49b4-85e3-af682c647d05-internvl3-exploring-advanced-training-and-test-time-recipes.md)
- [Applications of Deep Reinforcement Learning in Communications and Networking: A Survey](https://refivu.com/en/papers/0b4d9b08-577a-4c81-8c2b-a8a7244761e2-applications-of-deep-reinforcement-learning-in.md)
- [MOT16: A Benchmark for Multi-Object Tracking](https://refivu.com/en/papers/b140c8bc-846b-4f50-973f-76ab17fb435b-mot16-a-benchmark-for-multi-object-tracking.md)

## Terms in this paper

- [gradient descent](https://refivu.com/en/terms/7557852c745c-gradient-descent)
- [in-context learning](https://refivu.com/en/terms/d53d2af6b551-in-context-learning)
- [inference latency](https://refivu.com/en/terms/b79348d77559-inference-latency)
- [Big-bench Hard](https://refivu.com/en/terms/b9192cc54214-big-bench-hard)
- [direct method](https://refivu.com/en/terms/29b9a3750e9d-direct-method)
- [FLAN](https://refivu.com/en/terms/fbea0a362ee3-flan)
- [induction heads](https://refivu.com/en/terms/9e3f59843a35-induction-heads)
- [Symbol Tuning](https://refivu.com/en/terms/a9fb819bceeb-symbol-tuning)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/e3dcb216-0b54-4a23-8e0d-f077c493f505-a-survey-on-in-context-learning)
