Skip to main content
Cloud & AI Hub
Browse
Glossary AI Directory Playgrounds Models Prompts Explainers Strategy Matrix Benchmark Decoder

In-Context Learning

The capacity of LLMs to recognize patterns and adapt behaviors based on examples provided in the prompt.

Last reviewed: July 25, 2026

In-context learning is the ability of large language models to adapt their behavior based on examples or instructions provided directly in the prompt, without any update to the model’s underlying weights. It’s the mechanism that makes few-shot and zero-shot prompting possible: a model can learn to perform a new task — classify sentiment in a specific format, follow an unfamiliar output schema, or mimic a particular writing style — purely from what’s shown to it within a single forward pass.

Why It’s Notable

Before in-context learning was well understood, adapting a model to a new task typically meant fine-tuning it on task-specific labeled data, which requires additional training compute and produces a separate, specialized version of the model. In-context learning showed that sufficiently large models could instead be steered at inference time simply by demonstrating the desired behavior in the prompt — a capability first highlighted prominently in OpenAI’s 2020 GPT-3 paper, which showed few-shot performance approaching fine-tuned models on several benchmarks.

How It’s Believed to Work

The prevailing explanation is that during pretraining on massive, diverse text corpora, models implicitly encounter many structured patterns — question-answer pairs, translation examples, formatted lists — often enough that they learn a general capacity to recognize and continue a demonstrated pattern, rather than learning any one task specifically. This is distinct from traditional machine learning generalization; the model isn’t updating its parameters based on the in-context examples, it’s using the existing frozen weights to recognize and extend a pattern present in the current context.

Practical Implications

In-context learning is the foundation of prompt engineering as a discipline: it’s why providing 2-3 well-chosen examples (few-shot prompting) often improves accuracy more than elaborate zero-shot instructions alone, and why the order, formatting, and diversity of those examples measurably affects output quality.

The Ongoing Debate About What’s Really Happening

There remains active research debate about the precise mechanism behind in-context learning — some researchers argue it resembles a form of implicit gradient descent happening within the forward pass itself (sometimes called “meta-optimization”), while others frame it more simply as sophisticated pattern completion drawing on structures already present in the pretrained weights, without anything resembling learning happening at inference time. This distinction isn’t just academic: it has practical implications for how reliably in-context learning generalizes to genuinely novel patterns versus how much it depends on the pattern resembling something the model implicitly encountered during pretraining, which affects how much trust to place in few-shot performance on tasks meaningfully different from anything in a model’s training distribution.

Advertisement (In-Content)

Historical figures and technical concepts for informational purposes only. Not technical, professional, legal, or financial advice. Sources: Official Documentation.