A Survey on In-context Learning

Qingxiu Dong, Lei Li 0039, Damai Dai, Ce Zheng, Jingyuan Ma, Rui Li, Heming Xia, Jingjing Xu, Zhiyong Wu, Baobao Chang, Xu Sun, Lei Li 0005, Zhifang Sui

Introduction

In-context learning (ICL) has emerged as a paradigm shift in how we interact with Large Language Models (LLMs). Unlike traditional supervised learning, which requires extensive parameter updates for each new task, ICL enables models to perform tasks by simply observing a few demonstrations within a prompt. This "training-free" adaptation allows for rapid task switching and deployment without the computational overhead of fine-tuning.

The basic mechanism of In-Context Learning, where a model predicts a label based on provided examples.

The Problem: Sensitivity and Complexity

While powerful, ICL is notoriously sensitive to prompt design. Minor changes in example ordering, template wording, or label distribution can lead to significant performance fluctuations—sometimes swinging from state-of-the-art accuracy to random chance. This survey addresses the need for a unified framework to categorize the techniques used to stabilize and optimize ICL, as well as the theoretical underpinnings of why this behavior emerges in Transformer architectures.

A Taxonomy of In-Context Learning

The authors organize the ICL landscape into three primary pillars: Training, Inference, and Analysis. This structured approach helps researchers navigate the vast array of recent developments in the field.

A comprehensive taxonomy of In-Context Learning, covering training strategies, inference-time prompt design, and theoretical analysis.

1. Model Training

Although ICL is used at inference without weight updates, models can be specifically prepared to be better in-context learners during their development phase:

  • Pre-training: Reorganizing training data to encourage cross-document reasoning and long-range dependencies.
  • Warmup (Instruction Tuning): Fine-tuning on a diverse range of tasks (e.g., FLAN or MetaICL) to bridge the gap between raw text prediction and the structured, task-oriented format of ICL.

2. Prompt Engineering and Inference

The "surface" of ICL involves how demonstrations are presented to the model. Key research areas include:

  • Demonstration Selection: Using unsupervised methods like $k$-Nearest Neighbors (kNN) or diversity-based methods like votek to find examples most relevant to the query.
  • Demonstration Ordering: Arranging examples to avoid "recency bias" or using entropy-based metrics to find the optimal sequence.
  • Scoring Functions: Deciding how to map the model's raw probability output to a final answer, such as comparing Direct scoring against Perplexity-based (Channel) models.

3. Theoretical Analysis

Understanding the learning mechanism is a key research frontier. Two prominent views include:

  • The Bayesian View: The model treats demonstrations as evidence to identify a latent concept or task from its pre-training distribution.
  • The Gradient Descent View: A provocative finding in recent literature suggests that the Transformer's forward pass implicitly performs mathematical operations equivalent to gradient updates, effectively acting as a meta-optimizer.

Key Insights

  • Analogy Mechanism: At its core, ICL is learning by analogy. The model doesn't just see text; it recognizes a pattern of [Input] -> [Label] and extrapolates that pattern to the new query.
  • Emergent Ability: ICL performance often scales non-linearly with model size, appearing as an "emergent" property only after models reach a certain threshold of parameters or training tokens.
  • Label Mapping: While early studies suggested LLMs only care about label distributions, newer research shows that ground-truth correctness in demonstrations is vital for complex reasoning and smaller models.

Benchmarks and Performance

The survey reviews performance across diverse benchmarks, from traditional NLP tasks (SST-2, SNLI) to complex reasoning (BIG-bench, GSM8K). A critical finding is that the "best" prompt strategy is often model-dependent; for instance, similarity-based selection (topk) remains highly effective for modern models like Llama3 and Qwen2, outperforming more complex selection algorithms.

Future Directions

Future research must address the quadratic computational cost of long prompts as the number of demonstrations ($k$) increases. Additionally, with the advent of models supporting millions of tokens, "Many-shot ICL" presents new challenges in retrieval and context management. Bridging the gap between current theoretical models and the empirical behavior of massive LLMs remains a primary goal for the field.

Summary updated

BibTeX
@inproceedings{dong2024survey,
  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 Baobao Chang and Xu Sun and Lei Li and Zhifang Sui},
  title = {{A Survey on In-context Learning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.64},
}
Figure