What is few-shot learning?
Few-shot learning is adding a few worked input and output examples to the prompt so the model can infer the target task from them and apply it to a new input.
It differs from fine-tuning in the weights: fine-tuning retrains the model on examples and changes its weights, while in few-shot learning weights stay the same and examples only form that request's context. It is the few-example form of in-context learning.
- Topic
- Prompts, context, reasoning and generation
- Also known as
- Few-shot, few-shot prompting
How few-shot learning works
- A few examples of inputs and expected outputs that represent the task are added to the prompt, followed by the new input.
- The model applies the style, decision criteria and output format shown in the examples to the new input.
- Choice, order and class balance of examples affect results noticeably, so the example set is tested.
- Examples are resent with every request; fixed ones are kept in a prompt template.
In more detail
Classic machine learning versus few-shot prompting in language models
Classical machine learning approaches few-shot learning through meta-learning (such as MAML) or metric learning (such as Prototypical Networks), updating parameters or embedding distances across episodes. Modern LLMs instead achieve few-shot behaviour at inference time through in-context learning without parameter updates.
From few-shot to many-shot and prefix caching
With modern long-context models, teams can scale from few-shot (typically 2 to 10 examples) to many-shot in-context learning (hundreds or thousands of examples) inside a single prompt. Many-shot learning can rival supervised fine-tuning on narrow tasks, though inference memory scales with context length unless prefix caching is enabled.
Dynamic example selection
Static prompts can fail when input diversity is high; dynamic few-shot prompting uses a vector store at runtime to retrieve the k most similar labelled examples for each incoming query. This improves accuracy across heterogeneous categories while keeping prompt token counts bounded.
Commonly confused terms
| Term | How it differs |
|---|---|
| Zero-shot learning | Zero-shot prompting gives only task instructions with no solved examples, whereas few-shot prompting supplies a handful of input-output demonstrations inside the context window. |
Why few-shot learning matters for on-premises AI
It adapts a model to organisational tasks quickly without preparing large labelled datasets or training; a few well-chosen examples often improve format and consistency markedly. If real customer data is used in examples it is masked; otherwise personal data is processed again with every request. Too many examples fill the context window and raise latency and cost. If gains flatten as examples grow, fine-tuning may be more efficient.
A bank adds one masked example per category to the prompt of its in-house complaint classification assistant and compares results with a labelled test set.
Common questions
How many examples are enough?
It depends on the task and model; a few are often enough. Too many fill the context window and add cost; the right number is found by testing.
Do the examples change the model's weights?
No. They are used only within that request's context; their effect ends with the request and they are sent again each time.
Related terms
Sources
- Brown et al., Language Models are Few-Shot Learners, 2020
- Zhao et al., Calibrate Before Use: Improving Few-Shot Performance of Language Models, 2021
- Wang et al., Generalizing from a Few Examples: A Survey on Few-Shot Learning, 2019
In the glossary: Glossary, D to L