Few-shot learning

Also known as: few-shot classification · FSL

On this page 7

Few-shot learning (FSL) is a machine learning setting in which a model must generalize to new classes or tasks from very few labeled examples, typically between one and twenty per class. Instead of collecting thousands of samples for each category, the model relies on prior knowledge acquired from related data and adapts it to the new task with a small support set.

The setting is usually described as N-way K-shot classification: the model sees N new classes with K labeled examples each and must classify unseen queries among them. The term few-shot classification is often used as a synonym, while the broader idea also covers regression, detection and, in large language models, in-context learning from a few prompt examples.

How few-shot learning is structured

Few-shot learning separates data into base classes and novel classes. The model is trained on base classes with plentiful data and evaluated on novel classes it has never seen, using only the few labeled examples provided at test time. This split is what distinguishes it from ordinary supervised learning with a small dataset.

Each evaluation unit is called an episode. An episode contains a support set of N classes with K labeled examples each and a query set of unlabeled examples to classify. Many methods also train in episodes, a practice known as episodic training, so that training conditions mirror test conditions.

The table below defines the core vocabulary used across the field.

TermMeaningTypical value
N-wayNumber of novel classes in an episode5 or 20
K-shotLabeled examples per novel class1, 5 or 10
Support setThe N times K labeled examples5 to 100 samples
Query setExamples the model must classify15 per class is common
Base classesClasses with abundant training dataTens to thousands
Core terms in few-shot learning

Main families of few-shot methods

Few-shot methods fall into three broad families, each answering the question of how prior knowledge is transferred in a different way. In practice, strong systems often combine elements of several families.

Metric-based methods learn an embedding space in which examples of the same class lie close together, then classify queries by distance to the support examples. Optimization-based methods, often grouped under meta-learning, learn an initialization or update rule that adapts quickly with a few gradient steps. Transfer-based methods pretrain a large feature extractor and then fit a simple classifier on top of the frozen or lightly tuned features.

FamilyRepresentative methodsCore idea
Metric-basedSiamese networks, Prototypical Networks, Matching NetworksCompare queries with class prototypes in an embedding space
Optimization-basedMAML, ReptileLearn parameters that adapt in a few gradient steps
Transfer-basedPretrained backbone with linear probe or fine-tuningReuse rich general features
In-contextLarge language models with prompt examplesCondition on examples without weight updates
Representative few-shot learning approaches

A Prototypical Network, for example, computes the mean embedding of each class in the support set and assigns a query to the nearest mean. Its simplicity and robustness made it a standard baseline against which newer methods are measured.

Few-shot learning is closely tied to zero-shot learning, metric learning and transfer learning, and the boundaries between them are a frequent source of confusion. The key differentiator is what information is available for the new classes at prediction time.

SettingData for new classesTypical mechanism
Few-shot learningA few labeled examplesEmbeddings, meta-learning or light fine-tuning
One-shot learningExactly one labeled exampleSpecial case of few-shot learning
Zero-shot learningNo examples, only descriptions or attributesSemantic embeddings linking text and inputs
Transfer learningUsually hundreds or more examplesFine-tuning a pretrained model
Metric learningNot a setting, a techniqueLearns distances used by many few-shot methods
How few-shot learning differs from neighboring settings

Few-shot learning also differs from data augmentation and SMOTE, which create more samples for an existing class. Augmentation can support few-shot learning, but it does not by itself supply the transferable knowledge that the setting requires.

Applying few-shot learning in practice

Few-shot learning is most valuable when labeling is expensive, slow or impossible to scale: rare diseases in medical imaging, new product categories in retail, emerging fraud patterns, rare species in ecology, or a new customer intent in a support chatbot. It is also useful when classes change often and full retraining is impractical.

Choosing an approach depends mainly on the available pretrained models and on how far the new task lies from the training data. The decision table below gives a practical starting point.

SituationRecommended approachReason
Strong pretrained backbone availableLinear probe or prototypes on frozen featuresSimple, fast and hard to beat
Many related tasks for trainingEpisodic metric or meta-learningLearns how to adapt
Text classification with a language modelPrompt with a few examplesNo training needed
Large domain shift from pretrainingLight fine-tuning with strong regularizationFeatures need adjustment
Fewer than 3 examples per classPrototypes plus data augmentationReduces variance of estimates
Choosing a few-shot strategy

A recurring finding in research is that a well-pretrained feature extractor with a simple classifier often matches or beats elaborate meta-learning algorithms. Teams should therefore test that baseline first before investing in more complex training schemes.

Limitations and evaluation pitfalls

Few-shot learning is fragile because every decision rests on a tiny support set. One mislabeled or atypical example can shift a class prototype and change many predictions. Reported results are also hard to compare across papers. The most common pitfalls are listed below.

  • High variance between episodes: accuracy should be averaged over hundreds or thousands of episodes with confidence intervals.
  • Class overlap or data leakage between base and novel classes inflates benchmark scores.
  • Domain shift: models trained on natural images often fail on medical, satellite or industrial data.
  • Benchmark saturation on datasets such as miniImageNet and Omniglot hides weak real-world generalization.
  • Comparisons that use different backbones attribute gains to the method rather than to the feature extractor.

Few-shot learning reduces labeling cost but does not remove the need for representative data. The base data must cover features relevant to the new task, otherwise no adaptation method can recover what the model never learned.

In simple terms

A child who has seen many animals can recognize a new one after seeing two photos. The child does not start from zero. Few-shot learning gives a computer the same ability. It learns a new category from a few examples.

The trick is prior experience. The model first learns from a large collection of other data. Then it uses that knowledge to understand the new examples quickly. Less labeling work is the main benefit.

A practical example

A manufacturer of printed circuit boards wants to detect a newly discovered solder defect. Only eight images of the defect exist, because it appears in roughly one board out of 20,000. Collecting thousands of examples would take months.

The quality team takes a vision model pretrained on millions of general images and further trained on forty known defect types from the factory. They compute a prototype embedding from the eight new images and compare every inspected board region against all class prototypes, including the new one.

In a validation run on 500 held-out regions, the system flags the new defect with recall above 90 percent at an acceptable false alarm rate. Inspectors confirm flagged boards manually, and each confirmed case is added to the support set, so accuracy improves week by week without a full retraining cycle.