What is In-Context Learning?
In-context learning is a prompting technique where a pre-trained model performs new tasks by inferring patterns from examples included directly in the input prompt, without updating its weights.
The model receives a prompt containing task instructions plus one or more input-output examples. It uses its existing parameters to recognize the pattern and generate the correct output for a new query that follows the same format.
No gradient updates or fine-tuning occur; the 'learning' happens entirely within the forward pass by conditioning on the provided context. Performance typically improves as more relevant examples are added, up to the model's context window limit.
This approach emerged prominently with large language models and enables rapid task adaptation using only natural language, bridging zero-shot and traditional supervised learning.
Example
A prompt might list three math word problems with their step-by-step solutions, then ask the model to solve a fourth similar problem. The model mimics the demonstrated reasoning style to produce the answer.
Why it matters
It allows large models to handle novel tasks instantly without costly retraining, making powerful AI systems far more flexible and accessible for real-world applications.
Frequently asked questions
Normal training updates model weights with gradient descent; in-context learning leaves weights unchanged and only uses examples inside the prompt.
Related terms
Few-shot learning (in prompting) is a technique where a language model is given a handful of input-output examples directly in the prompt to guide it on a new task.
Prompt engineering is the practice of designing and refining text inputs (prompts) to guide AI models like large language models toward producing accurate, relevant, or creative outputs.
Zero-shot learning (or zero-shot prompting) is when an AI model completes a task it has never seen examples of during training, relying only on a natural language description of what to do.
Fine-tuning is the process of taking a pre-trained AI model and continuing its training on a smaller, task-specific dataset to adapt it for a particular use case.
Transfer learning is a machine learning method that reuses a model trained on one task as the starting point for a different but related task.
Chain-of-Thought (CoT) is a prompting technique that asks an AI model to generate intermediate reasoning steps before giving a final answer, helping it solve complex problems more reliably.