Prototypical Networks for few-shot classification
metric-based few-shot learning.
an encoder embeds support examples, each class prototype is the mean embedding of its support examples, and a query is classified by nearest prototype using a distance like Euclidean via softmax.
What's really being asked
Whether you understand metric-based few-shot learning and the simple prototype-and-distance rule at its core.
The full answer
Prototypical Networks tackle few-shot classification, where each task or episode provides only a handful of labeled examples per class, called the support set, plus query images to classify. A single embedding network, shared across all classes, maps each image into a feature space. For each class the prototype is computed as the mean vector of the embeddings of that class's support examples, so with five examples per class you average five embeddings into one prototype. A query image is then embedded with the same network and classified by finding the nearest prototype, using a distance metric, with squared Euclidean distance working well; the negative distances are passed through a softmax to give class probabilities. Training is episodic: each training iteration samples a small support and query set mimicking the few-shot test setting, and the encoder is optimized so that queries land close to their correct class prototype. The key idea is that classification reduces to nearest-prototype matching in a learned space, requiring no per-episode parameter updates.
The mistakes people make
Claiming it trains or fine-tunes a new classifier head for each episode rather than comparing embeddings; using a learned parametric classifier instead of distance to class means; saying prototypes are single examples rather than means; forgetting episodic training; assuming cosine similarity is required when the original work used squared Euclidean.
What usually comes next
Why squared Euclidean rather than cosine, and how does it relate to a linear classifier? How does this compare with Matching Networks or MAML? What happens with one-shot, where the prototype is a single embedding? How does episodic training improve generalization to new classes?
A concrete example
In a five-way five-shot episode you get five new classes with five labeled images each. The encoder embeds all twenty-five support images and averages the five per class into five prototypes. A query image of an unseen bird is embedded, and its squared Euclidean distance to each prototype is computed; the softmax over negative distances assigns it to the nearest prototype's class, all without updating any weights at test time.
Interview question
How does a Prototypical Network classify a query image?
- a.By assigning it to the class whose mean support embedding (prototype) is nearestCorrect
- b.By retrieving the single most similar support image's label
- c.By fine-tuning a new softmax classifier on the support set each episode
- d.By averaging logits from many pretrained classifiers
Why? this is the answer
The query is embedded and matched to the nearest class prototype, the mean of that class's support embeddings, with no per-episode training. Fine-tuning a classifier each episode describes optimization-based methods, not Prototypical Networks.
Just read this? Test yourself on what you have been reading.
Read the original → arxiv.org
- #few-shot-learning
- #prototypical-networks
- #metric-learning
- #embeddings
- #meta-learning
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles