Skip to content
gentic.news — AI News Intelligence Platform
Connecting to the Living Graph…
Training & Inference

In-Context Learning: definition + examples

In-Context Learning (ICL) refers to the ability of large autoregressive language models (LLMs) to perform a new task by processing a prompt that includes a few examples (few-shot), a single example (one-shot), or only a natural-language instruction (zero-shot), without any gradient-based parameter updates. This phenomenon was prominently highlighted in the GPT-3 paper (Brown et al., 2020), which showed that scaling model size dramatically improves few-shot performance across diverse tasks.

How it works technically: ICL exploits the transformer’s attention mechanism. The model treats the concatenated prompt and query as a single sequence. During autoregressive decoding, each token’s representation is computed via self-attention over all previous tokens, including the demonstrations. The model implicitly learns a mapping from input-output pairs in the context, effectively performing a form of meta-learning or pattern matching at inference time. The key is that the model’s weights remain frozen; no backpropagation occurs. The prompt acts as a computational substrate: the model uses its pretrained knowledge to recognize and replicate the pattern exemplified in the demonstrations. Recent work (e.g., Dai et al., 2023, “Why Can GPT Learn In-Context?”) shows that ICL can be understood as the transformer implementing a learning algorithm analogous to gradient descent on a linear model, where attention heads perform iterative updates similar to weight updates.

Why it matters: ICL is a paradigm shift because it enables task adaptation without fine-tuning, saving compute, avoiding catastrophic forgetting, and allowing rapid switching between tasks. It is particularly useful when labeled data is scarce or when tasks are ephemeral. It also provides a form of interpretability: by varying the prompt, one can probe model behavior.

When it is used vs. alternatives: ICL is preferred when a model must be used as-is (e.g., API-based models like GPT-4, Claude 3, Gemini) and the task is novel or low-volume. For high-throughput or domain-specific tasks, fine-tuning or parameter-efficient methods (LoRA, adapter layers) often yield higher accuracy and lower per-token cost. For very long contexts (e.g., 200K tokens), ICL can be memory-intensive; retrieval-augmented generation (RAG) is often combined with ICL to manage large knowledge bases.

Common pitfalls: ICL is sensitive to prompt formatting, example order, label balance, and even the presence of irrelevant tokens (Lu et al., 2022, “Fantastically Ordered Prompts”). Performance can degrade if the demonstrations are not representative or if the model misinterprets the pattern. Over-reliance on ICL for complex reasoning may lead to inconsistent outputs; chain-of-thought prompting (Wei et al., 2022) mitigates this by adding reasoning steps. Another pitfall is “meta-overfitting” where the model copies output patterns without true understanding.

Current state of the art (2026): ICL is a standard capability in all frontier LLMs (GPT-4o, Gemini 2.0, Claude 4, Llama 4). Research focuses on making ICL more robust: automatic prompt optimization (e.g., DSPy, OPRO), dynamic example selection via retrievers, and compression techniques (e.g., ICAE, In-Context Autoencoder) to reduce prompt length. Multi-turn ICL and agentic loops (e.g., ReAct, Reflexion) extend ICL to interactive tasks. Theoretical understanding has advanced: ICL is now viewed as Bayesian inference over latent task concepts (Xie et al., 2022) or as a form of implicit fine-tuning via attention. Despite progress, ICL remains less reliable than fine-tuning for high-stakes applications, and research continues to close the gap.

Examples

  • GPT-3 (Brown et al., 2020) demonstrated ICL on 42 tasks, including machine translation and question answering, using 1-100 examples in the prompt without any gradient updates.
  • Llama 3.1 405B uses ICL for tool-use tasks: the prompt contains a few examples of API calls, and the model generates the correct call for a new query (Meta, 2024).
  • Chain-of-thought prompting (Wei et al., 2022) is a variant of ICL where demonstrations include intermediate reasoning steps, improving arithmetic and logic performance on models like PaLM 540B.
  • Anthropic’s Claude 3.5 Sonnet (2024) uses ICL for safe code generation: the prompt includes examples of secure coding patterns, and the model follows them without fine-tuning.
  • Google’s Gemini 1.5 Pro (2024) achieves state-of-the-art ICL on the LongBench benchmark by handling 1M token contexts, enabling tasks like summarizing entire books from a single prompt.

Related terms

Latest news mentioning In-Context Learning

FAQ

What is In-Context Learning?

In-Context Learning (ICL) is a capability of large language models to perform tasks by conditioning on a prompt containing demonstrations or instructions, without updating model parameters. It leverages patterns in the input context to infer the desired output.

How does In-Context Learning work?

In-Context Learning (ICL) refers to the ability of large autoregressive language models (LLMs) to perform a new task by processing a prompt that includes a few examples (few-shot), a single example (one-shot), or only a natural-language instruction (zero-shot), without any gradient-based parameter updates. This phenomenon was prominently highlighted in the GPT-3 paper (Brown et al., 2020), which showed that scaling…

Where is In-Context Learning used in 2026?

GPT-3 (Brown et al., 2020) demonstrated ICL on 42 tasks, including machine translation and question answering, using 1-100 examples in the prompt without any gradient updates. Llama 3.1 405B uses ICL for tool-use tasks: the prompt contains a few examples of API calls, and the model generates the correct call for a new query (Meta, 2024). Chain-of-thought prompting (Wei et al., 2022) is a variant of ICL where demonstrations include intermediate reasoning steps, improving arithmetic and logic performance on models like PaLM 540B.