Lesson 5.8advanced3 h

Self-supervised and contrastive learning

Learning representations without labels — SimCLR, MoCo, BYOL, DINO, MAE

Labels are expensive; pixels are free. Self-supervised learning (SSL) turns unlabeled images into training signal, and since 2020 it has produced the best general-purpose visual features: DINOv2 embeddings power retrieval, depth and segmentation out of the box. The core loss, InfoNCE, is the same one that trains CLIP (8.10 Multimodal models) and every text embedding model behind RAG (9.2 Embeddings deep dive), and masked image modeling is the visual twin of BERT's masked language modeling (7.5 Encoder-only: BERT and friends (and sentence embeddings)). Learn the mechanism once here and you will recognize it across the rest of the path.

You'll be able to

  • Define pretext tasks and explain why augmentation-based positives work
  • Derive the InfoNCE / NT-Xent loss as a softmax classifier over candidates and explain the role of temperature
  • Contrast contrastive (SimCLR, MoCo), non-contrastive (BYOL, DINO) and masked (MAE) approaches and why the latter two avoid collapse
  • Evaluate representations with linear probing, kNN and fine-tuning
  • Implement NT-Xent in PyTorch

Key ideas

  1. Self-supervision creates labels from the data (augmented views, masked patches); at scale it yields better transferable features than supervised ImageNet pretraining.
  2. NT-Xent/InfoNCE is cross-entropy over a softmax of scaled cosine similarities: pick the positive view among 2N−1 candidates; it lower-bounds mutual information, so more negatives help.
  3. Temperature τ controls focus on hard negatives: τ = 0.1 turns (0.8, 0.2, 0.1) into near-certainty, τ = 1 leaves it ambiguous; typical τ ≈ 0.1–0.5.
Show 4 more key ideas
  1. SimCLR needs crop + color distortion, a discarded projection head and big batches; MoCo replaces big batches with a momentum encoder and a queue of negatives.
  2. BYOL/SimSiam/DINO avoid collapse without negatives via predictor + stop-gradient + EMA teacher (DINO adds centering and sharpening); DINO attention maps segment objects for free.
  3. MAE masks 75% of patches, encodes only visible ones (3–4× cheaper) and reconstructs pixels; masked modeling fine-tunes best, joint-embedding probes best.
  4. Evaluate with linear probe, kNN, fine-tuning and transfer — the same protocol used for text embeddings.

Suggested path through this lesson