Pick a concrete input and say what the equation should give before you read the math.
Foundation reference
Contrastive Learning & InfoNCE
Contrastive learning trains useful encoders without labels: a linear classifier on SimCLR features reached 76.5% top-1 accuracy on ImageNet, matching a supervised ResNet-50 (Chen et al., 2020).
Study guide
Where to start
How does the temperature τ decide whether the loss concentrates on the hardest negatives or spreads its weight over all of them?
How to study this pagePredict · Check · Generalize · Continue
Work through the math, then read the cited papers for the original argument.
Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.
Use the prerequisites and related concepts at the end of the page to fill the next gap.
Why It Matters for Modern Models
- Contrastive learning trains useful encoders without labels: a linear classifier on SimCLR features reached 76.5% top-1 accuracy on ImageNet, matching a supervised ResNet-50 (Chen et al., 2020).
- Applied to image–caption pairs, the same loss produced CLIP, whose encoders support zero-shot image classification and are used to condition text-to-image models (Radford et al., 2021; Ramesh et al., 2022).
- The same framework is used for sentence embeddings, audio–text models and the encoders of multimodal models.
Questions to Think About
- Why do more negatives, for example from larger batches, tighten the mutual-information bound and often give better representations?
- What happens when two examples of the same class are treated as negatives of each other, and how much does correcting for these false negatives help (Chuang et al., 2020)?
Core Math
Contrastive learning trains an encoder so that two views of the same example (a positive pair) get similar embeddings, while views of different examples (negatives) do not.
InfoNCE loss for an anchor with positive :
where the sum runs over the positive and negatives, is usually cosine similarity and is a temperature. In SimCLR the two views are random augmentations of the same image, and the negatives are the other images in the batch (Chen et al., 2020).
The loss is a cross-entropy for picking the positive out of candidates. If the positive pair is sampled from the joint distribution and the negatives are independently drawn from the opposite view's marginal, van den Oord et al. (2018) show . The expectation is over those draws, not one observed batch; increasing raises the bound's possible ceiling.
CLIP applies the same loss to image–text pairs, in both directions (Radford et al., 2021):