Semi-supervised Metric Learning

Machine Learning
Introduced by
Yeung, D.-Y. & Chang, H.; Davis, J. V. & Dhillon, I. S.
Year
2007–2008
Type
Hybrid supervised/unsupervised distance learning
Family
Machine learning

What does it do?

Semi-supervised metric learning learns a distance function from weak supervision, typically pairwise must-link constraints (members share a class) and cannot-link constraints (members differ).

Many formulations also exploit the geometry of a larger unlabeled sample. The learned distance is usually a Mahalanobis form or a kernel-induced distance, and it is used in downstream tasks such as nearest-neighbor classification, retrieval and clustering.

The intuition behind the method

Fully supervised metric learning needs many labeled pairs or triplets, which can be costly to obtain. The semi-supervised variant also uses unlabeled data: a regularizer built from a neighborhood graph, kernel matrix or manifold estimate encourages points that are close in the data to stay close under the learned metric, while the constraints pull known same-class pairs together and push known different-class pairs apart. Whether this helps depends on the unlabeled data actually reflecting the structure relevant to the task.

History

Semi-supervised metric learning builds on the fully supervised metric learning setting, in which the distance is learned from labeled pairs or triplets. Yeung & Chang (2007) proposed a kernel approach for semi-supervised metric learning based on pairwise similarity or dissimilarity information, formulated as a convex kernel learning problem. Davis & Dhillon (2008) presented scalable, structured Mahalanobis metric learning for high-dimensional problems based on the log-determinant matrix divergence; their constraints can arise from fully supervised or semi-supervised information. Later work on deep metric learning and contrastive objectives, which make heavy use of unlabeled data, is not covered by the sources listed on this page.

When to use it

Use semi-supervised metric learning when labeled data is scarce, unlabeled data is abundant, and the downstream task depends on a good notion of similarity, such as kNN classification, retrieval, clustering or few-shot learning. It suits settings where annotation is costly, for example medical imaging, molecular biology or document retrieval. Avoid it when labels are plentiful, since fully supervised metric learning is the more direct choice. It is also a poor fit when the unlabeled pool is small or unrepresentative, because the manifold assumption then fails, or when the dimensionality is very high and no low-rank, sparse or structured restriction is available, because estimating a full Mahalanobis matrix becomes ill-conditioned.

Limitations and considerations

  • The regularizer assumes that the neighborhood structure of the unlabeled data reflects the task's notion of similarity. If the unlabeled points are noisy or unrepresentative, that structure can pull the metric in the wrong direction.
  • A full Mahalanobis matrix has a number of parameters that grows quadratically with dimensionality, so high-dimensional data requires low-rank, sparse or structured restrictions.
  • Exact optimization over large sets of pairwise constraints and large kernel matrices is computationally expensive, and a kernel matrix grows with the square of the number of data points.
  • Noisy or inconsistent must-link and cannot-link labels degrade the learned metric, because the constraints are the only direct supervision.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Many formulations can use unlabeled points as a regularizer on the learned metric, something a purely supervised pairwise method does not do.
  • The kernel optimization problem in Yeung & Chang (2007) is convex and so has no local optima. One special case has a closed-form solution; the other is solved by iterative majorization, which estimates the optimum asymptotically.
  • Pairwise must-link and cannot-link judgements can be recorded without assigning items to named classes, which suits some annotation pipelines.
  • Structured, low-parameter Mahalanobis formulations, such as the log-determinant framework in Davis & Dhillon (2008), scale linearly with dimensionality; their constraints can come from fully supervised or semi-supervised information.
  • The method can be applied in the original feature space or in a kernelized space.

Applications

  • Face verification and person re-identification with few identity labels.
  • Medical image retrieval where expert-annotated pairs are scarce.
  • Document and text similarity where only partial relevance judgments exist.
  • Protein or molecular similarity learning with limited experimental assay data.
  • Few-shot learning pipelines that require a strong initial embedding space.
  • Semi-supervised clustering where must-link/cannot-link constraints guide partition.

How it works

How it works

1

Pairwise constraints are collected from labels or expert judgement: must-link pairs (instances believed to belong to the same class) and cannot-link pairs (instances known to differ). A judgement that two items are alike can be recorded without naming a class, which is why such constraints are often easier to gather than full labels.

2

In many formulations, all data, labeled and unlabeled, is used to estimate local structure, for example through a neighborhood graph, a kernel matrix or a manifold estimate. This encodes the assumption that nearby unlabeled points should remain near each other under the new metric, and it acts as a regularizer on the learned distance. This step is formulation-specific: the Yeung & Chang (2007) kernel approach is described in its abstract as using pairwise similarity or dissimilarity information, and it is not stated there to use a separate unlabeled-data regularizer.

3

An objective is written that rewards satisfying the must-link and cannot-link constraints and, in formulations that use unlabeled data, penalizes departures from the structure estimated in the previous step. The exact form varies: kernel-based formulations, information-theoretic divergences over Mahalanobis matrices (such as the log-determinant divergence of Davis & Dhillon, 2008) and graph Laplacian regularized losses are all used. Yeung & Chang (2007) formulate metric learning as a convex optimization problem for kernel learning.

4

The objective is minimized, typically by convex optimization or gradient-based methods, to yield a positive semi-definite matrix M for the Mahalanobis distance d_M(x,y) = sqrt((x-y)^T M (x-y)), or a kernel function. Positive semi-definiteness is required for d_M to be a valid pseudo-metric, so it has to be verified rather than assumed. In Yeung & Chang (2007), one special case has a closed-form solution, while the other is solved by iterative majorization, which estimates the optimum asymptotically.

5

The learned metric is assessed on data not used for fitting: by constraint satisfaction on held-out pairs, by neighbor purity for nearest-neighbor classification, or by clustering agreement (NMI, ARI) against a labeled test set. These checks indicate whether the metric transfers to new data rather than only fitting the training constraints.

Common pitfalls

  • Treating the whole unlabeled pool as reliable when it contains out-of-distribution samples, which can distort the neighborhood structure used as a regularizer.
  • Judging the learned metric by constraint satisfaction on the training constraints. Fitting those constraints does not show that the metric generalizes; kNN accuracy or clustering quality on held-out labeled data is needed.
  • Using the learned matrix downstream without first checking that it is positive semi-definite.
  • Ignoring class imbalance in the constraint set, which can bias the metric toward the over-represented classes.
  • Comparing only against unmodified Euclidean distance. This hides whether any gain comes from the constraints or from the unlabeled structure; an ablation that removes one source separates the two.

Frequently asked questions

How many pairwise constraints are typically needed?

The number depends on the data, its dimensionality and how well the unlabeled data covers the classes of the task. The sources on this page do not establish a general threshold. Report the number of must-link and cannot-link pairs and their class balance, and plot held-out performance against the number of constraints to see whether it levels off.

How does this differ from purely supervised metric learning?

Purely supervised metric learning optimizes only on labeled triplets or pairs. Semi-supervised metric learning works with weaker supervision such as pairwise constraints and, in many formulations, also incorporates the geometry of unlabeled examples as a regularizer, which can help when labels are scarce.

Can deep neural networks be used as the backbone?

Yes. Deep semi-supervised metric learning trains an encoder with contrastive or triplet losses on labeled pairs, while self-supervised pretext tasks or pseudo-labels use the unlabeled data, combining both paradigms.

What evaluation metric should I use?

Common choices are mean Average Precision (mAP) or Recall@k for retrieval, accuracy (and F1 if classes are imbalanced) for kNN classification, and NMI and ARI for clustering on a held-out labeled subset. Whatever the metric, evaluating on held-out data is the reliable check.

When is it better to use self-supervised or transfer learning instead?

This depends on the task. If a suitable pretrained model exists for a related domain, it is worth comparing against directly, since a pretrained encoder does not need pairwise annotation at fitting time. Neither approach dominates in general, so a comparison on the target data is the reliable way to choose.

Related methods

Sources

  1. Yeung, D.-Y., & Chang, H. (2007). A kernel approach for semi-supervised metric learning. IEEE Transactions on Neural Networks, 18(1), 141–149.

    Open DOI reference
  2. Davis, J. V., & Dhillon, I. S. (2008). Structured metric learning for high dimensional problems. Proceedings of the 14th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 195–203.

    Open DOI reference