Skip to content
tezvyn:
Menu

Prototypical Networks: Learning from a Handful of Examples

Source: arXivMediumHow cards are made

Prototypical Networks classify new categories from few examples by finding the average representation, or 'prototype,' for each class. This is key for few-shot image recognition where you have only 1-5 examples.

Why it exists

Standard deep learning models need thousands of examples per class. But what if you only have a handful of images for a new category? Few-shot learning addresses this, and Prototypical Networks are a simple, effective solution. They aim to generalize from a small 'support set' of examples to new, unseen classes.

The mental model

Imagine plotting points on a map where each city represents a class (e.g., 'cat,' 'dog'). A Prototypical Network learns to draw a map (the embedding space) where examples of the same class are tightly clustered. The 'prototype' is the geometric center of a class's cluster. To classify a new image, you plot it on the map and see which city center it's closest to.

How it works

The network learns an embedding function that maps an input, like an image, to a vector in a high-dimensional space. During a few-shot task, you provide a small 'support set' of examples for each new class. The network embeds each of these examples. The 'prototype' for that class is simply the mean of these embedding vectors. To classify a new 'query' image, it's also embedded, and its distance (usually Euclidean) to each class prototype is calculated. The class with the minimum distance is the predicted label.

When to use it

Use Prototypical Networks when you need to classify new categories with very few labeled examples (e.g., 1-shot or 5-shot learning). They are effective in image recognition, character recognition, and other domains where you can't afford to collect large datasets for every new class you might encounter. Their simplicity makes them a strong baseline.

When not to use it

They may be less effective when a class has high variance, meaning its examples don't form a single, tight cluster in the embedding space. More complex models might handle such distributions better. If you have abundant data for all classes, standard supervised classification is usually more powerful and appropriate.

One canonical example

In a 5-shot bird classification task, you're given 5 images of a 'Blue Jay' and 5 of a 'Cardinal'—classes the model has never seen. The network embeds all 10 images. The 'Blue Jay prototype' is the average of the 5 Blue Jay embedding vectors. The 'Cardinal prototype' is the average of the 5 Cardinal vectors. Given a new, unlabeled image of a Blue Jay, it's embedded, and its distance to the Blue Jay prototype will be smaller than to the Cardinal prototype, leading to a correct classification.

Interview question

How does a Prototypical Network classify a new, unseen image in a few-shot learning task?

  • a.It calculates the average of all support set images and checks if the new image is similar to this overall average.
  • b.It retrains a separate classifier for each new class using the provided support examples.
  • c.It directly compares the new image's raw pixel data to all images in the support set.
  • d.It embeds the image into a feature space and assigns it to the class whose mean embedding (prototype) is nearest.Correct
Why?

Prototypical Networks classify by embedding the query image and assigning it to the class whose prototype (mean embedding of its support examples) is closest. Option B describes a different few-shot learning approach, not how Prototypical Networks operate.

Just read this? Test yourself on what you have been reading.

Read the original → arxiv.org

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.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on machine learning — each one lists the topics its interview covers.

See open roles