- Introduced by
- Chen, T. et al. (SimCLR); earlier metric learning foundations by Bromley, LeCun (1994)
- Year
- 2020 (modern contrastive formulation); foundations 1990s–2000s
- Type
- Self-supervised representation learning with metric objective
- Family
- Machine learning
What does it do?
Self-supervised metric learning trains a neural encoder so that inputs judged similar by the data's own augmentations lie close together in an embedding space, without human labels.
It combines a self-supervised pretext task, in which positive pairs are generated by augmenting the same input, with a contrastive or triplet-style metric objective. The resulting representations are intended for transfer to retrieval, clustering and few-shot classification, either used directly or with a light downstream classifier.
The intuition behind the method
Suppose a model must learn which inputs belong together, but no one has said which items share a class. It is shown two distorted copies of the same image, one flipped and one cropped, and is trained to map both to nearby embeddings, while copies of different images are pushed apart. The metric loss supplies the direction of each update, and the augmentation policy supplies the only notion of similarity. What the model learns is therefore a distance function shaped by the invariances built into those augmentations, and it can be reused on downstream tasks that have only a few labelled examples.
History
Metric learning with Siamese-style networks dates to the 1990s. The self-supervised contrastive formulation was popularised by Chen et al. (2020), who showed that contrastive pretraining on unlabelled ImageNet images can yield features competitive with supervised ones on transfer tasks. Khosla et al. (2020) extended the same contrastive objective to labelled data, which is a related but distinct setting.
When to use it
Choose this approach when labelled examples for the target task are scarce or costly, but a large pool of unlabelled data from the same domain is available, as in some image retrieval, medical imaging or audio fingerprinting settings. It also fits few-shot evaluation, where embedding quality matters more than a task-specific classifier. It requires that domain-appropriate augmentations exist which preserve the semantics of the target task. Do not use it when a labelled dataset is large enough for supervised training, when no augmentation policy can be justified for the domain, or when decisions must be explained at the level of individual features, since the learned embedding is not directly interpretable.
Limitations and considerations
- Results depend strongly on the augmentation policy: a transformation that removes a feature the downstream task needs makes the encoder invariant to exactly that feature.
- The contrastive loss needs many negatives per update, usually supplied by a large batch or a memory bank, which raises GPU memory demand.
- Pretraining is expensive relative to a supervised baseline on the same encoder, because each example is encoded in several views at every step.
- Distances in the learned space are shaped by the chosen augmentations, so what the model treats as similar is only as interpretable as that policy; the embedding itself gives little direct explanation.
- Batch negatives are drawn without regard to semantics, so semantically similar items can be treated as negatives (false negatives), pushing apart items that should lie close together.
- Results are sensitive to hyperparameters such as batch size, temperature and augmentation strength, so a fair comparison requires tuning both the self-supervised model and the baseline on the same validation split.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Pretraining labels come from the data itself, so an unlabelled pool can be used without annotation effort.
- Because the objective shapes a general similarity geometry, the same encoder can be reused for retrieval, clustering, few-shot classification and anomaly detection.
- When the downstream labelled set is small, fine-tuning a self-supervised pretrained encoder was reported to outperform training the same network from scratch in the semi-supervised settings studied by Chen et al. (2020); comparable gains on other tasks should be checked empirically.
- The objective is defined on embeddings, so it can be attached to convolutional or Transformer backbones, the two families named in the encoder step.
Applications
- Image and video retrieval where labelled training sets are unavailable or costly to build.
- Medical imaging: learning representations from large collections of unlabelled scans, then adapting them to disease classification with few labelled cases.
- Audio fingerprinting and music similarity search using contrastive pretraining on raw waveforms.
- Few-shot classification benchmarks such as miniImageNet and Omniglot, where embedding quality strongly affects downstream accuracy.
- Anomaly detection by thresholding distances in the learned metric space, and cross-modal retrieval using a shared embedding space.
How it works
How it works
For each unlabelled data point, two or more augmented views are created with transformations suited to the domain, such as random crops, colour jitter, masking or noise. Views of the same point form the positive pairs, and in the usual batch setting the other items in the same mini-batch serve as negatives. The choice of transformations is the main design decision, because it defines which variations the embedding is trained to ignore.
Each view is passed through a shared backbone encoder (e.g., ResNet, Vision Transformer, or a text encoder) to produce a fixed-dimensional embedding vector. The encoder weights are shared across views so that both paths are forced to learn the same feature space.
A lightweight projection head, typically one or two MLP layers, maps the backbone embedding to the space where the metric loss is computed. The head is discarded after pretraining, and the backbone embedding is used for downstream tasks. Chen et al. (2020) reported that this separation improves transfer performance.
A contrastive loss such as NT-Xent (InfoNCE) maximises the cosine similarity of a positive pair relative to all other samples in the batch. In the formula, a mini-batch of N images yields 2N augmented views; for anchor view i, z_i and z_j are the projected embeddings of the anchor and of its positive view j (the other augmented view of the same image), sim is cosine similarity, and the denominator sums over every k not equal to i. It therefore includes the positive pair as well as the 2N-2 remaining views, which act as negatives. Triplet-style variants instead shrink the anchor-positive distance while requiring a margin over the anchor-negative distance. The temperature tau scales the similarities before the softmax; a smaller value emphasises the most similar negatives.
Formula
\mathcal{L} = -\log \frac{\exp(\text{sim}(z_i, z_j)/\tau)}{\sum_{k \neq i} \exp(\text{sim}(z_i, z_k)/\tau)}After pretraining, the encoder is either linearly probed with frozen embeddings or fine-tuned on a labelled downstream task. A linear probe can be competitive when the pretrained geometry already separates the target classes. In the semi-supervised settings studied by Chen et al. (2020), fine-tuning a pretrained encoder with few labels was reported to outperform training the same network from scratch; whether this holds for a given target task has to be checked empirically, and the better option depends on that task.
Common pitfalls
- Choosing augmentations that violate task semantics (e.g., colour jitter on tasks where colour is the target signal), causing the model to become invariant to discriminative features.
- Reporting only linear-probe accuracy without also reporting fine-tuning results, which can give a misleading picture of transfer utility.
- Ignoring false negatives in the contrastive loss when the dataset contains many near-duplicate or semantically identical items.
- Using projection-head outputs for downstream tasks instead of backbone embeddings, which degrades transfer performance.
- Comparing self-supervised models pretrained on a large unlabelled corpus against supervised baselines trained on a small labelled set, without acknowledging the difference in data available to each.
Frequently asked questions
What is the difference between metric learning and self-supervised metric learning?
Traditional metric learning requires labelled pairs or triplets to define positive and negative relationships. Self-supervised metric learning generates these relationships automatically using data augmentation or pretext tasks, eliminating the need for human labels during pretraining.
Which contrastive loss should I use: NT-Xent, triplet, or something else?
NT-Xent (InfoNCE) is the loss used in the SimCLR framework of Chen et al. (2020) and is the usual default for batch-based training. Triplet loss suits settings where explicit anchor, positive and negative triples can be defined. Hard negative mining can make training more informative, but it also raises the risk of treating false negatives as negatives.
How important is the augmentation strategy?
Critically important. Augmentations define what the model treats as equivalent. If the augmentation breaks a feature that is discriminative for the downstream task (e.g., removing colour when colour matters), the model will be invariant to exactly the wrong things. Domain expertise in augmentation design is essential.
Can self-supervised metric learning be applied to tabular data?
Yes, though the approach is less established for tables than for images. Augmentations for tabular data include feature masking, mixup and noise injection. Gains over a supervised baseline are not guaranteed and should be checked on the target table against a properly tuned supervised model.
How do I evaluate the quality of learned embeddings without labelled data?
Common unsupervised proxies include k-nearest-neighbour accuracy on a small labelled probe set, clustering quality (silhouette score, NMI), and alignment and uniformity measures of embedding geometry. A linear probe on a held-out labelled split is the standard supervised evaluation.
Is SSML the same as smooth simulated maximum likelihood?
No. In econometrics, SSML denotes smooth simulated maximum likelihood, a simulation-based estimator for limited dependent variable models due to Börsch-Supan and Hajivassiliou (1990). It is a different method from the self-supervised metric learning described on this page, so a search for SSML may return that econometric method instead.
Related methods
Sources
Chen, T., Kornblith, S., Norouzi, M., & Hinton, G. (2020). A Simple Framework for Contrastive Learning of Visual Representations. Proceedings of the 37th International Conference on Machine Learning (ICML 2020), PMLR 119, 1597–1607.
Open publication referenceKhosla, P., Tian, Y., Wang, X., Liu, C., Krishnan, D., Isola, P., & Tian, Y. (2020). Supervised Contrastive Learning. Advances in Neural Information Processing Systems (NeurIPS 2020), 33, 18661–18673.
Open publication reference