What is one-shot learning?
One-shot learning is when a model learns a new class or task from a single example. In image recognition it means one example per new class; in language models, one solved example added to the prompt with a task description.
Unlike few-shot learning, which gives as many examples as fit in the context window, one-shot uses exactly one; zero-shot gives only a natural language instruction.
- Topic
- Prompts, context, reasoning and generation
- Also known as
- One-shot prompting, single-demonstration prompting
- Origin
- 2006, study of visual object categories; 2020, one-shot prompting in language models
How one-shot learning works
- Classical approaches use knowledge from previously learned categories as a prior, updated by the new class's single example.
- Siamese networks score whether two images share a class, comparing a test image with one example per new class and picking the top match.
- Matching networks map a small labelled support set and an unlabelled example straight to a label, without fine-tuning for new classes.
- Language model prompts hold a task description, one input and output example and the new input; weights stay unchanged.
In more detail
Results of matching networks
The 2016 paper introducing matching networks raised one-shot accuracy over competing approaches from 87.6% to 93.2% on an image dataset and from 88.0% to 93.8% on Omniglot, a dataset of handwritten characters. The same model was also tested on a one-shot task defined for language modelling.
Commonly confused terms
| Term | How it differs |
|---|---|
| Meta-learning | Meta-learning learns from a broad distribution of tasks in order to adapt rapidly to a new one. One-shot learning is the setting in which that adaptation happens with a single example. |
Why one-shot learning matters for on-premises AI
Visual category models traditionally need hundreds or thousands of examples, which are costly to label. One example shows a task's format most briefly: in a 2020 study, trivia question benchmark accuracy was 64.3% zero-shot, 68.0% one-shot and 71.2% few-shot. The same study notes that without examples a task's format can be hard to convey.
A logistics company's waybill extraction prompt includes the task description, one sample waybill and its expected JSON output. That example helps the model hit the output format; the team compares zero, one and few-shot versions on its validation set.
Common questions
Is the model retrained in one-shot learning?
Not in language models: the example is added to the prompt and weights do not change. In classical approaches such as matching networks the model is trained beforehand on other classes and is not fine-tuned for the new class.
Should I give one example or several?
It depends on the task and model. In one study accuracy rose from zero to one example and again to a few, but every example takes space in the context window. Choose by measuring on your own data.
Is one-shot learning the same as in-context learning?
A one-shot prompt is the single-demonstration form of in-context learning. The idea of one-shot learning predates language models and was used for image recognition methods that work with one example per class.
Related terms
Sources
- One-Shot Learning of Object Categories, IEEE TPAMI, 2006
- Siamese Neural Networks for One-shot Image Recognition, ICML, 2015
- Matching Networks for One Shot Learning, arXiv, 2016
- Language Models are Few-Shot Learners, arXiv, 2020
In the glossary: Glossary, M to Q