A collection of fragments of understanding in the pursuit of deeper questions.
Metric-Based ML The core idea in metric-based meta-learning is similar to nearest neighbors algorithms and kernel density estimation. The predicted probability over a set of known labels y is a weights sum of label of support set samples. The weight is generated by a kernel function , measuring the similarity between two data samples.
To learn a good kernel is crucial to the success of a metric-based meta-learning model. Metric learning is well aligned with this intention, as it aims to learn a metric or distance function over objects. The notion of a good metric is problem-dependent. It should represent the relationship between inputs in the task space and facilitate problem solving. A few models are introduced, that learn embedding vectors of input data explicitly and use them to design proper kernel functions:
Prototypical Networks They use an embedding function to encode each input into a M-dimensional feature vector. A prototype feature vector is defined for every class , as the mean vector of the embedded support data samples in this class.
![]() |
![]() |
|---|
The distribution over classes for a given test input x is a softmax over the inverse of distances between the test data embedding and prototype vectors.
where can be any distance function as long as is differentiable. In the paper, they used the squared Euclidean distance. The loss function is the negative log-likelihood:
Siamese Networks They are composed of two twin networks and their outputs are jointly trained on top with a function to learn the relationship between pairs of input data samples. The twin networks are identical, sharing the same weights and network parameters. In other words, both refer to the same embedding network that learns an efficient embedding to reveal relationship between pairs of data points. Convolutional Siamese Neural Networks have been applied to one-shot image classification.
Training: The Siamese network is trained for a verification task for telling whether two input images are in the same class. It outputs the probability of two images belonging to the same class.
Testing: The Siamese network processes all the image pairs between a test image and every image in the support set. The final prediction is the class of the support image with the highest probability. Given a support set S and a test image , the final predicted class is:
where c(x) is the class label of an image x and is the predicted label.
Matching Networks
They aim at learning a classifier for any given (small) support set (k-shot classification). This classifier defines a probability distribution over output labels y given a test example . Similar to other metric-based models, the classifier output is defined as a sum of labels of support samples weighted by attention kernel - which should be proportional to the similarity between and .
The attention kernel depends on two embedding functions, f and g, for decoding the test sample and the support set samples respectively. The attention weight between two data points is the cosine similarity, cosine(.), between their embedding vectors, normalized by softmax:
The embedding has to be chosen carefully. In a simple version, an embedding function is a neural network with a single data sample as input. Taking a single data point as input might not be enough to efficiently gauge the entire feature space. Therefore, the Matching Network model further proposed to enhance the embedding functions by taking as input the whole support set S in addition to the original input, so that the learned embedding can be adjusted based on the relationship with other support samples.
Relation Networks They are similar to Siamese Networks but with a few differences:
In the figure we have a Relation Network architecture for a 5-way 1-shot problem with one query example.