In-context learning is the ability of a language model to adapt its behavior to a new task based purely on the content of its prompt, without any update to the model's parameters. A user can provide instructions, examples, or supporting documents within the Context window of a single conversation, and the model will condition its next output on that material as though it had been trained for the task, even though no training actually occurred. It is the mechanism underlying both Few-shot learning and Zero-shot learning prompting, and it is one of the most consequential behaviors observed in modern Transformer (architecture)-based Large language model systems.
The phenomenon was highlighted prominently in the 2020 GPT-3 paper, which showed that a large enough pretrained model could perform new tasks from a handful of prompt examples with no gradient updates. Because this looked superficially like the model was "learning" within a single forward pass, the term in-context learning was adopted to distinguish it from ordinary training-time learning, which changes the weights, and from Transfer learning or Fine-tuning, which also require an explicit optimization step on task-specific data.
How it works
There is no single settled mechanistic explanation for in-context learning, but several complementary accounts are widely cited. One view treats it as a form of implicit pattern matching: because the model's Pretraining corpus contains countless examples of tasks being explained, demonstrated, and solved in text, the model has learned a general procedure for continuing "task, examples, then a new instance" sequences in a way that satisfies the implied pattern. A more mechanistic line of interpretability research has proposed that the Attention mechanism inside transformers can implement something resembling a simple learning algorithm internally, effectively performing a lightweight form of pattern completion or even gradient-descent-like computation across the tokens in the prompt, though this remains an active and contested area of study connected to broader Mechanistic interpretability research. In-context learning is also closely tied to the emergence of capabilities with scale, discussed under Emergent abilities, since smaller models tend to benefit far less from added context than sufficiently large ones.
Uses
In-context learning underlies most practical uses of Prompt engineering, including few-shot demonstrations, role and persona instructions via a System prompt, and providing reference material directly in the prompt so the model can answer questions about it, a pattern that scales up into Retrieval-augmented generation when the reference material is fetched dynamically from an external source rather than pasted by hand. It also enables rapid task-switching within a single conversation: a chat assistant can move from writing code to translating a paragraph to summarizing a document purely because each new instruction reconditions the model's behavior, without any retraining between turns.
Limitations and significance
In-context learning is bounded by the size of the context window and tends to degrade as the amount of information in the prompt grows very large or when relevant details are buried in the middle of a long input, an effect sometimes described informally as a model "losing track" of context. It is also not persistent: because no weights change, anything learned in context is forgotten as soon as the conversation ends or the context is cleared, in contrast to fine-tuning, which produces a lasting change to the model. Despite these limits, in-context learning is considered one of the most important properties of the transformer architecture for practical deployment, since it allows a single general-purpose model to be repurposed for an effectively unlimited range of tasks at inference time, without the cost, delay, or infrastructure that retraining or fine-tuning a model would require.