# Prototypical Networks for Few-shot Learning

Prototypical networks classify new classes by distance to class means

Jake Snell, Kevin Swersky, Richard S. Zemel · arXiv · 2017-3-15

- **Problem** Retraining a classifier on a few examples of each new class overfits badly. Recent few-shot methods rely on complicated architectures and meta-learning.
- **Method** Prototypical networks average the embedded support examples of each class into one prototype. A query is then assigned to the nearest prototype by squared Euclidean distance.
- **Results** On 5-way 1-shot Omniglot, prototypical networks scored 98.8%, compared to 98.1% for matching networks with cosine distance.

## Why few-shot classifiers overfit

Few-shot classification asks a classifier to recognise classes absent from training, given only a handful of labelled examples per new class. Retraining the model on that tiny new dataset would overfit badly, so the method has to be built around that risk. Humans can still identify a class from a single example with high accuracy, which shows the task is possible but hard for models.

Two recent lines of work made real progress, and both rely on episodic training. Matching networks apply attention over a learned embedding of the support set, which gives a weighted nearest-neighbour classifier. Ravi and Larochelle train an LSTM to produce updates for a classifier, so each episode gets its own custom model.

The authors treat overfitting as the central issue and argue that a few-shot classifier should have a very simple inductive bias.

## Class means as prototypes

The key idea is to learn an embedding space where the examples of each class cluster around one point, and to use that point as the class prototype. Each prototype is the mean of the embedded support examples of its class, so a class needs only one vector to be stored.

A neural network \\(f\_\\phi\\) maps each \\(D\\)-dimensional input into an \\(M\\)-dimensional space, and the prototype of class \\(k\\) averages the embedded support points in \\(S\_k\\). \\\[ c\_k = \\frac{1}{\|S\_k\|}\\sum\_{(x\_i,y\_i)\\in S\_k} f\_\\phi(x\_i) \\\] Here \\(S\_k\\) is the set of support examples labelled with class \\(k\\), and the sum runs over those examples only.

For a query \\(x\\), the model takes a softmax over negative distances to all prototypes. \\\[ p\_\\phi(y=k\\mid x)=\\frac{\\exp(-d(f\_\\phi(x),c\_k))}{\\sum\_{k'}\\exp(-d(f\_\\phi(x),c\_{k'}))} \\\] Because the softmax uses negative distances, the closest prototype gets the highest probability, which is the same as classifying by the nearest prototype.

Training minimises the negative log-probability of the true class by SGD, averaged over query points in sampled episodes. Each episode randomly picks NC classes, then NS support examples and NQ query examples per class, computes the prototypes, and averages the query losses.

## Why squared Euclidean distance

The class mean is the optimal cluster representative only for certain distances, namely regular Bregman divergences. Squared Euclidean distance is one such divergence, and the Mahalanobis distance is another. The general form is \\\[ d\_\\phi(z,z') = \\phi(z)-\\phi(z')-(z-z')^T\\nabla\\phi(z') \\\]

For such distances, prototype classification is equivalent to inference in an equally weighted exponential family mixture with one cluster per class. The choice of distance therefore fixes the assumed shape of each class's distribution in the embedding. Squared Euclidean distance corresponds to spherical Gaussian densities.

Expanding the squared distance shows that the model is a linear classifier, with \\(w\_k = 2c\_k\\) and \\(b\_k = -c\_k^\\top c\_k\\). The first term of the expansion is the same for every class, so it drops out of the softmax. The authors hypothesise that the required non-linearity sits in the embedding function, as in modern neural classifiers.

Matching networks had used cosine distance, but the authors found squared Euclidean distance can greatly improve both kinds of network. They conjecture the main reason is that cosine distance is not a Bregman divergence, so the mixture view no longer holds.

## Matching networks and design choices

With one support example per class, the prototype is that example, so prototypical and matching networks become the same model. With more shots, matching networks keep a weighted nearest-neighbour rule, while prototypical networks stay linear under squared Euclidean distance. Multiple prototypes per class would need a partitioning step run apart from the weight updates, whereas this approach trains with ordinary gradient descent.

Episode construction is the other lever, and the authors found it can help a lot to train with more classes per episode than the test task uses. They tuned the training way on a held-out validation set and kept the training shot equal to the test shot. The authors skip the FCE-style extensions of matching networks and rely on simple design choices instead.

## Omniglot and miniImageNet results

On Omniglot, the same four-block encoder maps 28 by 28 images to a 64-dimensional space, and it encodes both support and query points. Each training episode had 60 classes and 5 query points per class, with the training shot matched to the test shot.

On 5-way 1-shot, prototypical networks with Euclidean distance scored 98.8%, compared to 98.1% for matching networks with cosine distance. On 20-way 1-shot, the figures were 96.0% compared to 93.8% for matching networks. The authors call these state-of-the-art results on this dataset, as far as they know. They read the margin as a sign that a simple inductive bias suits the small-data regime.

miniImageNet uses 84 by 84 images and the Ravi and Larochelle split of 64 training, 16 validation and 20 test classes. The same architecture produces a 1600-dimensional output here, and the validation classes only monitor generalisation. Training used 30-way episodes for 1-shot and 20-way episodes for 5-shot, with 15 query points per class.

Each result averages 600 test episodes and carries a 95% confidence interval.

On 5-way 1-shot, prototypical networks scored 49.42 ± 0.78%, compared to 43.44 ± 0.77% for the Meta-Learner LSTM as reported by Ravi and Larochelle. On 5-way 5-shot, the scores were 68.20 ± 0.66% and 60.60 ± 0.71%. The authors describe this as state of the art by a wide margin, against baselines that include non-fine-tuned matching networks and nearest neighbours on learned features.

The distance and training-way analysis uses the authors' own matching network implementation, built on the same encoder. Twenty-way training beat 5-way training, which the authors link to the finer decisions it forces in the embedding. Euclidean distance beat cosine distance, and the gap was larger for prototypical networks, since a mean suits Euclidean distance better.

In the 1-shot case the two methods are identical, so that comparison isolates the choice of distance and training way.

## Zero-shot classification on CUB-200 2011

In the zero-shot setting a class has no support examples, only a meta-data vector \\(v\_k\\). The prototype becomes \\(c\_k = g\_\\vartheta(v\_k)\\), an embedding of the meta-data in the same space as the image embedding. The authors fix the prototype embedding to unit length because attributes and images come from different domains, and they leave the query embedding unconstrained.

CUB-200 2011 has 11,788 images of 200 bird species, split into 100 training, 50 validation and 50 test classes. Images use 1,024-dimensional GoogLeNet features from several crops, while each class is described by 312 attribute values. A linear map sends both the image features and the attribute vectors into a 1,024-dimensional space.

At 50-way zero-shot, prototypical networks scored 54.6%, compared to 50.9% for DA-SJE with GoogLeNet features. The authors describe the margin as large and read it as evidence that the approach works even when images and classes come from different domains. The baseline rows carry the citations of earlier papers, so the comparison rests on their reported numbers.

## Where the method sits among related work

Non-linear NCA also uses a neural network and a softmax over Euclidean distances, but it forms the softmax over individual points. Prototypical networks form the softmax over class prototypes, so the support set need not be kept for prediction.

Nearest class mean classifiers also use class means, but they rely on a linear embedding and target classes with many examples. Mensink et al. add multiple prototypes through k-means on the input space, whereas prototypical networks learn one prototype per class end to end.

Matching networks and prototypical networks both build classifiers from new episodes, yet their embeddings are fixed after training. The neural statistician is a generative model of datasets, while prototypical networks are discriminative.

## Limitations

Bregman divergences beyond squared Euclidean distance are left as future work. A variance per dimension for each class gave no empirical gain in preliminary explorations, which the authors take to mean the embedding has enough flexibility.

The explanation for why cosine distance underperforms is a conjecture, not a tested result. Experiments cover Omniglot, miniImageNet and CUB-200 2011 only, and zero-shot learning was tested on CUB-200 2011 alone. The Omniglot results average 1000 test episodes, and the miniImageNet results average 600 with 95% confidence intervals. The FCE-style extensions were not tested together with prototypical networks.

## Paper info

- **Authors**: Jake Snell, Kevin Swersky, Richard S. Zemel
- **Venue**: arXiv · Preprint
- **First published**: 2017-3-15
- **Added**: 2026-11-11
- **Updated**: 2017-6-19
- **Version**: v2
- **arXiv**: 1703.05175
- **Category**: cs.LG · stat.ML
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1703.05175v2) · [PDF ↗](https://arxiv.org/pdf/1703.05175v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Jake Snell, Kevin Swersky, Richard S. Zemel (2017). Prototypical Networks for Few-shot Learning. arXiv:1703.05175v2. https://arxiv.org/abs/1703.05175v2

**BibTeX**

```
@misc{snell2017prototypical,
  title = {{Prototypical Networks for Few-shot Learning}},
  author = {Jake Snell and Kevin Swersky and Richard S. Zemel},
  year = {2017},
  eprint = {1703.05175},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1703.05175v2}
}
```

## Other paper commentary

- [How transferable are features in deep neural networks?](https://refivu.com/en/papers/cb0b30a7-565d-41f8-bd71-41713c953bea-how-transferable-are-features-in-deep-neural-networks.md)
- [Recent Advances in Convolutional Neural Networks](https://refivu.com/en/papers/7bfaa2e2-6e96-45b8-b038-2820fa693e61-recent-advances-in-convolutional-neural-networks.md)
- [Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering](https://refivu.com/en/papers/0acc0ddc-2464-497b-a440-69d6bbfb7937-convolutional-neural-networks-on-graphs-with-fast-localized.md)
- [Coordinate Attention for Efficient Mobile Network Design](https://refivu.com/en/papers/dfcb6641-7770-48f4-826a-22a20dca2f0b-coordinate-attention-for-efficient-mobile-network-design.md)
- [Dual Attention Network for Scene Segmentation](https://refivu.com/en/papers/849ff02e-2552-4ac6-a139-a8a0f4332d34-dual-attention-network-for-scene-segmentation.md)
- [An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling](https://refivu.com/en/papers/b568511a-a3c8-42b3-9fd2-bd1b072662ac-an-empirical-evaluation-of-generic-convolutional-and.md)
- [Explanation in Artificial Intelligence: Insights from the Social Sciences](https://refivu.com/en/papers/97a0e87f-2056-41e6-ba4d-00a7f2aa4ab0-explanation-in-artificial-intelligence-insights-from-the.md)
- [Retrieval-Augmented Generation for Large Language Models: A Survey](https://refivu.com/en/papers/ac45776a-0a09-4a03-a773-f9aa88c71453-retrieval-augmented-generation-for-large-language-models-a.md)
- [MissForest - nonparametric missing value imputation for mixed-type data](https://refivu.com/en/papers/ab5b3748-ade4-4bb9-b016-975b4f82baee-missforest-nonparametric-missing-value-imputation-for-mixed.md)
- [Deformable DETR: Deformable Transformers for End-to-End Object Detection](https://refivu.com/en/papers/e0311cd6-f252-409d-a37d-7b236622ec8e-deformable-detr-deformable-transformers-for-end-to-end.md)
- [BERTScore: Evaluating Text Generation with BERT](https://refivu.com/en/papers/30f8b3be-d1a1-4c44-9203-702fc98d0cc9-bertscore-evaluating-text-generation-with-bert.md)
- [Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation](https://refivu.com/en/papers/178a13b8-5d0e-4448-a1cb-759db558ade3-swin-unet-unet-like-pure-transformer-for-medical.md)

## Terms in this paper

- [classification accuracy](https://refivu.com/en/terms/3c67905d3166-classification-accuracy)
- [Omniglot](https://refivu.com/en/terms/207a37dcf16c-omniglot)
- [cosine distance](https://refivu.com/en/terms/e6f2fa77e243-cosine-distance)
- [miniImageNet](https://refivu.com/en/terms/026c3473346e-miniimagenet)
- [Prototypical networks](https://refivu.com/en/terms/525a04df527e-prototypical-networks)
- [Support set](https://refivu.com/en/terms/6ca07dac69e7-support-set)
- [Bregman divergence](https://refivu.com/en/terms/901f7d5a921d-bregman-divergence)
- [few-shot classification](https://refivu.com/en/terms/f633be9d0a73-few-shot-classification)
- [squared Euclidean distance](https://refivu.com/en/terms/3bfb73dbbef3-squared-euclidean-distance)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/04a3b578-d356-4e26-95c4-7e6362f71054-prototypical-networks-for-few-shot-learning)
