{'fraction_non_alphanumeric': 0.026351049575703438, 'fraction_numerical': 0.009704007470867677, 'mean_word_length': 4.81582054309327, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Generative Adversarial Residual Pairwise Networks for One Shot Learning

Deep neural networks achieve unprecedented performance levels over many tasks and scale well with large quantities of data, but performance in the low-data regime and tasks like one shot learning still lags behind. While recent work suggests many hypotheses from better optimization to more complicated network structures, in this work we hypothesize that having a learnable and more expressive similarity objective is an essential missing component. Towards overcoming that, we propose a network design inspired by deep residual networks that allows the efficient computation of this more expressive pairwise similarity objective. Further, we argue that regularization is key in learning with small amounts of data, and propose an additional generator network based on the Generative Adversarial Networks where the discriminator is our residual pairwise network. This provides a strong regularizer by leveraging the generated data samples. The proposed model can generate plausible variations of exemplars over unseen classes and outperforms strong discriminative baselines for few shot classification tasks. Notably, our residual pairwise network design outperforms previous state-of-theart on the challenging mini-Imagenet dataset for one shot learning by getting over 55% accuracy for the 5-way classification task over unseen classes.


Introduction
Human intelligence is considered the epitome towards which man-made intelligent systems strive. Two specific abilities that set the human mind apart are its ability to generalize to related but unseen data and its ability to learn from small quantities of data. As machine learning methods have seen tremendous progress in recent years there has been growing focus on measuring the ability of models to generalize to unseen varieties of data and to learn from even very little of it. This is the aim of the one-shot learning problem [20]. Specifically, given a dataset some of whose classes are not used for training, the model is tested for its ability to classify over those unseen classes using a single example for each class. Essentially, the model must learn features that generalize across classes. The one shot learning problem has been studied under various domains like Bayesian learning [6] [26] and deep representation learning using distance metrics [18]. Deep networks till recently were felt unsuited for such a problem given the huge number of parameters involved and the possibility of overfitting on a problem with very little data. However recent work [34] [23] has shown that deep models, especially recurrent architectures, can perform very well on the one-shot task.
The focus of our work, however is on two aspects which we believe are essential for a model to do well on the task of one shot learning -inferring an accurate semantic representation in a low dimensional manifold and strong regularization. Convolutional Neural Nets are very effective at both, as is shown by their success on many image classification tasks. We additionally enforce the first criteria by presenting a hypothesis that learning an end-to-end trainable distance measure is better than a fixed distance metric (see figure 1). We do this by implementing a modification of the residual network architecture [12]. Specifically our modification involves using skip residual connections and we refer to the our model as Skip Residual Siamese Network (SRPN). The model takes a pair of images and outputs a single similarity embedding vector. We train this model end-to-end for the similarity matching objective and then use it for few shot classification tasks on the Omniglot and mini-Imagenet datasets.
We propose a solution to the second problem in the form of a novel architecture derived from the Generative Adversarial Networks (GAN) [9]. The field of generative modelling has seen rapid advancement in the past few years. This can majorly be attributed to the development of various frameworks that work well in tandem with deep neural networks. Models have been developed that are able to efficiently approximate data distributions well enough to be of practical utility. An interesting subclass of such models is that of the implicit variety [22] which do not prescribe a fixed parametric form for the learned distribution. These Figure 1. Two approaches to obtain the similarity embedding. In the first case f can be a neural network and g is a simple function like L1 or cosine distance. In the second case g is also parameterized by the neural network and hence is adaptive to minimize the training objective with end-to-end optimization. models are consequently trained using methods of comparison instead of maximizing a fixed log-likelihood function. The de facto framework for implicit models is Generative Adversarial Networks (GANs), which has been successfully used for many learning tasks. While this framework has received great interest, work towards understanding its generalization in the low-data regime and its applicability for tasks such as one shot learning has been limited. Our work attempts to bridge that gap and show that GANs provide effective regularization on unseen data distributions. Specifically, we extend the framework by trying to generate a conditional distribution which can regularize a siamese matching network. The siamese network is itself modified to incorporate a feedback that trains the generator along with the task of similarity matching. Thus, our model can be considered an instance of multi-task learning [2]. We show that the generated data is a strong regularizer for the similaritymatching task and helps in generalization to unseen classes.

Related Work
Our work is closely related to that on similarity matching using Siamese Networks [1], which was extended for convolutional networks for face verification in [3]. Koch et. al [18] show results using convolutional variants of these networks on the few shot classification tasks for Omniglot. Various formulations for the similarity objective such as contrastive loss [10] and triplet loss [35] and efficient methods to do the same [28] are also closely related.
Other related approaches include those based on Deep Metric Learning such as deep embeddings for triplet loss [13] and better metrics for fine-grained similarity [24], and popular methods like Neighbourhood Component Analysis [15].
The few shot problem specifically has been studied from multiple perspectives, including the similarity-matching [18], optimization [23], metric learning [34], hierarchical graphical models [26] etc. Our work falls in the similaritymatching paradigm ie. the model learns to classify by individually comparing and contrasting the similarities of the given class data with the test example at hand. To the best of our knowledge, the earliest work on this problem is using Bayesian methods [6] [7]. Salakhutdinov et. al [26] proposed an elegant approach using hierarchical bayesian models. Lake et. al [19] [20] develop the framework of Bayesian Program Learning that naturally inculcates predicting by learning from small amounts of data. They also developed the Omniglot dataset used in our experiments. Recent work includes methods that try to use deep networks for learning embeddings which are the fed to recurrent networks for calculating embeddings [34]. Vinyals et. al [34] also propose an approach for learning the similarity embedding based on the full context of the input set as opposed to pairwise comparisons used in typical similarity matching settings, including this work. They also modify the training procedure to be similar to the testing protocol for few shot learning. Another recent work [30] also explicitly optimizes the one shot learning objective by essentially training the model for multiclass classification in the one shot setting. In contrast, this work aims to show that deep residual networks are naturally well suited to generalization objectives and even the proper pairwise similarity matching objective can perform the one shot task well. The recent work in [29] proposes a recurrent model that also outputs a pairwise embedding, however their reasoning is towards using attention to selectively infer the next step whereas we are focused on a natural, scalable extension to the CNN for one-shot learning.
Another related area is that of deep generative models for one-shot learning. Edwards et. al [5] propose handling the one shot classification task by learning dataset statistics using the amortized inference of a variational auto-encoder. Another popular framework of Generative Modeling -GANs [9] and their conditional [21] [8] alternatives are the essential components of our Generative Regularizer. Our design of using the generator with a discriminator is inspired by the ImprovedGAN model [27] for semi-supervised learning. Another work which uses generated images for improving one shot learning is [11], although they train their model as a transformer for test time generations using cosine similarity in the training set to generate analogies instead of an adversarial loss.

Contributions
To summarize, our work proposes a model for similarity matching with two suggested improvements for similarity measures and . The specific contributions are: • We propose using a trainable distance measure for the task of one shot learning, and our implementation based on the modification of the residual network achieves state-of-the-art on the challenging mini-Imagenet dataset • We show that generated data acts as a strong regularizer for the task of similarity matching and design a novel network based on the GAN framework that shows improvements for the one shot learning task 2. Preliminaries

Few Shot Learning
The objective of few shot learning is to measure the ability of a model to learn generalizable features across classes unseen during training. Specifically, the model is trained on labelled training data (x, y) where each example comes from a subset of the total classes C train ⊂ C. Then during the testing phase, the model is provided with a single example from each of the chosen classes in C test ⊂ C − C train from the disjoint testing set. Using these examples only as the support set S, the model must correctly classify another sample chosen from C test . The number of classes in C test (generally 5 or 20) and the number of examples (generally 1 or 5) characterize the problem.

Generative Adversarial Networks
Generative Adversarial Networks (GANs) propose a method for learning a continuous-valued generative model without a fixed parametric form for the output. This is done by establishing a generator function that maps from latent to data space and a discriminator function that maps from the data space to a scalar. The discriminator function D tries to predict the probability of the input being from p data , and the generator is trained to maximize the error of the discriminator on G(z). Both the generator and the discriminator are parametrized as deep neural networks. The value function of this min-max formulation can be written as follows: 3. Models

Skip Residual Pairwise Network
Siamese networks in literature have been typically referred to models that have two identical feed-forward paths to generate embeddings for two data-points and the similarity is then computed as a function g of these two embeddings. While this is a successful paradigm, one can argue that the choice of g is arbitrary and the model is forced to learn an embedding that works well with a particular choice of g. Such a choice may often be sub-optimal, such as when the embedding itself is an intermediate step in a solving a problem such as similarity matching for one-shot learning. To circumvent this we propose a pairwise network which is takes as input a pair of data points and is trained end-to-end to optimize a particular objective -in our case the similarity between two data points. Note that this leads to the loss of symmetric property necessary for metrics. Our network design is presented in figure 2. The initial part of the network focusing on most abstract features is similar to an ordinary residual network. Then, the intermediate embeddings are split for the input pair and are fed through different pathways alternating between a residual skip connection using 1×1 convolutions and two 3×3 convolutions with Batch Normalization [14] and a non-linearity. The network is designed thus to ensure 2 objectives: The final output of our model is then a single embedding which is fed into a linear classifier to predict the similarity. The whole network is trained end-to-end using the binary cross-entropy loss similar to a normal siamese network.
Multiplicative Units: Multiplicative gating units have been shown to be effective in learning with deep models [31]. Multiplicative interactions could improve performance in our case by allowing better mixing of information from the two sources. We followed the formulation used in [16] to replace the second rectified linear unit activation in our block with a three-gated multiplicative unit. However, we found it did have any significant positive effect on the mini-Imagenet experiments while increasing the number of parameters substantially, thus we refrain from using it in our final model.

Generative Regularizer
We adapt the Generative Adversarial Network to create the second model whose purpose is to provide better regularization for the similarity matching task. The proposed model consists of two networks -a similarity matching discriminator network D φ (.) and a generator network G θ (.) where φ, θ are the parameters of the networks. The objective of the discriminator network is to predict whether an input data point x belongs to the same class-conditional distribution as another data point x t . The discriminator is simultaneously trained to classify the generated images as fake. The generator is trained with the objective of being able to generate plausible variations of a given image -ie. images that belong to the same class conditional distribution as the input image x t . The structure of our model is depicted in figure 3. The mathematical formulation of the two networks is described below.
Discriminator Network: The discriminator network D φ (x, x t ) tries to predict the probability whether the input data point x belongs to the same class-conditional distribution as x t , ie. x ∼ p data (x|class(x t )) where class(x t ) is the class of the data point x t . Thus, the network tries to maximize the probability for x ∼ p data (x|class(x t )) and minimize it for x ∼ p data (x|class = class(x t )) and x ∼ p gen (x|G(x t )). We avoid using explicit label vectors for class(x t ) chiefly because of 2 reasons: i) we do not want the network to memorize class details but instead only the invariant transformations ii) it would prevent conditioning the generator over classes unseen during training. The network is simultaneously trained to minimize with x drawn from any other distribution. It thus also acts as the similarity-based classifier where similarity is ascertained from class labels. For our purpose we found that having the discriminator separate outputs for p data (x|class = class(x t )) and p θ (x|x t ) leads to better performance. This is consistent with the work of [27] for semi-supervised learning. Hence we formulate our discriminator to minimize the following loss: where y = 1 is the label associated with the tuple (x, x t ), x ∼ p data (x|class(x t )) and y = 0 is associated with x ∼ p data (x|class = class(x t )).
Generator Network: The generator in our proposed model is a parametric function G θ (.) that maps from the data space to another point in the same space, ie. it acts as an auto-encoder. To prevent the generator from simply copying the input we enforce regularization by corrupting the input data point x t by some stochastic process. The corrupted input data pointx t is then down-scaled by passing through a series of convolutions followed by up-scaling using a series of transposed convolutions. Essentially our generator behaves as a denoising autoencoder [33] but instead of a reconstruction loss it is trained with an adversarial loss. The generator is trained to minimize the following objective:

Experiments
We perform experiments to validate the proposed models for few shot learning over two datasets -Omniglot and mini-Imagenet. All our models are implemented using the Lasagne library [4] for Theano [32].

Omniglot
Omniglot was introduced in [20] for the express purpose of measuring one shot learning performance of models. It consists of 1623 classes of characters with 20 binary images per class. Results on the dataset have been reported using two different configurations in literature -a within alphabet setting of [20] and the more recent across alphabet setting of [34]. In this paper we follow [34] to have consistent results with other recent works.  The dataset is divided into two parts -the first 1200 classes are used for training and validation, while the remaining are test classes for the few shot tasks. For this dataset we follow the training protocol (algorithm 1) with num tests = 200 and runs per test = 20. We tested both our proposed improvements, Skip Residual Pairwise Networks (SRPN) and Generative Regularizer (GR) on this dataset.
We train two architectures for the convolutional siamese network: i) Siam-I: a smaller one with 5 convolutional layers and a final global pooling layer ii) Siam-II: a larger network with 5 residual blocks followed by global pooling. We follow the Wide Residual Networks design with k=2 [36]. We modify Siam-II for the design of our SRPN model. While the depth of Siam-I and Siam-II is different, both have a similar number of trainable parameters. We also use these convolutional siamese networks as baselines for our proposed models.
To ensure consistency with other published results, we rescale the images to 28x28 pixels, and augment the training data with random rotations (by ±45 degrees and/or translations (6 pixels) in both X and Y axis. The training is done using mini-batch gradient descent with Adam [17] updates and batch size of 128. The initial learning rate is set to 8 × 10 −4 and β 1 = 0.5 for GR experiments. L2 regularization is used with all models except those with GR. We maintain a validation set of 60 classes from training for early stopping. Results are reported in table 1

Mini-Imagenet
Mini-Imagenet was introduced recently in [34] as a more challenging dataset for one shot learning tasks. The dataset consists of 100 classes of natural images from the Imagenet total-correct-pred = 0; for num-tests do sample support set S by randomly picking N classes and 1 example for each of those classes; for runs-per-test do sample a test case x t from one of the classes in S; if predict(S,x t ) == class(x t ) then total-correct-pred += 1 end end end return (total-correct-pred / (num-tests*runs-per-test)) Algorithm 1: Testing protocol for N -way one shot learning Figure 5. Actual data samples from some of the test classes for the Mini-Imagenet Dataset. Each column shows two images from the same class. Given the huge inter-class variation in these natural images, the problem of recognizing the class by comparing it to a single image of each of the other classes is challenging.
dataset [25] with 600 RGB images per class, rescaled to 84x84 pixels. Since the standard splits for the dataset were not released, researchers have reported results by randomly selecting 100 classes from the Imagenet dataset [23] [30]. We follow a similar practice here.
The dataset is divided into two parts -the first 80 classes are used for training and validation, while the remaining are test classes for the few shot tasks. For this dataset we follow the training protocol (algorithm 1) with num-tests = 100 and runs-per-test = 100. We tested both our proposed improvements, Skip Residual Pairwise Networks (SRPN) and Generative Regularizer (GR) separately on this dataset. However we found that Generative Regularization (GR) did not yield any benefits for these very deep models as the generator itself was not able to learn well. We believe it is due to the unstable nature of GAN training. Hence we only report results on Skip Residual Pairwise Networks (SRPN) for this task.
Since network depth has been shown to be essential for good performance on Imagenet, we restrict ourselves to the Wide Resnet model [36] with network depth of 40 and k=2. We train a siamese network using this model as our baseline and we modify it for the design of our SRPN model to ensure the results are comparable.
To ensure consistency with other published results, we rescale the images to 84x84 pixels. No data augmentation or pre-processing of any kind is done. The training is done using mini-batch gradient descent with Adam [17] updates and batch size of 64. Both models are trained for 100000 updates. The initial learning rate is set to 5 × 10 −4 , and is annealed linearly to 1 × 10 −4 . L2 regularization is used for both models with initial value of 5 × 10 −7 increased to 1 × 10 −6 after 60000 updates. Results are reported in table 2.

Discussion
We discuss some observations about our two suggested models -the Skip Residual Pairwise Network (SRPN) and the Generative Regularizer (GR). First, we notice that not only does the SRPN achieves higher accuracy than the equivalent Residual Siamese Network but its convergence is much faster and the mean network weight is noticeably smaller. (see figure 6,7) In our opinion, this happens because the SRPN is not forced to learn an embedding that . One shot test accuracy comparison for the SRPN (red) and the wide residual siamese net (blue) as training progresses on mini-Imagenet works well with a fixed distance metric, instead it is able to adapt to the distance measure that best minimizes the total loss. This allows the network to find a manifold which reduces the similarity loss as well as the regularization penalty, effectively leading to better generalization performance. We also note that while the SRPN is not explicitly trained to learn a symmetric embedding the model does this automatically as can be seen by the diminishing difference between the embeddings (pre-final layer) in figure 8. Also interesting to note is that for the mini-Imagenet task our siamese residual net baseline outperforms the previous state-of-the-art, which reinforces the importance of depth in complicated image recognition tasks but is also an indicator that deep convolutional models with millions of parameters can be successful in learning from features that generalize well to unseen data distributions and thus do well in the one shot learning setup.
Our experiments with the Generative Regularizer (GR) give a mixed-bag of results -the regularization is much more effective than L2 regularization as shown by the results on Omniglot with Siam-I model reaffirming the results in semi-supervised learning with such methods [27]. However, training the generator-discriminator framework is challenging due to its sensitivity to hyperparameters, often leading to poorly trained generator that impedes training as seen with very deep models as discriminators. We believe that advances in the GAN training methodology could be applied here directly and that a properly trained GR+SRPN network would outperform one with L2-regularization.
As an aside, we also tried training the GR model without providing conditioning information, ie. mapping from Gaussian noise to the image space. We observed that the generator inevitably collapsed to a single point, but was still able to regularize the siamese network. This indicates that there are multiple failure modes of the generator and that good generation is not essential for regularization. We will continue to experiment in this direction.

Conclusion
To summarize, we identified fixed distance measures and weak regularization as major challenges to similarity matching and its extension to one shot learning and presented a network design for each of the problems. Our Skip Residual Pairwise Network outperforms an equivalent Residual Siamese Network and achieves state of the art performance on the mini-Imagenet one shot classification dataset. Our Generative Regularizer shows promising results and outperforms L2-regularization on the Omniglot dataset. Future work would focus on integrating the two networks presented here by tapping into advancements in the training of Generative Adversarial models.