Matching Networks for One Shot Learning

06/13/2016 ∙ by Oriol Vinyals, et al. ∙ Google 0

Learning from a few examples remains a key challenge in machine learning. Despite recent advances in important domains such as vision and language, the standard supervised deep learning paradigm does not offer a satisfactory solution for learning new concepts rapidly from little data. In this work, we employ ideas from metric learning based on deep neural features and from recent advances that augment neural networks with external memories. Our framework learns a network that maps a small labelled support set and an unlabelled example to its label, obviating the need for fine-tuning to adapt to new class types. We then define one-shot learning problems on vision (using Omniglot, ImageNet) and language tasks. Our algorithm improves one-shot accuracy on ImageNet from 87.6 competing approaches. We also demonstrate the usefulness of the same model on language modeling by introducing a one-shot task on the Penn Treebank.



There are no comments yet.


page 6

Code Repositories


An attempt at replicating the Matching Networks for One Shot Learning in Tensorflow - Paper URL:

view repo


Implementation of "Matching Networks for One Shot Learning" in Keras

view repo
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Humans learn new concepts with very little supervision – e.g. a child can generalize the concept of “giraffe” from a single picture in a book – yet our best deep learning systems need hundreds or thousands of examples. This motivates the setting we are interested in: “one-shot” learning, which consists of learning a class from a single labelled example.

Deep learning has made major advances in areas such as speech hinton2012deep , vision krizhevsky2012imagenet and language mikolov2010recurrent

, but is notorious for requiring large datasets. Data augmentation and regularization techniques alleviate overfitting in low data regimes, but do not solve it. Furthermore, learning is still slow and based on large datasets, requiring many weight updates using stochastic gradient descent. This, in our view, is mostly due to the parametric aspect of the model, in which training examples need to be slowly learnt by the model into its parameters.

In contrast, many non-parametric models allow novel examples to be rapidly assimilated, whilst not suffering from catastrophic forgetting. Some models in this family (e.g., nearest neighbors) do not require any training but performance depends on the chosen metric

lwl . Previous work on metric learning in non-parametric setups nca has been influential on our model, and we aim to incorporate the best characteristics from both parametric and non-parametric models – namely, rapid acquisition of new examples while providing excellent generalisation from common examples.

The novelty of our work is twofold: at the modeling level, and at the training procedure. We propose Matching Nets (MN), a neural network which uses recent advances in attention and memory that enable rapid learning. Secondly, our training procedure is based on a simple machine learning principle: test and train conditions must match. Thus to train our network to do rapid learning, we train it by showing only a few examples per class, switching the task from minibatch to minibatch, much like how it will be tested when presented with a few examples of a new task.

Besides our contributions in defining a model and training criterion amenable for one-shot learning, we contribute by the definition of tasks that can be used to benchmark other approaches on both ImageNet and small scale language modeling. We hope that our results will encourage others to work on this challenging problem.

We organized the paper by first defining and explaining our model whilst linking its several components to related work. Then in the following section we briefly elaborate on some of the related work to the task and our model. In Section 4 we describe both our general setup and the experiments we performed, demonstrating strong results on one-shot learning on a variety of tasks and setups.

2 Model

Our non-parametric approach to solving one-shot learning is based on two components which we describe in the following subsections. First, our model architecture follows recent advances in neural networks augmented with memory (as discussed in Section 3). Given a (small) support set , our model defines a function

(or classifier) for each

, i.e. a mapping . Second, we employ a training strategy which is tailored for one-shot learning from the support set .

2.1 Model Architecture

Figure 1: Matching Networks architecture

In recent years, many groups have investigated ways to augment neural network architectures with external memories and other components that make them more “computer-like”. We draw inspiration from models such as sequence to sequence (seq2seq) with attention montreal , memory networks memnets and pointer networks ptrnets .

In all these models, a neural attention mechanism, often fully differentiable, is defined to access (or read) a memory matrix which stores useful information to solve the task at hand. Typical uses of this include machine translation, speech recognition, or question answering. More generally, these architectures model where and/or can be a sequence (like in seq2seq models), or, more interestingly for us, a set vinyals2015order .

Our contribution is to cast the problem of one-shot learning within the set-to-set framework vinyals2015order . The key point is that when trained, Matching Networks are able to produce sensible test labels for unobserved classes without any changes to the network. More precisely, we wish to map from a (small) support set of examples of image-label pairs to a classifier which, given a test example

, defines a probability distribution over outputs

. We define the mapping to be where is parameterised by a neural network. Thus, when given a new support set of examples from which to one-shot learn, we simply use the parametric neural network defined by to make predictions about the appropriate label for each test example : . In general, our predicted output class for a given input unseen example and a support set becomes .

Our model in its simplest form computes as follows:


where are the samples and labels from the support set , and is an attention mechanism which we discuss below. Note that eq. 1 essentially describes the output for a new class as a linear combination of the labels in the support set. Where the attention mechanism is a kernel on , then (1

) is akin to a kernel density estimator. Where the attention mechanism is zero for the

furthest from according to some distance metric and an appropriate constant otherwise, then (1) is equivalent to ‘’-nearest neighbours (although this requires an extension to the attention mechanism that we describe in Section 2.1.2). Thus (1

) subsumes both KDE and kNN methods. Another view of (

1) is where acts as an attention mechanism and the act as memories bound to the corresponding . In this case we can understand this as a particular kind of associative memory where, given an input, we “point” to the corresponding example in the support set, retrieving its label. However, unlike other attentional memory mechanisms montreal , (1) is non-parametric in nature: as the support set size grows, so does the memory used. Hence the functional form defined by the classifier is very flexible and can adapt easily to any new support set.

2.1.1 The Attention Kernel

Equation 1 relies on choosing

, the attention mechanism, which fully specifies the classifier. The simplest form that this takes (and which has very tight relationships with common attention models and kernel functions) is to use the softmax over the cosine distance

, i.e., with embedding functions and being appropriate neural networks (potentially with ) to embed and . In our experiments we shall see examples where and are parameterised variously as deep convolutional networks for image tasks (as in VGGsimonyan2014very or Inceptionszegedy2015going ) or a simple form word embedding for language tasks (see Section 4).

We note that, though related to metric learning, the classifier defined by Equation 1 is discriminative. For a given support set and sample to classify , it is enough for to be sufficiently aligned with pairs such that and misaligned with the rest. This kind of loss is also related to methods such as Neighborhood Component Analysis (NCA) nca , triplet loss hoffer2015deep or large margin nearest neighbor weinberger2009distance .

However, the objective that we are trying to optimize is precisely aligned with multi-way, one-shot classification, and thus we expect it to perform better than its counterparts. Additionally, the loss is simple and differentiable so that one can find the optimal parameters in an “end-to-end” fashion.

2.1.2 Full Context Embeddings

The main novelty of our model lies in reinterpreting a well studied framework (neural networks with external memories) to do one-shot learning. Closely related to metric learning, the embedding functions and act as a lift to feature space to achieve maximum accuracy through the classification function described in eq. 1.

Despite the fact that the classification strategy is fully conditioned on the whole support set through

, the embeddings on which we apply the cosine similarity to “attend”, “point” or simply compute the nearest neighbor are myopic in the sense that each element

gets embedded by independently of other elements in the support set . Furthermore, should be able to modify how we embed the test image through .

We propose embedding the elements of the set through a function which takes as input the full set in addition to , i.e. becomes . Thus, as a function of the whole support set , can modify how to embed . This could be useful when some element is very close to , in which case it may be beneficial to change the function with which we embed – some evidence of this is discussed in Section 4

. We use a bidirectional Long-Short Term Memory (LSTM)

hochreiter to encode in the context of the support set , considered as a sequence (see appendix for a more precise definition).

The second issue can be fixed via an LSTM with read-attention over the whole set , whose inputs are equal to :

where are the features (e.g., derived from a CNN) which are input to the LSTM (constant at each time step). is the fixed number of unrolling steps of the LSTM, and is the set over which we attend, embedded with . This allows for the model to potentially ignore some elements in the support set , and adds “depth” to the computation of attention (see appendix for more details).

2.2 Training Strategy

In the previous subsection we described Matching Networks which map a support set to a classification function, . We achieve this via a modification of the set-to-set paradigm augmented with attention, with the resulting mapping being of the form , noting that are the parameters of the model (i.e. of the embedding functions and described previously).

The training procedure has to be chosen carefully so as to match inference at test time. Our model has to perform well with support sets which contain classes never seen during training.

More specifically, let us define a task as distribution over possible label sets . Typically we consider to uniformly weight all data sets of up to a few unique classes (e.g., 5), with a few examples per class (e.g., up to 5). In this case, a label set sampled from a task , , will typically have 5 to 25 examples.

To form an “episode” to compute gradients and update our model, we first sample from (e.g., could be the label set ). We then use to sample the support set and a batch (i.e., both and are labelled examples of cats and dogs). The Matching Net is then trained to minimise the error predicting the labels in the batch conditioned on the support set . This is a form of meta-learning since the training procedure explicitly learns to learn from a given support set to minimise a loss over a batch. More precisely, the Matching Nets training objective is as follows:


Training with eq. 2 yields a model which works well when sampling from a different distribution of novel labels. Crucially, our model does not need any fine tuning on the classes it has never seen due to its non-parametric nature. Obviously, as diverges far from the from which we sampled to learn , the model will not work – we belabor this point further in Section 4.1.2.

3 Related Work

3.1 Memory Augmented Neural Networks

A recent surge of models which go beyond “static” classification of fixed vectors onto their classes has reshaped current research and industrial applications alike. This is most notable in the massive adoption of LSTMs

hochreiter in a variety of tasks such as speech hinton2012deep , translation seq2seqilya ; montreal or learning programs ntm ; ptrnets . A key component which allowed for more expressive models was the introduction of “content” based attention in montreal

, and “computer-like” architectures such as the Neural Turing Machine

ntm or Memory Networks memnets . Our work takes the metalearning paradigm of mann , where an LSTM learnt to learn quickly from data presented sequentially, but we treat the data as a set. The one-shot learning task we defined on the Penn Treebank marcus1993building relates to evaluation techniques and models presented in hill2015goldilocks , and we discuss this in Section 4.

3.2 Metric Learning

As discussed in Section 2, there are many links between content based attention, kernel based nearest neighbor and metric learning lwl . The most relevant work is Neighborhood Component Analysis (NCA) nca , and the follow up non-linear version salakhutdinov2007learning . The loss is very similar to ours, except we use the whole support set instead of pair-wise comparisons which is more amenable to one-shot learning. Follow-up work in the form of deep convolutional siamese siamese networks included much more powerful non-linear mappings. Other losses which include the notion of a set (but use less powerful metrics) were proposed in weinberger2009distance .

Lastly, the work in one-shot learning in omniglot was inspirational and also provided us with the invaluable Omniglot dataset – referred to as the “transpose” of MNIST. Other works used zero-shot learning on ImageNet, e.g. norouzi2013zero . However, there is not much one-shot literature on ImageNet, which we hope to amend via our benchmark and task definitions in the following section.

4 Experiments

In this section we describe the results of many experiments, comparing our Matching Networks model against strong baselines. All of our experiments revolve around the same basic task: an -way -shot learning task. Each method is providing with a set of labelled examples from each of classes that have not previously been trained upon. The task is then to classify a disjoint batch of unlabelled examples into one of these classes. Thus random performance on this task stands at . We compared a number of alternative models, as baselines, to Matching Networks.

Let denote the held-out subset of labels which we only use for one-shot. Unless otherwise specified, training is always on , and test in one-shot mode on .

We ran one-shot experiments on three data sets: two image classification sets (Omniglot omniglot and ImageNet (ImageNet, , ILSVRC-2012)) and one language modeling (Penn Treebank). The experiments on the three data sets comprise a diverse set of qualities in terms of complexity, sizes, and modalities.

4.1 Image Classification Results

Model Matching Fn Fine Tune 5-way Acc 20-way Acc
1-shot 5-shot 1-shot 5-shot
Pixels Cosine N 41.7% 63.2% 26.7% 42.6%
Baseline Classifier Cosine N 80.0% 95.0% 69.5% 89.1%
Baseline Classifier Cosine Y 82.3% 98.4% 70.6% 92.0%
Baseline Classifier Softmax Y 86.0% 97.6% 72.9% 92.3%
MANN (No Conv) mann Cosine N 82.8% 94.9%  –  –
Convolutional Siamese Net siamese Cosine N 96.7% 98.4% 88.0% 96.5%
Convolutional Siamese Net siamese Cosine Y 97.3% 98.4% 88.1% 97.0%
Matching Nets (Ours) Cosine N 98.1% 98.9% 93.8% 98.5%
Matching Nets (Ours) Cosine Y 97.9% 98.7% 93.5% 98.7%
Table 1: Results on the Omniglot dataset.

For vision problems, we considered four kinds of baselines: matching on raw pixels, matching on discriminative features from a state-of-the-art classifier (Baseline Classifier), MANN mann , and our reimplementation of the Convolutional Siamese Net siamese . The baseline classifier was trained to classify an image into one of the original classes present in the training data set, but excluding the classes so as not to give it an unfair advantage (i.e., trained to classify classes in

). We then took this network and used the features from the last layer (before the softmax) for nearest neighbour matching, a strategy commonly used in computer vision

donahue2014decaf which has achieved excellent results across many tasks. Following siamese , the convolutional siamese nets were trained on a same-or-different task of the original training data set and then the last layer was used for nearest neighbour matching.

We also tried further fine tuning the features using only the support set sampled from . This yields massive overfitting, but given that our networks are highly regularized, can yield extra gains. Note that, even when fine tuning, the setup is still one-shot, as only a single example per class from is used.

4.1.1 Omniglot

Omniglot omniglot consists of 1623 characters from 50 different alphabets. Each of these was hand drawn by 20 different people. The large number of classes (characters) with relatively few data per class (20), makes this an ideal data set for testing small-scale one-shot classification. The -way Omniglot task setup is as follows: pick unseen character classes, independent of alphabet, as . Provide the model with one drawing of each of the characters as and a batch . Following mann , we augmented the data set with random rotations by multiples of 90 degrees and used 1200 characters for training, and the remaining character classes for evaluation.

We used a simple yet powerful CNN as the embedding function – consisting of a stack of modules, each of which is a

convolution with 64 filters followed by batch normalization


, a Relu non-linearity and

max-pooling. We resized all the images to so that, when we stack 4 modules, the resulting feature map is , resulting in our embedding function . A fully connected layer followed by a softmax non-linearity is used to define the Baseline Classifier.

Results comparing the baselines to our model on Omniglot are shown in Table 1. For both -shot and -shot, -way and -way, our model outperforms the baselines. There are no major surprises in these results: using more examples for k-shot classification helps all models, and 5-way is easier than 20-way. We note that the Baseline Classifier improves a bit when fine tuning on , and using cosine distance versus training a small softmax from the small training set (thus requiring fine tuning) also performs well. Siamese nets fare well versus our Matching Nets when using 5 examples per class, but their performance degrades rapidly in one-shot. Fully Conditional Embeddings (FCE) did not seem to help much and were left out of the table due to space constraints.

Like the authors in siamese , we also test our method trained on Omniglot on a completely disjoint task – one-shot, 10 way MNIST classification. The Baseline Classifier does about 63% accuracy whereas (as reported in their paper) the Siamese Nets do 70%. Our model achieves 72%.

4.1.2 ImageNet

Our experiments followed the same setup as Omniglot for testing, but we considered a rand and a dogs (harder) setup. In the rand setup, we removed 118 labels at random from the training set, then tested only on these 118 classes (which we denote as ). For the dogs setup, we removed all classes in ImageNet descended from dogs (totalling 118) and trained on all non-dog classes, then tested on dog classes (). ImageNet is a notoriously large data set which can be quite a feat of engineering and infrastructure to run experiments upon it, requiring many resources. Thus, as well as using the full ImageNet data set, we devised a new data set – miniImageNet – consisting of colour images of size with classes, each having examples. This dataset is more complex than CIFAR10 krizhevsky2010convolutional , but fits in memory on modern machines, making it very convenient for rapid prototyping and experimentation. This dataset is fully described in Appendix B. We used classes for training and tested on the remaining classes. In total, thus, we have randImageNet, dogsImageNet, and miniImageNet.

The results of the miniImageNet experiments are shown in Table 2. As with Omniglot, Matching Networks outperform the baselines. However, miniImageNet is a much harder task than Omniglot which allowed us to evaluate Full Contextual Embeddings (FCE) sensibly (on Omniglot it made no difference). As we an see, FCE improves the performance of Matching Networks, with and without fine tuning, typically improving performance by around two percentage points.

Figure 2: Example of two 5-way problem instance on ImageNet. The images in the set contain classes never seen during training. Our model makes far less mistakes than the Inception baseline.
Model Matching Fn Fine Tune 5-way Acc
1-shot 5-shot
Pixels Cosine N 23.0% 26.6%
Baseline Classifier Cosine N 36.6% 46.0%
Baseline Classifier Cosine Y 36.2% 52.2%
Baseline Classifier Softmax Y 38.4% 51.2%
Matching Nets (Ours) Cosine N 41.2% 56.2%
Matching Nets (Ours) Cosine Y 42.4% 58.0%
Matching Nets (Ours) Cosine (FCE) N 44.2% 57.0%
Matching Nets (Ours) Cosine (FCE) Y 46.6% 60.0%
Table 2: Results on miniImageNet.

Next we turned to experiments based upon full size, full scale ImageNet. Our baseline classifier for this data set was Inception szegedy2015rethinking trained to classify on all classes except those in the test set of classes (for randImageNet) or those concerning dogs (for dogsImageNet). We also compared to features from an Inception Oracle classifier trained on all classes in ImageNet, as an upper bound. Our Baseline Classifier is one of the strongest published ImageNet models at 79% top-1 accuracy on the standard ImageNet validation set. Instead of training Matching Networks from scratch on these large tasks, we initialised their feature extractors and with the parameters from the Inception classifier (pretrained on the appropriate subset of the data) and then further trained the resulting network on random -way -shot tasks from the training data set, incorporating Full Context Embeddings and our Matching Networks and training strategy.

The results of the randImageNet and dogsImageNet experiments are shown in Table 3. The Inception Oracle (trained on all classes) performs almost perfectly when restricted to 5 classes only, which is not too surprising given its impressive top-1 accuracy. When trained solely on , Matching Nets improve upon Inception by almost when tested on , halving the errors. Figure 2

shows two instances of 5-way one-shot learning, where Inception fails. Looking at all the errors, Inception appears to sometimes prefer an image above all others (these images tend to be cluttered like the example in the second column, or more constant in color). Matching Nets, on the other hand, manage to recover from these outliers that sometimes appear in the support set


Matching Nets manage to improve upon Inception on the complementary subset

(although this setup is not one-shot, as the feature extraction has been trained on these labels). However, on the much more challenging

subset, our model degrades by . We hypothesize this to the fact that the sampled set during training, , comes from a random distribution of labels (from ), whereas the testing support set from contains similar classes, more akin to fine grained classification. Thus, we believe that if we adapted our training strategy to samples from fine grained sets of labels instead of sampling uniformly from the leafs of the ImageNet class tree, improvements could be attained. We leave this as future work.

Model Matching Fn Fine Tune ImageNet 5-way 1-shot Acc
Pixels Cosine N 42.0% 42.8% 41.4% 43.0%
Inception Classifier Cosine N 87.6% 92.6% 59.8% 90.0%
Matching Nets (Ours) Cosine (FCE) N 93.2% 97.0% 58.8% 96.4%
Inception Oracle Softmax (Full) Y (Full)
Table 3: Results on full ImageNet on rand and dogs one-shot tasks. Note that and are sets of classes which are seen during training, but are provided for completeness.

4.1.3 One-Shot Language Modeling

We also introduce a new one-shot language task which is analogous to those examined for images. The task is as follows: given a query sentence with a missing word in it, and a support set of sentences which each have a missing word and a corresponding 1-hot label, choose the label from the support set that best matches the query sentence. Here we show a single example, though note that the words on the right are not provided and the labels for the set are given as 1-hot-of-5 vectors.

1. an experimental vaccine can alter the immune response of people infected with the aids virus a <blank_token> u.s. scientist said. prominent
2. the show one of five new nbc <blank_token> is the second casualty of the three networks so far this fall. series
3. however since eastern first filed for chapter N protection march N it has consistently promised to pay creditors N cents on the <blank_token>. dollar
4. we had a lot of people who threw in the <blank_token> today said <unk> ellis a partner in benjamin jacobson & sons a specialist in trading ual stock on the big board. towel
5. it’s not easy to roll out something that <blank_token> and make it pay mr. jacob says. comprehensive
Query: in late new york trading yesterday the <blank_token> was quoted at N marks down from N marks late friday and at N yen down from N yen late friday. dollar

Sentences were taken from the Penn Treebank dataset marcus1993building . On each trial, we make sure that the set and batch are populated with sentences that are non-overlapping. This means that we do not use words with very low frequency counts; e.g. if there is only a single sentence for a given word we do not use this data since the sentence would need to be in both the set and the batch. As with the image tasks, each trial consisted of a 5 way choice between the classes available in the set. We used a batch size of 20 throughout the sentence matching task and varied the set size across k=1,2,3. We ensured that the same number of sentences were available for each class in the set. We split the words into a randomly sampled 9000 for training and 1000 for testing, and we used the standard test set to report results. Thus, neither the words nor the sentences used during test time had been seen during training.

We compared our one-shot matching model to an oracle LSTM language model (LSTM-LM) zaremba2014recurrent trained on all the words. In this setup, the LSTM has an unfair advantage as it is not doing one-shot learning but seeing all the data – thus, this should be taken as an upper bound. To do so, we examined a similar setup wherein a sentence was presented to the model with a single word filled in with 5 different possible words (including the correct answer). For each of these 5 sentences the model gave a log-likelihood and the max of these was taken to be the choice of the model.

As with the other 5 way choice tasks, chance performance on this task was 20%. The LSTM language model oracle achieved an upper bound of 72.8% accuracy on the test set. Matching Networks with a simple encoding model achieve 32.4%, 36.1%, 38.2% accuracy on the task with examples in the set, respectively. Future work should explore combining parametric models such as an LSTM-LM with non-parametric components such as the Matching Networks explored here.

Two related tasks are the CNN QA test of entity prediction from news articles hermann2015teaching , and the Children’s Book Test (CBT) hill2015goldilocks . In the CBT for example, a sequence of sentences from a book are provided as context. In the final sentence one of the words, which has appeared in a previous sentence, is missing. The task is to choose the correct word to fill in this blank from a small set of words given as possible answers, all of which occur in the preceding sentences. In our sentence matching task the sentences provided in the set are randomly drawn from the PTB corpus and are related to the sentences in the query batch only by the fact that they share a word. In contrast to CBT and CNN dataset, they provide only a generic rather than specific sequential context.

5 Conclusion

In this paper we introduced Matching Networks, a new neural architecture that, by way of its corresponding training regime, is capable of state-of-the-art performance on a variety of one-shot classification tasks. There are a few key insights in this work. Firstly, one-shot learning is much easier if you train the network to do one-shot learning. Secondly, non-parametric structures in a neural network make it easier for networks to remember and adapt to new training sets in the same tasks. Combining these observations together yields Matching Networks. Further, we have defined new one-shot tasks on ImageNet, a reduced version of ImageNet (for rapid experimentation), and a language modeling task. An obvious drawback of our model is the fact that, as the support set grows in size, the computation for each gradient update becomes more expensive. Although there are sparse and sampling-based methods to alleviate this, much of our future efforts will concentrate around this limitation. Further, as exemplified in the ImageNet dogs subtask, when the label distribution has obvious biases (such as being fine grained), our model suffers. We feel this is an area with exciting challenges which we hope to keep improving in future work.


We would like to thank Nal Kalchbrenner for brainstorming around the design of the function , and Sander Dieleman and Sergio Guadarrama for their help setting up ImageNet. We would also like thank Simon Osindero for useful discussions around the tasks discussed in this paper, and Theophane Weber and Remi Munos for following some early developments. Karen Simonyan and David Silver helped with the manuscript, as well as many at Google DeepMind. Thanks also to Geoff Hinton and Alex Toshev for discussions about our results.

plus 1pt



Appendix A Model Description

In this section we fully specify the models which condition the embedding functions and on the whole support set . Much previous work has fully described similar mechanisms, which is why we left the precise details for this appendix.

a.1 The Fully Conditional Embedding

As described in section 2.1.2, the embedding function for an example in the batch is as follows:

where is a neural network (e.g., VGG or Inception, as described in the main text). We define to be the number of “processing” steps following work from vinyals2015order from their “Process” block. represents the embedding function applied to each element from the set .

Thus, the state after processing steps is as follows:


noting that follows the same LSTM implementation defined in seq2seqilya with the input, the output (i.e., cell after the output gate), and the cell. is commonly referred to as “content” based attention, and the softmax in eq. 6 normalizes w.r.t. . The read-out from is concatenated to . Since we do steps of “reads”, where is as described in eq. 3.

a.2 The Fully Conditional Embedding

In section 2.1.2 we described the encoding function for the elements in the support set , , as a bidirectional LSTM. More precisely, let be a neural network (similar to above, e.g. a VGG or Inception model). Then we define with:

where, as in above, follows the same LSTM implementation defined in seq2seqilya with the input, the output (i.e., cell after the output gate), and the cell. Note that the recursion for starts from . As in eq. 4, we add a skip connection between input and outputs.

Appendix B miniImageNet Description

To construct miniImageNet we chose 100 random classes from ImageNet, and used the first 80 for training, and the last 20 for testing. This split was used in our one-shot experiments described in section 4.1.2. Note that the last 20 class objects were never seen during training. For the exact 600 images that comprise each of the 100 classes in miniImageNet, please see the following text file:

n01614925, n01632777, n01641577, n01664065, n01687978, n01695060, n01729322, n01773157, n01833805, n01871265, n01877812, n01978455, n01986214, n02013706, n02066245, n02071294, n02088466, n02090379, n02091635, n02096437, n02097130, n02099429, n02108089, n02108915, n02109047, n02109525, n02111889, n02115641, n02123045, n02129165, n02167151, n02206856, n02264363, n02279972, n02342885, n02346627, n02364673, n02454379, n02481823, n02486261, n02494079, n02655020, n02793495, n02804414, n02808304, n02837789, n02895154, n02909870, n02917067, n02966687, n03000684, n03014705, n03041632, n03045698, n03065424, n03180011, n03216828, n03355925, n03384352, n03424325, n03452741, n03482405, n03494278, n03594734, n03599486, n03630383, n03649909, n03676483, n03690938, n03742115, n03868242, n03877472, n03976467, n03976657, n03998194, n04026417, n04069434, n04111531, n04118538, n04200800

n04201297, n04204347, n04239074, n04277352, n04370456, n04409515, n04456115, n04479046, n04487394, n04525038, n04591713, n04599235, n07565083, n07613480, n07695742, n07714571, n07717410, n07753275, n10148035, n12768682

Appendix C ImageNet Class Splits

Here we define the two class splits used in our full ImageNet experiments – these classes were excluded for training during our one-shot experiments described in section 4.1.2.

n01498041, n01537544, n01580077, n01592084, n01632777, n01644373, n01665541, n01675722, n01688243, n01729977, n01775062, n01818515, n01843383, n01883070, n01950731, n02002724, n02013706, n02092339, n02093256, n02095314, n02097130, n02097298, n02098413, n02101388, n02106382, n02108089, n02110063, n02111129, n02111500, n02112350, n02115913, n02117135, n02120505, n02123045, n02125311, n02134084, n02167151, n02190166, n02206856, n02231487, n02256656, n02398521, n02480855, n02481823, n02490219, n02607072, n02666196, n02672831, n02704792, n02708093, n02814533, n02817516, n02840245, n02843684, n02870880, n02877765, n02966193, n03016953, n03017168, n03026506, n03047690, n03095699, n03134739, n03179701, n03255030, n03388183, n03394916, n03424325, n03467068, n03476684, n03483316, n03627232, n03658185, n03710193, n03721384, n03733131, n03785016, n03786901, n03792972, n03794056, n03832673, n03843555, n03877472, n03899768, n03930313, n03935335, n03954731, n03995372, n04004767, n04037443, n04065272, n04069434, n04090263, n04118538, n04120489, n04141975, n04152593, n04154565, n04204347, n04208210, n04209133, n04258138, n04311004, n04326547, n04367480, n04447861, n04483307, n04522168, n04548280, n04554684, n04597913, n04612504, n07695742, n07697313, n07697537, n07716906, n12998815, n13133613

n02085620, n02085782, n02085936, n02086079, n02086240, n02086646, n02086910, n02087046, n02087394, n02088094, n02088238, n02088364, n02088466, n02088632, n02089078, n02089867, n02089973, n02090379, n02090622, n02090721, n02091032, n02091134, n02091244, n02091467, n02091635, n02091831, n02092002, n02092339, n02093256, n02093428, n02093647, n02093754, n02093859, n02093991, n02094114, n02094258, n02094433, n02095314, n02095570, n02095889, n02096051, n02096177, n02096294, n02096437, n02096585, n02097047, n02097130, n02097209, n02097298, n02097474, n02097658, n02098105, n02098286, n02098413, n02099267, n02099429, n02099601, n02099712, n02099849, n02100236, n02100583, n02100735, n02100877, n02101006, n02101388, n02101556, n02102040, n02102177, n02102318, n02102480, n02102973, n02104029, n02104365, n02105056, n02105162, n02105251, n02105412, n02105505, n02105641, n02105855, n02106030, n02106166, n02106382, n02106550, n02106662, n02107142, n02107312, n02107574, n02107683, n02107908, n02108000, n02108089, n02108422, n02108551, n02108915, n02109047, n02109525, n02109961, n02110063, n02110185, n02110341, n02110627, n02110806, n02110958, n02111129, n02111277, n02111500, n02111889, n02112018, n02112137, n02112350, n02112706, n02113023, n02113186, n02113624, n02113712, n02113799, n02113978

Appendix D PTB Class Splits

Here we define the two class splits used in our PTB experiments – these classes were excluded for training during our one-shot language experiments described in section 4.1.3.

’s, 12-year, 190.58-point, 1930s, 26-week, a.c., abortion, absorbed, accelerating, acceptable, accords, accusations, achieve, acquires, actively, adapted, addition, adequate, admitting, adopt, adopted, adopting, advised, advisers, advises, advising, aer, affidavits, afternoon, ag, aged, ages, agreements, airport, akzo, alaska, alcohol, alert, alliance, allied-signal, ally, altman, ambrosiano, american, amgen, amount, amounts, an, andy, angry, animals, annuities, antitrust, anybody, anyway, appointed, approaching, approvals, arabs, arafat, arbitration, argentina, arranged, arrest, artists, assembled, associations, assume, assumptions, atoms, attitudes, audio, authorities, authority, away, balls, bally, banknote, banks, banning, barely, barred, barriers, bass, battery, baum, bears, bell, belt, best, best-known, billion, binge, blamed, blanket, bloc, block, blocking, boat, bodies, boesel, bolstered, bonuses, boston, bowed, boys, bozell, bradstreet, brains, breakers, breaks, briefly, brink, brisk, broad-based, broken, bronx, brother, bsn, built, buried, burmah, burned, bursts, bush, businessland, businessman, buys, calculate, calculated, caltrans, campbell, candlestick, capitalism, captured, careers, carpeting, carried, carry-forward, casting, castle, catholic, caught, ceiling, cells, centuries, chair, chairs, challenged, chances, chandler, characters, charts, cheating, checks, cherry, chiron, cie, cie., cincinnati, circuit, civic, clara, classroom, clean-air, climate, closer, cms, cnw, coast, coats, cocom, cold, collected, comes, commercial, commerzbank, commissioned, committed, commute, complains, completing, computer, confirm, confiscated, confronted, conn, conn., consisting, consortium, constitute, consultant, consumer, consumers, contemporary, contra, contraceptive, contributing, convinced, cost-cutting, count, counterparts, counties, courses, cover, cracks, craft, crane, create, creating, crossing, crumbling, crusade, crusaders, cubic, curtail, curve, cushion, cut, cynthia, dairy, dam, david, davis, day, deal, dealerships, debentures, debut, deceptive, decided, decision, decisions, deck, defended, defenders, defenses, definitely, delivering, della, demonstrated, department, departure, depress, designated, desk, desktop, detailing, devaluation, develops, devoe, di, dialogue, dictator, die, diesel, differ, digs, diluted, diminished, direct-mail, disappointing, discount, discrepancies, discuss, disease, disney, disruption, distributed, distributor, dive, diversified, divided, dividends, dodge, doing, domestic, dominant, domination, double-a, downgraded, downgrading, downtown, drives, drought, drunk, dunkin, earn, earthquakes, edisto, editions, educate, eggs, elaborate, elite, embarrassing, emerges, emerging, emigration, employers, empty, enactment, encourages, endorsement, enemies, engelken, enhanced, entertaining, enthusiastic, epicenter, equipped, era, erosion, esselte, est, ethical, ethiopia, eurodollar, events, everyone, exchanges, exciting, exclusively, executed, executing, executive, executives, exempt, expertise, explicit, explosion, expressed, expression, extending, extraordinary, faculty, failed, failure, fallout, faltered, fanfare, fare, farm, fast-growing, fasteners, fastest, fax, fazio, february, federated, fee, field, fifth, fighting, filipino, film, final, financiers, finished, finland, firmed, fiscal, fits, fitzwater, five-cent, fixed-income, fla, flamboyant, fleets, fleming, fletcher, flight, flights, flowers, focus, folk, following, foot, forecasting, found, fox, fray, freeway, freeways, freeze, frequency, freshman, fromstein, frustrating, fur, galileo, game, gandhi, garbage, gathered, gave, gear, gene, generale, genuine, gerard, giant, girl, gloomy, goes, golden, goodman, gov., governing, government-owned, governor, grave, greenhouse, gridlock, grim, guerrilla, guild, gun, h&r, half-hour, handicapped, handy, hanging, happening, happy, harold, haunts, headed, heating, heavier, heavily, hedges, heights, heller, helping, helps, hepatitis, hess, high-definition, high-technology, hiring, hoffman, hold, hole, homeless, honduras, hooker, horizon, hot-dipped, houses, how, hubbard, hurricane, hydro-quebec, hyman, idaho, ill, illness, illustrated, immune, impeachment, implicit, impose, impression, impressive, increase, incredible, incurred, indexing, indiana, indicates, indications, influences, influx, inherent, inquiry, intensive, intentions, internationally, involves, irish, ironically, isler, itel, itt, j., jackson, jaguar, jazz, jefferson, jittery, jolted, july, jump, jury, justifies, karen, kean, keating, kent, kgb, khan, killing, knocked, knocking, koch, l.j., labs, lasts, lately, latest, lawrence, league, lean, least, leave, legitimacy, lehman, leisure, lend, leo, life, lighter, lights, linda, line, literature, live, living, longstanding, looking, looks, loral, lord, lose, lotus, louisville, lower, ltd., luis, lumpur, made, madrid, malcolm, male, manage, management, manic, manville, marcos, marked, market-makers, market-share, markets, mary, mass-market, mayor, mccormick, mcdonald, md., measured, member, members, memorandum, merabank, mercury, merely, merged, mergers, message, mich., mile, millions, mining, ministers, ministry, minorities, minutes, missile, mission, mitterrand, modified, monitor, months, moody, moore, mothers, motorola, movie, mr., much, multibillion-dollar, multiples, mundane, municipalities, muscle, mutual, mutual-fund, named, names, namibia, nashua, nathan, ncr, near-term, nec, necessary, necessity, negligence, negotiating, negotiation, nervousness, newcomers, newspaper, nice, noise, northrop, norton, nose, nothing, noticed, notification, notified, notwithstanding, november, nurses, nutritional, observed, oddly, off, offerings, official, oh, oklahoma, oldest, olympic, ones, opening, opera, optical, optimistic, or, original, orthodox, ortiz, ousted, outfit, outlook, outside, oversees, owen, oy, pachinko, packaged, painted, park, parker, part, particular, partly, patrick, patterson, payable, pc, peace, peaked, peddling, pegged, pepsico, perception, perfect, perfectly, pfizer, pharmaceutical, phelan, philippine, philippines, phony, photographic, physicians, picking, pigs, pittsburgh, place, plagued, plan, planes, planet, pleasure, poles, pool, portable, portfolio, ports, post-crash, pound, poured, poverty, precedent, preclude, pregnant, prescribed, presents, pretty, priced, privileges, procurement, products, profit-taking, projections, prominent, promise, promotional, prompted, proper, proponents, propose, prosecuted, protein, prototype, prove, proved, published, publisher, pull, pulled, pumped, pumping, pushing, quebec, quickview, quist, quite, radical, radio, rain, ranging, rank, rebates, rebel, rebound, rebuild, recent, recital, recognizes, recognizing, recorded, recorders, reduce, reduced, refinery, refrigerators, registered, regret, reinvest, rejected, rejecting, rejection, relations, relatively, relying, remark, remics, reorganization, repaired, repeatedly, reports, represent, repurchase, resembles, reserved, resisted, resolved, resort, rest, restraints, restrictions, restructured, restructuring, result, rican, right, ring, rise, robbed, robinson, robots, robust, roh, role, rolled, rose, rothschild, rough, royal, ruled, rushing, s.c, sale, salesmen, salespeople, salmonella, salvage, saul, says, scheduled, school, schwarz, seagram, second, sector, securities, seek, segment, seismic, seldom, selected, semel, sending, sentences, sentencing, session, settlement, seventh, shed, shell, sheraton, shifting, shocks, short, showed, shy, sigh, sights, signals, sir, site, sites, sitting, skinner, slashed, snapped, so-called, soldiers, solely, solo, somehow, sotheby, speak, specialist, specialize, specializing, specifically, specifications, speculate, speculated, spencer, sperry, spreading, spur, stake, standardized, standing, statistics, steady, stemmed, stern, stevens, stock-index, stockholm, straight, strategists, stream, strength, stress-related, strict, subscriber, suggestions, surplus, surprise, surprises, surrounding, syrian, taiwanese, tall, tap, tapped, task, taxation, taxed, tci, technicians, televised, temptation, testing, texans, theatre, third, this, thomas, those, thoughts, thriving, tickets, ties, tiger, tighter, tire, tisch, together, toronto-based, toshiba, towers, toxin, traditional, trains, transit, trap, treated, trecker, tribune, trigger, triggering, trillion, tube, tune, turn, turnaround, typically, u.k., u.n., uncertain, underlying, underwear, underwrite, underwriter, underwriting, undo, unfortunately, unidentified, unilab, unisys, unit, unknown, unlawful, unless, unused, upheld, upon, upside, urge, usia, uv-b, valid, van, vendors, very, victim, vienna, violations, virginia, vision, visit, voluntary, w., wade, wait, wanting, ward, warner, wars, wary, wash., wealthy, wednesday, when-issued, whether, white-collar, wholly, widening, will, willingness, wilmington, win, winnebago, winners, wish, wolf, words, work, working, worse, would, yard, yards, yearly, yielding, youth, z, zones