AI Glossary / Probabilistic machine learning / Advanced

Matching network

Definition

A matching network is a few-shot classification model that predicts a query's label by attending to labeled examples in a support set. It learns representations and a matching procedure across training tasks, then uses a new support set to define a new classification task.

What it means

Suppose a system must recognize several unfamiliar categories from a handful of examples. Instead of training a separate final classifier from scratch for every new set of categories, a matching network compares the new query with supplied reference examples.

The method combines learned features with an example-based prediction rule. The neural representation has already been trained using many tasks or examples; “one-shot” does not mean the entire system learned from one observation in total.

Its output is conditioned on the support set. Changing that set can change the prediction without changing the network's learned weights. In the basic formulation, the possible output labels are those supplied by the support examples.

How it works

Encode the query and each support example into learned representations. Calculate similarity scores, convert them into attention weights that sum to one, and take the weighted sum of the support labels represented as class indicator vectors.

Several support examples may share a label, so their attention weights accumulate into the same class probability. The original formulation includes cosine-based attention and versions whose embeddings also depend on the support-set context.

Training uses episodes: select a small group of classes, form a labeled support set and ask the network to classify separate queries from those classes. Optimization adjusts its representations using query prediction errors. Evaluation should use appropriately held-out classes when the intended claim is generalization to new categories. Successful adaptation still depends on how related the new tasks are to the training experience.

Three practical examples

  • A visual-catalog prototype classifies new component types using a few labeled reference photographs for each type.
  • A document-image experiment compares unfamiliar symbols against a support set after learning transferable representations from other symbols.
  • A research team studies whether rare-event categories can be recognized from small support sets while keeping query examples separate from those references.

Think of it this way

Think of an experienced archivist comparing an unfamiliar stamp with a small reference tray. Past experience helps the archivist notice useful features, while the tray specifies the categories relevant to the current question.

The analogy captures prior learning plus task-specific examples. A matching network does not possess an archivist's background understanding, and similarity in its learned space can reflect irrelevant visual features.

Worked example

Attention to examples is aggregated by class

Consider a query with three support examples. The first two are class A and the third is class B. Suppose their similarity scores are 0.5, 0 and 1, values that could occur in a cosine-based example.

Exponentiating gives approximately 1.648721, 1 and 2.718282. Their sum is 5.367003, so the attention weights are approximately 0.307196, 0.186324 and 0.506480.

The predicted probability for A is the sum of its two weights, approximately 0.493520. The probability for B is approximately 0.506480. Although B has only one reference example, it narrowly receives the higher probability in this constructed case.

If an identical copy of the second A example is added while these embeddings and scores are held fixed, the denominator becomes 6.367003. A's probability becomes 3.648721/6.367003, approximately 0.573067, and the predicted class changes.

This illustrates sensitivity to support composition in the simple fixed-embedding rule. A full-context embedding may itself change when the support set changes, so the second calculation is not a universal prediction for every matching-network variant. The scores are invented; no model-training performance is claimed.

Illustrative case study

A fictional spare-parts service introduces new component categories frequently. Its research team tests a matching-network prototype using reference photographs captured by warehouse staff.

The initial evaluation mixes near-duplicate photographs of the same physical item across support and query sets. The team revises the split so queries come from different physical items and holds out entire categories for the new-category evaluation. It also varies the number and quality of reference photographs.

The exercise identifies what a convincing evaluation must measure. The service does not conclude that one reference photograph will reliably cover every pose, lighting condition or damaged version of a component.

Common misconceptions and mistakes

  • One-shot means no substantial earlier training: transferable representations normally depend on prior learning.
  • It always chooses the single closest example: the basic attention rule combines multiple support labels.
  • Adding duplicate references has no effect: it can change the distribution of attention across classes.
  • A high output probability proves the query belongs to a supported class: a closed-set classifier can be confident even when the true class is absent.

Business use

Matching networks can be useful to investigate when categories change frequently and only small labeled support sets are available. Compare them with simpler nearest-neighbor methods using the same features and with other few-shot approaches.

Define how references are selected, whether class sizes are balanced and what happens when the query matches none of the supported categories. Measure variation across many episodes rather than reporting one favorable support set. Updating references can alter production behavior, so support-set versions deserve tracking alongside model versions.

People also ask

Does adaptation require retraining?

The original inference procedure can use a new support set without updating network weights, although other variants may include adaptation steps.

Is it the same as a prototypical network?

No. A basic matching network attends to individual support examples; a prototypical network typically compares queries with class-level representative embeddings.

Can it invent a label missing from the support set?

The basic weighted-label formulation cannot assign probability to an entirely absent class without an additional mechanism.

Check your understanding

Three support examples receive attention weights 0.2, 0.3 and 0.5. Their labels are A, A and B. What are the class probabilities?

Answer: A receives 0.2 + 0.3 = 0.5 and B receives 0.5. The class prediction is tied even though one individual B example has the greatest attention weight.

Related terms

  • Few-shot learning
  • One-shot learning
  • Metric Learning
  • Attention
  • Prototypical network
  • support set
  • query set
  • episodic training
  • nearest-neighbour classification

Learn next

Practice converting similarity scores into attention weights and aggregating those weights by label. Then design a small episodic evaluation with disjoint support and query items. Compare ordinary sample splits with class-disjoint splits to understand the different generalization claims.

  • Attention

More in Probabilistic machine learning

  • Log-sum-exp trick - The log-sum-exp trick is a numerically stable way to calculate the logarithm of a sum of exponentials.
  • Manifestation shift - Manifestation shift is a change in how a target condition produces the observable physical characteristics used to recognize it.
  • Masked autoregressive flow - A masked autoregressive flow, or MAF, is a normalizing-flow model that uses masked neural networks to transform observed data into a simpler base distribution.
  • Matrix normal distribution - The matrix normal distribution is a probability distribution for a matrix whose entries jointly follow a multivariate Gaussian distribution with a separable...
  • Max-product algorithm - The max-product algorithm is a message-passing method for finding a highest-probability joint assignment in a factorized probability model.
  • Maximum entropy reinforcement learning - Maximum entropy reinforcement learning trains a policy to maximize a combination of expected reward and policy entropy.

Sources

Vinyals and colleagues, Matching Networks for One Shot Learning, NeurIPS 2016, architecture and episodic training: https://proceedings.neurips.cc/paper/2016/file/90e1357833654983612fb05e3ec9148c-Paper.pdf

Author preprint: https://arxiv.org/abs/1606.04080

The attention calculation and fictional service are original illustrations. Historical benchmark numbers are not used as current performance claims.

Previous: Matched-samples t test Next: Matching pursuit

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer