Definition
Few-shot learning is the technique of giving a language model a small number of worked examples — typically between two and ten — directly inside the prompt, so it can infer the desired pattern and apply it to a new input. It is a form of in-context learning: the model adapts its behaviour at inference time purely from what it sees in the prompt, without any change to its weights. The examples act as a demonstration of “here is the task, and here is exactly what a good answer looks like”.
Zero-shot, few-shot, and fine-tuning
Few-shot sits between two neighbours:
- Zero-shot — you give only an instruction (“Classify this review as positive or negative”) and rely on the model’s pre-trained knowledge. Fast, but format and edge cases can be inconsistent.
- Few-shot — you prepend several labelled examples before the real input. This anchors both the format and the decision boundary and usually lifts accuracy on niche or ambiguous tasks.
- Fine-tuning — you actually retrain the model’s weights on a dataset. Powerful and cheap per call at scale, but slower to set up and harder to iterate.
A simple template
A classification prompt might look like:
Classify the sentiment as Positive or Negative.
Review: "Loved it, would buy again." -> Positive
Review: "Broke after one day." -> Negative
Review: "Honestly the best purchase this year." ->
The two labelled examples teach the format (a single word) and the boundary, so the model completes the third line correctly.
Best practices
Use clear, diverse, and correct examples — the model copies their format and any mistakes in them. Order matters: keep examples consistent in structure, and note that the most recent example can carry extra weight. Start small (two or three) and add more only if it measurably helps, since every example consumes context tokens that could otherwise hold the real input.
When to reach for it
Few-shot is the right tool when a task needs a specific output format, when the request is ambiguous without illustration, or when you want quick gains without a training pipeline. Move to fine-tuning when you call the same task thousands of times, when examples no longer fit the context window, or when you need stronger reliability than prompting alone can guarantee.