Skip to content
StackDecode
AI & ML Atlas
Deep LearningtechniqueInteractive simulation

Deep Metric Learning

Learns an embedding where similar things are close and different things are far apart.

The idea

Instead of predicting a class, the network maps each input to a vector, and the loss shapes the geometry of that space: same-class pairs are pulled together, different-class pairs pushed apart. New classes can then be recognised by nearest-neighbour search without retraining.

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

  • class 1
  • class 2
  • class 3

Items from three classes are scattered randomly in embedding space. We want the same class close together and different classes far apart.

step:
0
spread ratio:
0.968
1/41

Spread ratio = (average distance within a class) ÷ (average distance between classes). Lower is better.

Step by step

  1. 1Embed inputs with a shared network.
  2. 2Choose pairs or triplets of examples.
  3. 3Use a loss (contrastive or triplet) to pull positives together and push negatives apart.
  4. 4Search in the embedding space to match or retrieve.

Where it is used

Face verification, product search, few-shot learning.

Watch out for

Choosing informative ("hard") pairs is crucial and tricky.

Related