AI Glossary / AI and machine learning / Intermediate
Similarity learning
Definition
Similarity learning trains a model to judge how alike or related two objects are for a particular task. It can learn a comparison function directly or learn representations in which useful similarities are reflected by distances or other scores.
What it means
Similarity is not a single universal property. Two products can be similar in appearance but different in function. Two documents can discuss the same topic while expressing opposite conclusions. The learning task must specify which relationship matters.
Training information may identify similar and dissimilar pairs, rank one item as more similar to an anchor than another, or provide labels from which such relationships are constructed. These signals guide the model toward a task-specific comparison.
Metric learning is a closely related area that learns distances with particular mathematical properties. Similarity learning is broader: a useful score need not satisfy every property of a formal distance metric.
The result can support retrieval, matching, clustering, or nearest-neighbor prediction. It does not automatically establish identity, causation, or interchangeability. Those claims require stronger definitions and evidence than a high learned similarity score.
How it works
Define the objects, the intended relationship, and the evidence available for learning it. Choose features or an encoder that produces representations suitable for comparison.
Construct training pairs, triplets, or other supervision. A triplet commonly contains an anchor, a desired closer example, and a desired farther example. Sampling choices affect which distinctions the model learns.
Optimize a loss that rewards the intended relationships. The model may adjust feature weights, learn a transformation, or train a neural embedding. Constraints and regularization help avoid degenerate solutions or excessive fitting to the training comparisons.
Evaluate on unseen objects and relevant retrieval or matching tasks. Avoid splitting nearly identical items across training and testing in a way that exaggerates generalization. Check difficult alternatives, rare categories, and changes in the input population. A score threshold needs calibration for the actual decision and its error costs.
Three practical examples
1. A catalog search model learns that functional compatibility matters more than color for a particular retrieval task. Its evaluation checks whether compatible items appear near the top of the results.
2. A document-matching system learns from reviewer-labeled pairs. It distinguishes duplicate content from merely related topics, because those relationships serve different workflows.
3. A classroom exercise learns a distance from examples of similar shapes. Students compare the learned geometry with an unweighted distance over the original measurements.
Think of it this way
Think of choosing which features matter when comparing houses. Someone seeking a short commute may emphasize location, while someone comparing architectural styles may emphasize shape and materials.
The analogy captures task dependence. A learned model does not necessarily know why a feature matters, and its training judgments may be inconsistent or biased. Changing the purpose of comparison can require new supervision rather than reuse of the same score.
Worked example
Suppose an anchor item is compared with a relevant item P and an irrelevant item N. Their current learned distances are d(anchor,P) = 0.7 and d(anchor,N) = 0.9.
An illustrative triplet loss requires the irrelevant item to be at least 0.3 farther away. The loss is max(0, 0.7 − 0.9 + 0.3) = 0.1. The ordering is correct, but the desired margin is not yet satisfied.
If training changes the distances to 0.5 and 1.0, that triplet's loss becomes zero. This does not prove that the whole model is good: other comparisons may worsen, and unseen items may behave differently. The margin is a modeling choice, not an intrinsic unit of semantic difference.
Illustrative case study
Fictional case: Oak Archive wants to find near-duplicate training documents. Its first labels mark any two documents on the same subject as similar, so the learned system returns many related but distinct documents.
Reviewers clarify that the task concerns substantially repeated content. They revise the labeling guidance and add difficult pairs that share a topic without being duplicates.
The team evaluates retrieval on a separate collection and inspects both missed duplicates and false matches. This invented case illustrates the importance of defining similarity. It does not claim a measured gain or suggest that changing the model architecture alone would correct an ambiguous task definition.
Common misconceptions and mistakes
Do not assume a learned similarity score is a probability. Its numerical scale depends on the model and training objective.
Do not confuse relevance, resemblance, duplication, and identity. Do not assume metric properties such as symmetry or the triangle inequality unless the chosen function guarantees them. Avoid training only on easy negative pairs, which can leave difficult distinctions untested. Finally, do not reuse a threshold across datasets without checking whether its error behavior remains acceptable.
Business use
Similarity learning can support search, recommendation, record matching, and organization of large collections. It is useful when a generic distance or exact-match rule does not reflect what users consider relevant.
Define success in terms of the workflow: ranking quality, false matches, missed matches, review effort, or another meaningful outcome. Assess the cost of collecting reliable comparison labels. Keep separate evaluations for different notions of similarity rather than assuming one embedding serves every business purpose equally well.
People also ask
Is similarity learning always supervised?
It often uses explicit or constructed relationship signals, but the supervision can come from labels, interactions, or self-supervised data transformations.
Must it use neural networks?
No. Learning feature weights or a distance transformation can also be similarity learning.
Does a low distance mean two records are the same entity?
Only if that interpretation is supported by the task definition and validated decision procedure.
Check your understanding
A model trained to find visually similar products returns an item with the wrong function. Is that necessarily a training failure?
Answer: Not necessarily. The model may be following its visual-similarity objective. Functional compatibility requires an appropriate definition, supervision, and evaluation.
Related terms
- Metric Learning
- Embedding
- Triplet loss
- Nearest neighbor search
- Semantic similarity
- Representation learning
- contrastive loss
- relevance ranking
Learn next
Compare several definitions of similarity for the same set of objects. Then calculate a simple pairwise or triplet loss and examine how training examples determine the desired geometry. Study retrieval evaluation to connect learned scores with user-visible results.
More in AI and machine learning
- Sequence-to-sequence task - A sequence-to-sequence task is one where both input and output are ordered sequences: a sentence becomes a translation, a question becomes an answer, a...
- Sequential Feature Selection - Sequential Feature Selection is a family of feature selection methods that build the feature set step by step, adding the most helpful feature each round...
- Shrinkage - Shrinkage is the deliberate pulling of estimated values toward a center, typically toward zero or a group average, trading a little bias for a large...
- Simultaneous autoregression - Simultaneous autoregression is a spatial statistics model where each location's value is predicted from the values of its neighboring locations at the same...
- Single program / multiple data - Single program / multiple data, usually shortened to SPMD, is a way of organizing parallel computing in which several processors run the same program on...
- Situated - In artificial intelligence, situated describes an agent whose behavior is embedded in and shaped by interaction with an environment.
Sources
Xing, Ng, Jordan, and Russell, Distance Metric Learning, with Application to Clustering with Side-Information: https://aima.cs.berkeley.edu/~russell/papers/nips02-metric.pdf, sections 1–2 consulted independently. Schroff and colleagues, FaceNet: https://arxiv.org/pdf/1503.03832, section 3 consulted for triplet supervision. FaceNet uses squared distances; this entry states its own illustrative distance-margin loss. Original arithmetic checked independently; the case is fictional.
Previous: Similarity graph Next: Similarity measure