Skip to content
AI360Xpert
Core ML
Visual explainer

Contrastive Learning

How models learn rich representations without human labels by comparing augmented views of the same image.

Reconstructing pixels wastes capacity on the background instead of the subject.
Reconstructing pixels wastes capacity on the background instead of the subject.

Reconstructing raw pixels spends model capacity memorising noisy backgrounds. Instead of recreating an image, contrastive learning asks the model to compare views. It learns a representation space by grouping similar things together and pushing different things apart, using the data itself as the label.

The Positive Pair

Two random crops from the same photo form a positive pair.
Two random crops from the same photo form a positive pair.

To teach the model identity, you create two augmented views of the same image. A random crop or colour shift defines what the model should ignore. These two views form a positive pair that share an identity.

Pull and Push

The loss pulls the positive pair together and pushes all other batch examples away.
The loss pulls the positive pair together and pushes all other batch examples away.

The mechanism is a ranking task. The loss function pulls the embeddings of the positive pair closer together. Simultaneously, it pushes the anchor away from all other unrelated images in the batch, treating them as negatives.

Organised by Identity

The resulting space groups images by identity, forming clean clusters.
The resulting space groups images by identity, forming clean clusters.

Over time, the embedding space organises itself. Images with the same underlying identity cluster tightly together, while distinct classes separate. The model has learned rich, linearly separable features without seeing a single human label.

Where It Breaks

Random batch sampling treats identical classes as negatives, pushing them apart.
Random batch sampling treats identical classes as negatives, pushing them apart.

The model assumes every other image in the batch is a true negative. If two photos of a deer happen to be in the same batch, the loss forces them apart. This false negative collision limits how well the clusters can form.

The Quick Version

  • Contrastive learning groups data without human labels.
  • Positive pairs are created by augmenting the same original image.
  • The loss pulls positives together and pushes batch negatives apart.
  • The learned space clusters by identity, not raw pixel appearance.
  • False negatives in the batch force identical classes apart.

What to Read Next