Papers
Topics
Authors
Recent
Detailed Answer
Quick Answer
Concise responses based on abstracts
Detailed Answer
Thorough responses based on abstracts and some paper content
Custom Instructions Pro
Preferences or requirements that you'd like Emergent Mind to consider when generating responses
Gemini 2.5 Flash
Gemini 2.5 Flash
152 tokens/sec
GPT-4o
76 tokens/sec
Gemini 2.5 Pro Pro
62 tokens/sec
o3 Pro
39 tokens/sec
GPT-4.1 Pro
77 tokens/sec
DeepSeek R1 via Azure Pro
24 tokens/sec
2000 character limit reached

In-Context Learning (ICL)

Updated 24 June 2025

In-Context Learning (ICL) is a paradigm in which LLMs learn to perform tasks solely by conditioning on a prompt that contains a handful of input-output examples—referred to as demonstrations—without updating model parameters. As detailed in "A Survey on In-context Learning" (Dong et al., 2022 ), ICL defines a significant methodological and conceptual shift in natural language processing and machine learning, enabling models to generalize to new tasks rapidly and flexibly through prompt engineering, rather than explicit retraining or gradient-based adaptation.

1. Formal Definition and Theoretical Placement

ICL is formally characterized by the model’s use of a demonstration context CC, typically composed of kk labeled examples and, optionally, explicit instructions II. Given a query input xx and a set of candidate outputs Y={y1,,ym}Y = \{y_1, \ldots, y_m\}, the pretrained model M\mathcal{M} predicts via: P(yjx)fM(yj,C,x)P(y_j \mid x) \triangleq f_{\mathcal{M}}(y_j, C, x) where ff is a task- and model-dependent scoring function (often the conditional log-probability).

ICL is related to, but distinct from, several existing learning paradigms:

  • Prompt-based Learning: ICL is a subclass that restricts prompts to interpretable, discrete contexts containing actual demonstrations.
  • Few-shot Learning: Unlike traditional few-shot learning, which updates parameters using labeled examples, ICL performs all task adaptation in the context, with no weight updates.
  • Meta-learning: ICL is often cast as implicit meta-learning, with LLMs leveraging patterns and structures present in their pretraining corpus to perform “learning” purely through context, mimicking human analogical reasoning.

The survey notes the emerging consensus that ICL’s effectiveness grows as a scaling property of LLMs.

2. Key Techniques and Methodologies

Training Strategies

ICL performance can be enhanced through intermediate training strategies:

  • Supervised In-Context Finetuning: Methods like MetaICL and OPT-IML format tasks during training identical to ICL inference scenarios, reducing distribution shift between pretraining and downstream use.
  • Instruction Tuning: Enriches model capability across tasks by integrating natural language instructions (e.g., FLAN, Super-NaturalInstructions).
  • Self-Supervised In-Context Training: Constructs unsupervised objectives that match ICL framing, utilizing raw corpus data for masked or completion-based objectives structured as demonstrations.

Prompt Design

The design and organization of demonstration prompts are pivotal:

  • Selection: Optimal example selection may be unsupervised (e.g., by embedding distance, mutual information, perplexity, or maximizing diversity) or supervised (e.g., using learned retrievers, reinforcement learning).
  • Ordering: Demonstration order substantially influences performance. Techniques utilizing entropy-based ordering have been proposed to exploit or mitigate order sensitivity.
  • Formatting: Explicitly incorporating task instructions or intermediate reasoning steps (Chain-of-Thought, Least-to-Most Prompting) within demonstrations further augments model performance and stability.

Scoring and Output Selection

ICL inference may rely on alternative output selection mechanisms:

  • Direct Conditional Probability: Selecting outputs based on model likelihoods.
  • Perplexity-based Methods: Utilizing total sequence perplexity to support variable output locations.
  • Channel Models: Evaluating M(xC,yj)\mathcal{M}(x | C, y_j) instead of the forward direction.
  • kNN and Structured Prompting: Nearest-neighbor prompting and structured retrieval further enhance precision and robustness.

3. Application Domains and Use Cases

ICL has rapidly extended across diverse natural language and cross-modal tasks:

  • Traditional NLP Tasks: Including translation, information extraction, question answering, and text-to-SQL.
  • Reasoning Tasks: Notably, ICL underpins advances in mathematical reasoning and compositional generalization, especially when combined with complex prompt designs (e.g., Chain-of-Thought).
  • Meta-learning and Instruction Learning: Facilitates fast task adaptation and task-agnostic reasoning via demonstration alone.
  • Multimodal Tasks: ICL has been applied to settings beyond text, such as visual infilling (SegGPT), segmentation, vision-LLMs (Flamingo, Kosmos-1), and even speech.
  • Data Engineering: LLMs using ICL can annotate data with high efficiency, offering up to 50–96% cost reductions over human annotation and enabling hybrid human-LLM labeling strategies.
  • Knowledge Updating and Model Editing: Counterfactual or corrective demonstrations in the prompt can induce on-the-fly behavioral adjustments, outperforming parameter-based model editing by reducing unwanted side effects.
  • Retrieval-Augmented and Safety-Critical Applications: ICL enables retrieval-augmented generation for improved factuality and can be used to steer model outputs towards safer or less biased responses by demonstration selection.

4. Challenges and Open Directions

Several fundamental challenges are highlighted:

  • Pretraining-ICL Objective Gap: There exists a mismatch between typical pretraining objectives (e.g., next-token prediction) and the requirements of effective ICL, motivating novel pretraining strategies.
  • Robustness: ICL is highly sensitive to the selection, ordering, and formatting of demonstrations; performance can range from random to state-of-the-art with minor changes in context.
  • Scalability and Efficiency: The maximum number of demonstrations is constrained by LLM context limits, with attention-based computation scaling quadratically with prompt length.
  • Analytical Understanding: The mechanisms that underlie ICL remain only partially understood; links to meta-learning, Bayesian inference, and implicit gradient descent are suggested but require further theoretical grounding.

Priority Research Directions

  • New Pretraining Objectives targeting ICL functionality directly.
  • Ability Distillation: Transferring ICL capabilities from large to smaller models for improved efficiency.
  • Benchmarking and Evaluation: Development of comprehensive, stable benchmarks and transparent evaluation tools (e.g., OpenICL).
  • Domain Expansion: Broadening ICL to graphs, images, structured data, and cross-modal settings.
  • Corpus-Level and Dynamic Prompt Selection: Moving beyond per-instance selection towards more globally optimal or real-time adaptive demonstration strategies.

5. Practical Impact and Outlook

ICL constitutes a paradigm shift for both practical NLP applications and the theoretical paper of LLMs. Its techniques—spanning training, prompt design, and scoring—yield broad and sometimes dramatic performance gains across a wide spectrum of tasks, particularly where rapid adaptation or minimal infrastructure is necessary (e.g., zero-shot/few-shot deployment scenarios, data annotation, knowledge distillation).

Despite its strengths, unresolved questions about robustness, scalability, and the underlying mechanisms of ICL ensure its continued focus as an area of research. Ongoing work on improved pretraining strategies, evaluation methodologies, and applications beyond language are likely to shape the next phase of LLM and ICL advancements.


Summary Table: Key Dimensions of In-Context Learning

Dimension Description Example/Technique
Prompt Construction Selection, order, format, and instructions in the context Entropy-ordering, Chain-of-Thought
Training Strategies Additional objectives bridging pretraining and ICL needs MetaICL, Super-NaturalInstructions
Output Scoring Methods for selecting predicted output from model probabilities Perplexity, channel models, kNN
Application Domains NLP, reasoning, multimodal, data engineering, safety Data annotation, visual ICL, model editing
Open Challenges Robustness, scalability, pretraining-objective mismatch OpenICL, structured prompting
Future Directions More robust theory, domain extension, efficient distillation Domain-agnostic ICL, OpenICL toolkit

ICL continues to redefine boundaries in both research and real-world machine learning applications, with its evolution closely tied to advances in model architecture, data engineering, and our understanding of artificial intelligence systems.