Contrastive learning trains models to pull similar examples together and push different ones apart. Learn how it works, contrastive loss, and its applications.

Updated August 2026
A model can learn what makes two things similar without anyone labeling a single example. Contrastive learning does it by comparison: show it two views of the same image and one of something different, and it learns which two belong together.
Quick answer: Contrastive learning is a technique that trains a model to place similar examples close together and different examples far apart in an embedding space. It builds "positive" pairs from two views of the same item and "negative" pairs from different items, then uses a contrastive loss to pull positives together and push negatives apart. It is a leading form of self-supervised learning.
Contrastive learning teaches a model by comparison rather than by labels. Instead of telling the model "this is a cat," it shows two altered versions of the same image and one different image, and asks which two belong together. Over millions of such comparisons, the model learns a representation where related things sit close and unrelated things sit far apart.
The payoff is that the training signal comes from the data itself. Any image can become a positive pair by making two altered copies, so a model can learn from a large pool of unlabeled data and then be fine-tuned on a small labeled set. That is why contrastive learning became a workhorse of .
This content was generated with the assistance of AI. Our AI prompt chain workflow is carefully grounded and preferences .gov and .edu citations when available. All content is reviewed by a Telnyx employee to ensure accuracy, relevance, and a high standard of quality.
The method rests on positive and negative pairs.
A neural network encoder maps each example to a vector, and a contrastive loss rewards the model when positives sit closer than negatives. SimCLR showed that the recipe matters: strong augmentation to create the positive views, and a nonlinear projection head on top of the encoder, both sharply improve the learned representation.
To make it concrete, take a single unlabeled photo. Contrastive learning creates two augmented views of it, say a random crop and a color shift, and treats them as a positive pair. Every other image in the batch becomes a negative. The encoder embeds all of them, and the loss adjusts the weights so the two views land near each other and far from everything else. Repeat across a huge unlabeled set, and the encoder learns features that transfer to real tasks.

Contrastive loss is the objective that pulls positives together and pushes negatives apart. Its most common form is InfoNCE, introduced by van den Oord and colleagues. It frames one positive against many negatives as a classification problem: given an anchor, score the positive above every negative, and the loss falls as the model gets that ranking right.
The number of negatives matters. More negatives sharpen the contrast, which is why methods work hard to supply them. SimCLR uses large batches, while MoCo keeps a running queue of past examples to compare against, so the contrast stays strong without enormous batch sizes.
A few methods made contrastive learning mainstream.
The results are strong. A linear classifier trained on SimCLR's self-supervised features reaches 76.5% top-1 accuracy on ImageNet, matching a supervised ResNet-50 while using no labels during pretraining.

Contrastive learning is used wherever good representations matter more than a single label.
The common thread is similarity. When the goal is a space where distance means relatedness, contrastive learning builds it directly.
The method has real costs. It usually needs many negatives to create a sharp contrast, which pushes toward large batches or extra machinery like MoCo's memory queue, and that makes training compute-heavy.
The choice of augmentations also carries weight. Make them too weak and the positive pair is trivial to match, so the model learns little. Make them too strong and the two views no longer share the content that made them a pair.
False negatives are a subtler trap. Two different images that happen to show the same object get treated as a negative pair and pushed apart, even though they are genuinely similar. Supervised contrastive learning sidesteps this by using labels to define pairs, at the cost of needing those labels.
Mostly self-supervised, which sits between the two. It uses no human labels, so it is not supervised in the usual sense. But it does manufacture its own training signal from the data, the positive and negative pairs, so it is not blind clustering either. That middle ground is the point: a clear training target without the cost of labeling.
There is also supervised contrastive learning, which uses real labels to define positives as same-class items and negatives as different-class items. It blends the contrastive objective with supervision when labels are available.
Contrastive learning is a technique that trains a model to place similar examples close together and different examples far apart in an embedding space. It builds positive pairs from two views of the same item and negative pairs from different items, then uses a contrastive loss to separate them. It is a common form of self-supervised learning.
Contrastive loss is the objective that pulls positive pairs together and pushes negatives apart. InfoNCE, its most common form, frames the task as picking the positive out of a set that also holds many negatives. The loss falls as the model scores the positive above the negatives.
A positive pair is two views of the same item, such as an image and an augmented copy, that should end up close in the embedding space. A negative pair is two different items that should end up far apart. The contrast between them is what the model learns from.
It pretrains models on unlabeled data, builds embeddings for search and retrieval, matches across modalities like image and text, and powers similarity tasks such as recommendation and deduplication. The shared goal is an embedding space where distance reflects similarity.
It is usually self-supervised: it uses no human labels but creates its own training signal from positive and negative pairs. A supervised variant also exists, which uses class labels to decide which pairs count as positive and which as negative.