# Matching Networks for One Shot Learning

Matching Networks classify a query by attending over a few labelled examples

Oriol Vinyals, Charles Blundell, Timothy Lillicrap, Koray Kavukcuoglu, Daan Wierstra · arXiv · 2016-6-13

- **Problem** Deep networks need many labelled examples and gradient steps to learn a new class. Their weights absorb each example slowly, so they cannot adapt from a few examples.
- **Method** Matching Networks label a query by attending over a small labelled support set, instead of fine-tuning the network on new classes.
- **Results** Matching Nets scored 93.8% on 20-way one-shot Omniglot, compared to 88.0% for the convolutional siamese net.

## Why one-shot learning is hard for parametric models

Deep networks have advanced speech, vision and language, but they usually depend on large datasets. Data augmentation and regularisation reduce overfitting in low-data regimes, but they do not remove the problem. Learning also stays slow, because each training example has to be absorbed into the parameters through many gradient steps.

Non-parametric models take in new examples quickly and avoid catastrophic forgetting. Nearest neighbours need no training, but their performance depends on the chosen metric. The authors want the rapid acquisition of non-parametric models together with the good generalisation that parametric models give on common classes.

## Key idea: attention over a labelled support set

Given a support set S of k image-label pairs, the model defines a distribution P(y\|x,S) over labels for each test example x, and the network that defines it is shared across all support sets. A new support set S' therefore needs no fine-tuning, because the same parametric network is simply applied to it.

In its simplest form the predicted output is a weighted sum of the support labels, with weights given by an attention function a. \\\[ \\hat{y} = \\sum\_{i=1}^{k} a(\\hat{x}, x\_i)\\, y\_i \\\] When a is a kernel, this sum behaves like a kernel density estimator, and when a is zero for all but the nearest b support points it becomes a nearest-neighbour rule.

Unlike other attentional memories, this form is non-parametric, so the memory it uses grows with the support set.

The attention used in the experiments is a softmax over the cosine similarity between an embedded query f(x) and an embedded support example g(x\_i). The embedding f and g can be deep convolutional networks for images, such as VGG or Inception, or a simple word embedding for language. Because the classifier is trained to make the query align with same-label support examples and misalign with the rest, the authors see it as discriminative, which is close to neighbourhood component analysis and triplet losses.

## Embeddings that see the whole support set

In the basic form, each support element is embedded on its own, so the other support examples cannot change how it is represented. The authors instead let g take the full support set as an extra input, so that g(x\_i, S) can depend on which other elements are present. This matters when one support element lies very close to another, because the embedding of one of them may then need to change.

For g, the authors run a bidirectional LSTM over the support set treated as a sequence. For the query embedding f, an LSTM with read-attention over the embedded support set is unrolled for a fixed number of steps K, and its inputs are the query features held constant at each step. This lets the model ignore some support elements and adds depth to the attention computation, and the authors give the precise definitions in an appendix.

## Training that mirrors test conditions

The authors argue that training and testing conditions must match, so the training tasks should look like the few-shot tasks used later. A task is a distribution over label sets, typically covering a few classes, such as 5, with a few examples per class, such as up to 5. Under this setup, a sampled label set usually contains 5 to 25 examples.

Each training episode first samples a label set L, then draws a support set S and a batch B from it. The network is trained to predict the labels in B given S, which is a form of meta-learning because it learns to learn from a support set. The objective is written as \\\[ \\theta = \\arg\\max\_{\\theta} \\; \\mathbb{E}\_{L\\sim T}\\left\[\\, \\mathbb{E}\_{S\\sim L,\\, B\\sim L}\\Big\[ \\sum\_{(x,y)\\in B} \\log P\_{\\theta}(y \\mid x, S) \\Big\] \\right\] \\\].

It maximises the summed log-likelihood of the batch labels, and the outer expectation is over tasks.

Because the model is non-parametric, it needs no fine-tuning on classes it has never seen. But the authors note that if the test task moves far from the training task distribution, the model will not work well, and they return to this point in the ImageNet experiments.

## Omniglot results

Omniglot has 1623 characters from 50 alphabets, and the authors used 1200 characters for training and the rest for evaluation, with random rotations as augmentation. The embedding is a stack of four modules, each with a 3 by 3 convolution of 64 filters, batch normalisation, a ReLU and 2 by 2 max-pooling, applied to 28 by 28 images. The baselines are raw-pixel matching, a baseline classifier with nearest-neighbour matching, MANN, and a reimplemented convolutional siamese net.

In 20-way one-shot classification, Matching Nets scored 93.8%, compared to 88.0% for the convolutional siamese net. The baseline classifier with cosine matching reached 69.5% in the same setting, so the gain is not explained by the features alone. The model outperforms the baselines across 1-shot and 5-shot, 5-way and 20-way settings, and it gains more in 1-shot than in 5-shot.

The siamese net is competitive with 5 examples per class, but its performance drops quickly in the one-shot case. Fully conditional embeddings did not help much on Omniglot, so the authors left them out of the table. As a transfer check, a model trained on Omniglot was tested on one-shot 10-way MNIST, where it scored 72%, the baseline classifier about 63%, and the siamese net 70% as reported in its original paper.

## ImageNet and miniImageNet results

The rand split removes 118 random labels from training and tests on them, while the dogs split removes all dog classes, 118 in total. The authors also built miniImageNet with 60,000 images of size 84 by 84 across 100 classes, using 80 classes for training and 20 for testing.

On miniImageNet, Matching Nets scored 41.2% in 1-shot with cosine matching and no fine-tuning, compared to 36.6% for the baseline classifier. Full context embeddings added about two percentage points, and with fine-tuning the model reached 46.6% in 1-shot.

For full ImageNet, the authors initialised the feature extractors from an Inception classifier pretrained on the relevant subset, then trained on random 5-way 1-shot tasks. The Inception oracle, trained on all classes, reaches about 99% and serves as an upper bound.

On the complementary subset of dog classes, Matching Nets improve on Inception, although that setup is not one-shot because the features were trained on those labels. On the harder dogs subset, the model is about 1% worse than Inception, which the authors link to training samples drawn uniformly from the whole label tree rather than from fine-grained groups.

## One-shot language modelling on Penn Treebank

The language task gives a query sentence with one missing word, plus a support set of sentences, each with a missing word and a one-hot label. The model picks the label whose support sentence best matches the query, so the choice is 5-way. Sentences come from the Penn Treebank, with batch size 20, support sets of size k = 1, 2, 3, and non-overlapping sentences in set and batch.

The words were split into 9000 sampled for training and 1000 for testing, and the standard test set was used for reporting. Matching Networks with a simple encoding model scored 32.4%, 36.1% and 38.2% for k = 1, 2 and 3, where chance is 20%. The LSTM language model trained on all words reaches 72.8%, but the authors describe it as an upper bound because it sees all data rather than doing one-shot learning.

The support sentences here share only a word with the query and give a generic rather than specific context, which differs from the CBT and CNN tasks. The authors expect that combining parametric language models with non-parametric matching would help, but they did not test this.

## Limitations

They mention sparse and sampling-based methods as possible fixes, but the paper does not test them.

When label distributions are biased, for example fine-grained as in the dogs subtask, the model suffers. The authors suspect that sampling training sets from fine-grained label groups would help, and they leave this as future work.

The experiments cover Omniglot, ImageNet splits, miniImageNet and one Penn Treebank task, and the language comparison uses a simple encoding model. The MNIST transfer result is a single disjoint task, and its siamese figure comes from the original paper.

## Paper info

- **Authors**: Oriol Vinyals, Charles Blundell, Timothy Lillicrap, Koray Kavukcuoglu, Daan Wierstra
- **Venue**: arXiv · Preprint
- **First published**: 2016-6-13
- **Added**: 2026-11-12
- **Updated**: 2017-12-29
- **Version**: v2
- **arXiv**: 1606.04080
- **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/1606.04080v2) · [PDF ↗](https://arxiv.org/pdf/1606.04080v2)

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

Oriol Vinyals, Charles Blundell, Timothy Lillicrap, Koray Kavukcuoglu, Daan Wierstra (2016). Matching Networks for One Shot Learning. arXiv:1606.04080v2. https://arxiv.org/abs/1606.04080v2

**BibTeX**

```
@misc{vinyals2016matching,
  title = {{Matching Networks for One Shot Learning}},
  author = {Oriol Vinyals and Charles Blundell and Timothy Lillicrap and Koray Kavukcuoglu and Daan Wierstra},
  year = {2016},
  eprint = {1606.04080},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1606.04080v2}
}
```

## Other paper commentary

- [LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation](https://refivu.com/en/papers/ce104c95-75b4-4033-900a-57eef9818488-lightgcn-simplifying-and-powering-graph-convolution-network.md)
- [Unsupervised Domain Adaptation by Backpropagation](https://refivu.com/en/papers/5b06ce85-04aa-40bd-a8ba-094e15a092f1-unsupervised-domain-adaptation-by-backpropagation.md)
- [Spatial Transformer Networks](https://refivu.com/en/papers/6eb29eca-41eb-4d69-ace3-032bf11562a8-spatial-transformer-networks.md)
- [LINE: Large-scale Information Network Embedding](https://refivu.com/en/papers/395ad92f-93c2-44fe-8480-bbf8df48c4cf-line-large-scale-information-network-embedding.md)
- [Stacked Hourglass Networks for Human Pose Estimation](https://refivu.com/en/papers/5578e324-2c80-4bb0-90a0-e90427560e5f-stacked-hourglass-networks-for-human-pose-estimation.md)
- [A Survey of Convolutional Neural Networks: Analysis, Applications, and Prospects](https://refivu.com/en/papers/070c8ac2-628a-4354-98cb-c9aeae701850-a-survey-of-convolutional-neural-networks-analysis.md)
- [The Kinetics Human Action Video Dataset](https://refivu.com/en/papers/a2b572fe-2c51-40af-87d9-956918d52119-the-kinetics-human-action-video-dataset.md)
- [Billion-scale similarity search with GPUs](https://refivu.com/en/papers/e02b0778-dbc6-4a4a-9b69-43dee7ffbd0c-billion-scale-similarity-search-with-gpus.md)
- [Qwen3-VL Technical Report](https://refivu.com/en/papers/a9ce03f9-9079-45df-9644-3195f785065b-qwen3-vl-technical-report.md)
- [Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution](https://refivu.com/en/papers/6c3c16f7-9275-4dac-84c5-17175ff5b338-qwen2-vl-enhancing-vision-language-model-s-perception.md)
- [Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena](https://refivu.com/en/papers/beb0d651-5eaa-425c-8bf2-ee14db24b3b0-judging-llm-as-a-judge-with-mt-bench.md)
- [Long-term Recurrent Convolutional Networks for Visual Recognition and Description](https://refivu.com/en/papers/746c9a37-e85c-4acd-aec2-5cfa2639a609-long-term-recurrent-convolutional-networks-for-visual.md)

## Terms in this paper

- [Support set](https://refivu.com/en/terms/6ca07dac69e7-support-set)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/b9fc7556-8641-4de5-90e9-278f5122412f-matching-networks-for-one-shot-learning)
