AI Glossary / Deep learning / Intermediate
Metric Learning
Definition
Metric learning learns a distance or similarity representation from data so that comparisons better reflect a specified task. Instead of accepting a fixed notion of closeness, it uses examples or constraints to make relevant items closer and irrelevant items farther apart under the learned comparison.
What it means
Two products can be similar in color but different in function. Two support requests can use different words yet require the same solution. Metric learning addresses which differences should matter for the intended comparison.
The training signal might identify matching pairs, different classes or triplets in which one item should be closer to a reference item than another. The resulting representation can support retrieval, nearest-neighbor classification or clustering.
Similarity remains task-dependent. A representation trained for visual resemblance may not identify interchangeable parts, and a metric trained for one dataset may fail on another. The word metric is also sometimes used loosely: a learned score or squared distance does not necessarily satisfy every mathematical property of a strict distance metric.
How it works
A classical approach learns a linear transformation of feature vectors and measures ordinary distance after that transformation. Equivalently, a suitable positive-semidefinite matrix defines a Mahalanobis-style squared distance. This can change the relative importance and combination of input directions.
Deep metric learning instead learns a nonlinear embedding with a neural network. Pair-based or triplet-based objectives encourage relationships specified by the training data. A triplet contains an anchor, a relevant positive and an irrelevant negative; the objective can require the positive to be closer by a chosen margin.
The selection of examples matters. Easy pairs may teach little, while incorrectly labeled difficult examples can push the representation in the wrong direction. Evaluate on genuinely held-out items or groups appropriate to the intended application.
After learning, a retrieval system still needs an index, a comparison rule and decision thresholds. Good embeddings do not automatically solve every part of search.
Three practical examples
- A catalog search system learns product embeddings from reviewed examples of visually similar items, while keeping functional compatibility as a separate requirement.
- A support tool learns which historical requests share a resolution, helping staff retrieve relevant cases despite different wording.
- A document organization project learns distances from expert judgments so that related materials become useful neighbors for exploration.
Think of it this way
Think of replacing a ruler that measures every direction equally with one designed for the question. If a tiny difference in a part's diameter matters more than a large difference in its packaging color, the comparison should reflect that.
The analogy is limited because learned similarity may involve a nonlinear transformation rather than simple weighted measurements. The training examples define what the ruler learns; they do not establish a universal standard of similarity.
Worked example
Changing which item is nearest
Consider a query with two prepared features q = (0, 0), a task-relevant item A = (0.2, 3) and an irrelevant item B = (1, 0). Under ordinary squared Euclidean distance, A is 0.2 squared plus 3 squared = 9.04 away, while B is 1 away. B is therefore nearer.
Suppose a learned weighting uses d squared = 25 times the first-feature difference squared plus the second-feature difference squared. Then A has squared distance 25 × 0.04 + 9 = 10, while B has squared distance 25. A is now nearer.
This constructed weighting illustrates how a learned comparison can change neighborhoods. It is not evidence that those weights would be learned or generalize well. A separate evaluation must establish whether emphasizing the first feature helps on new relevant and irrelevant items, rather than only on this example.
Illustrative case study
Fictional case: Cedar Support trains a retrieval embedding from pairs of tickets marked as having the same resolution. Early results return tickets with similar product names but different underlying issues.
The team examines the labels and finds that a broad administrative closure code was treated as a shared resolution. It refines the training definition, separates tickets from the same incident across evaluation boundaries and asks reviewers to judge retrieved cases against the actual support task.
The system also shows the original case and its context rather than presenting a near neighbor as a guaranteed answer. The example illustrates that a useful metric begins with a defensible meaning of similarity, not merely a sophisticated loss function.
Common misconceptions and mistakes
- Metric learning discovers the one true similarity. Similarity depends on the task and supervision.
- All embeddings are trained by metric learning. Embeddings can arise from other objectives, even if distances are later used.
- Nearby means interchangeable. A visual, semantic or behavioral match may not satisfy an operational constraint.
- A strong training score establishes useful retrieval. Leakage, narrow labels and new-item behavior require separate evaluation.
Business use
Metric learning is useful when fixed distances or general-purpose embeddings miss distinctions important to retrieval and matching. Its value should be measured by whether people find the right items, not only by a lower training loss.
Define relevant matches, acceptable near misses and costly confusions with domain experts. Evaluate ranking quality, coverage and thresholds on the intended population. If the embedding model changes, stored vectors may need to be regenerated unless cross-version compatibility has been established. A numerical distance has meaning only within its specified representation and comparison procedure.
People also ask
Does metric learning always reduce dimension?
No. It can change a distance or representation without reducing the number of dimensions.
Does it require class labels?
No. Pairwise or relative similarity judgments can provide supervision, and other approaches derive training signals differently.
Is a small distance a calibrated probability of a match?
Not automatically. Turning distance into a probability requires an appropriate model and calibration evidence.
Check your understanding
A metric trained to retrieve products with similar appearance returns a part that does not fit the user's equipment. Is that necessarily a failure of its stated training objective?
Answer: Not necessarily. Appearance and compatibility are different targets. The business system must encode or check compatibility rather than assume visual proximity guarantees it.
Related terms
- Embedding
- Similarity Search
- Mahalanobis distance
- Nearest neighbor
- Triplet loss
- Representation learning
- contrastive loss
- retrieval evaluation
Learn next
Read triplet loss and nearest-neighbor classification. Create three examples where two plausible definitions of similarity disagree, then decide which definition the intended user needs and how to obtain reliable training judgments.
More in Deep learning
- Lernmatrix - The Lernmatrix, German for learning matrix, is an early associative-learning architecture developed by Karl Steinbuch around 1960.
- Liquid State Machine Network - A liquid state machine network is a reservoir-computing architecture that transforms a time-varying input into changing internal activity, commonly in a...
- Manifold Learning - Manifold learning is a family of methods that seek a lower-dimensional representation of data whose structure may be curved or nonlinear within a...
- Modern Hopfield network - A modern Hopfield network is an associative-memory model that extends classical Hopfield ideas through different energy functions and retrieval dynamics.
- Multi-surface method - The multi-surface method is a historical approach to classifying patterns by constructing several separating surfaces.
- Multidimensional Scaling - Multidimensional scaling, or MDS, is a family of methods that represents objects as points so that distances between the points reflect supplied...
Sources
Weinberger and Saul, Distance Metric Learning for Large Margin Nearest Neighbor Classification: https://www.jmlr.org/papers/v10/weinberger09a.html. Schroff, Kalenichenko and Philbin, FaceNet, embedding and triplet-learning research: https://arxiv.org/abs/1503.03832. Seidenschwarz, Elezi and Leal-Taixé, Learning Intra-Batch Connections for Deep Metric Learning: https://proceedings.mlr.press/v139/seidenschwarz21a.html. Tatli and colleagues, Metric Learning in an RKHS: https://proceedings.mlr.press/v286/tatli25a.html. Worked weights and Cedar Support are original illustrations.
Previous: Metric Next: Metric multidimensional scaling