Contrastive self-supervised learning with SimCLR
contrastive learning mechanics.
two augmentations of one image form a positive pair, other images in the batch are negatives; an encoder plus projection head and the NT-Xent loss pull positives together and push negatives apart.
What's really being asked
Whether you can explain how augmentations, positive and negative pairs, and the contrastive loss produce useful representations without labels.
The full answer
SimCLR learns by instance discrimination. Take an image and apply two independent random augmentations, such as cropping, color jitter, and blur, producing two correlated views; these two views form a positive pair because they come from the same source image. Every other image's augmented views in the same batch are treated as negatives for that anchor. A shared base encoder, for example a ResNet, maps each view to a representation, and a small projection head, typically an MLP, maps representations to the embedding space where the loss is computed; the projection head is discarded after pretraining and the encoder is what you keep. The objective is the normalized temperature-scaled cross-entropy loss, NT-Xent: for each anchor it forms a softmax over cosine similarities to all other views, with a temperature parameter, and maximizes the similarity to its positive while minimizing similarity to all negatives. The strength of the augmentations and a large batch, which supplies many negatives, are critical to learning representations that transfer well to downstream tasks.
The mistakes people make
Saying positives are two different source images of the same class, which would require labels; dropping the augmentation step that creates the views; ignoring the role of the projection head or keeping it for downstream use; forgetting that negatives come from the batch; underplaying the importance of strong augmentation and batch size.
What usually comes next
Why discard the projection head before fine-tuning? Why does SimCLR need very large batches and how do later methods avoid that? What role does temperature play? Which augmentations matter most and why is color distortion important?
A concrete example
In a batch of 256 images, each yields two augmented views, giving 512 views. For an anchor view of a particular dog photo, its positive is the other augmentation of that same photo and its 510 negatives are all other views. NT-Xent pulls the two dog-photo views together in embedding space and pushes them away from everything else; after pretraining, the encoder produces features that fine-tune to strong classification accuracy with few labels.
Interview question
In SimCLR, what forms a positive pair?
- a.An image and its nearest neighbor in feature space
- b.An image and its horizontally flipped negative
- c.Two independent augmentations of the same source imageCorrect
- d.Two different images sharing the same class label
Why? this is the answer
Positives are two augmented views of the same image, requiring no labels, which is the essence of self-supervision. Pairing images by shared class label would need labels, defeating the purpose.
Just read this? Test yourself on what you have been reading.
Read the original → arxiv.org
- #self-supervised
- #simclr
- #contrastive-learning
- #nt-xent
- #representation-learning
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles