AI Glossary / Probabilistic machine learning / Intermediate
Prototypical network
Definition
A prototypical network is a few-shot classification method that learns an embedding space and represents each class by the mean embedding of its labeled support examples. It classifies a query by comparing its embedding with those class prototypes, commonly converting negative distances into a probability distribution with a softmax.
What it means
The method aims to make a small number of labeled examples useful for recognizing a new class. Rather than fitting a separate complex classifier from those few examples, it relies on a representation learned from earlier training tasks. In that representation, examples of a class should lie near a representative center.
The prototype is an average vector, not necessarily an actual image or other observed example. Its usefulness depends on the embedding and the assumption that a single center adequately represents the class. Few support examples do not mean the system learned all its knowledge from only those examples.
How it works
Map each support example x through a learned embedding f(x). For class k with support set S_k, compute c_k = sum_(x in S_k) f(x)/|S_k|. Embed a query q, calculate its distance to each c_k, and normalize exp[-distance] across the candidate classes.
The original method trains the embedding using episodes: choose a set of training classes, divide examples into support and query sets, form prototypes from the support examples, and minimize the query classification loss. Query labels guide training but are not included in the support prototypes.
Squared Euclidean distance is a common choice and is central to the original method's analysis. The learned representation makes the simple classifier meaningful. At evaluation, new-class prototypes can be formed from their support examples without requiring a new separately fitted classifier for each episode. Evaluation must preserve the intended distinction between training classes and new test classes.
Three practical examples
- Image-category research: classify examples of newly introduced visual categories from a small labeled support set in a previously learned embedding.
- Document routing: investigate whether new document types can be represented by a few examples, with evaluation on genuinely unseen types.
- Audio-event studies: compare new sound categories through embedded support examples, while testing robustness to recording conditions and background noise.
Think of it this way
Think of placing a flag at the center of each labeled group on a learned map, then assigning a new point to the nearest flag. The map matters as much as the flag locations. The analogy breaks down when a class has several distant clusters or the map fails to represent a new domain; a single center can then be misleading.
Worked example
Consider an original two-dimensional embedding example. Class A has support vectors (0, 0) and (2, 0), so its prototype is (1, 0). Class B has support vectors (0, 2) and (2, 2), giving prototype (1, 2).
For query embedding (1, 0.5), squared Euclidean distances are d_A = 0.25 and d_B = 2.25. The probability assigned to A is exp(-0.25)/[exp(-0.25) + exp(-2.25)] = 1/[1 + exp(-2)], approximately 0.8808. B receives approximately 0.1192, and the predicted class is A.
If every embedding coordinate is multiplied by 2, the prototypes and query also double. The squared distances become 1 and 9. The predicted class remains A, but its softmax probability becomes 1/[1 + exp(-8)], approximately 0.9997.
This shows why the scale of an embedding or an explicit temperature affects reported probabilities even when the nearest-prototype decision is unchanged. The numbers are a constructed calculation, not evidence that either probability is calibrated on real data.
Illustrative case study
Fictional case: Seabrook Archive tests a system for routing newly defined document categories. It supplies a few labeled examples of each new type and forms prototypes using a previously trained document embedding.
The team evaluates with separate query documents and checks whether examples from one category form multiple distinct clusters. It also examines predictions on documents belonging to none of the supplied classes, because the ordinary softmax still distributes probability among the listed classes. Reviewers judge both classification performance and uncertainty behavior before considering use. This invented case does not claim measured savings or reliable recognition from arbitrary small samples.
Common misconceptions and mistakes
A prototype is the mean of embeddings, not the embedding of the mean raw input; nonlinear mappings make those operations different. It is also different from retaining every support example for a nearest-neighbor decision.
Few-shot classification is not automatically open-set recognition. A standard closed-set episode assumes queries belong to the candidate classes. Nor does a large softmax value prove certainty: distance scale, support representativeness, and domain shift all affect interpretation.
Business use
For a business with frequently introduced categories, prototypical networks offer a simple way to construct a classifier from a learned representation and a small support set. The practical attraction is rapid category setup once the representation is suitable.
The evaluation should reflect the number of candidate classes, examples per class, and domain changes expected in use. Keep support selection separate from query evaluation and include a policy for unsupported or ambiguous inputs. The cost of learning and maintaining the embedding remains part of the system's overall cost.
People also ask
Can one example define a prototype?
Yes. With one support example, the prototype is that example's embedding, although reliability still depends on representativeness and the learned space.
Does every new task require gradient training?
Basic prototype construction can classify a new episode using the fixed embedding and support means; variants may add adaptation.
Can a prototype represent several separate clusters?
A single mean may be inadequate for a strongly multimodal class. Alternative representations or multiple prototypes require a modified method.
Check your understanding
Class A has three support embeddings. Should its prototype be divided by the total number of classes or by three?
Answer: By three, the number of support examples in class A. Each class prototype is its own support-set mean.
Related terms
- Few-shot learning
- Embedding
- Metric Learning
- Softmax
- Open set recognition
- support set
- query set
- episodic training
- class prototype
- squared Euclidean distance
Learn next
Compute support means and query distances by hand, then inspect how scaling distances changes softmax probabilities. Study episodic training and class-disjoint evaluation. Finally, test what happens when a class is multimodal or a query falls outside all supported classes.
More in Probabilistic machine learning
- Probabilistic inference by automatic differentiation - Probabilistic inference by automatic differentiation uses derivatives of a suitable probability computation to recover quantities such as marginal...
- Probability integral transform - The probability integral transform maps a random variable through its own cumulative distribution function.
- Probability of improvement - Probability of improvement is an acquisition criterion used in Bayesian optimization.
- Quasi-Monte Carlo integration - Quasi-Monte Carlo integration estimates an integral by averaging a function over deliberately well-distributed points rather than independent random points.
- Query by committee - Query by committee is an active-learning strategy that selects examples for labeling by examining disagreement among several plausible models.
- RAND-WALK word embedding model - RAND-WALK is a latent-variable model of word generation that helps explain the structure of word embeddings learned from co-occurrence statistics.
Sources
Snell, Swersky and Zemel, Prototypical Networks for Few-shot Learning, original paper, equations 1–2 and episodic-training description: https://papers.nips.cc/paper/2017/file/cb8da6767461f2812ae4290eac7cbc42-Paper.pdf Authors' code repository and project record: https://github.com/jakesnell/prototypical-networks Snell-Swersky-Zemel prototype and distance-softmax definitions were independently consulted.
Previous: Prototype methods Next: Provisioning