Post

Introduction to Self-Supervised Learning

Introduction to Self-Supervised Learning

Introduction to Self-Supervised Learning

Self-Supervised Learning (SSL) is a training paradigm that learns useful representations from unlabeled data by solving pretext tasks that generate their own supervision signals. SSL has become a foundation of modern AI across vision, language, audio, and multimodal systems.

Why Self-Supervised Learning?

  • Reduce label dependence: unlabeled data is abundant; labels are costly.
  • Transfer and generalization: pretrain once, adapt to many downstream tasks.
  • Robustness: invariances learned via augmentations often improve OOD performance.
  • Efficiency: downstream tasks can succeed with fewer labeled examples.

Core Paradigms

Contrastive Learning

Learn representations by bringing positive pairs closer and pushing negatives apart.

  • Objective (InfoNCE):
\[\mathcal{L}_{\text{InfoNCE}} = -\sum_i \log \frac{\exp(\operatorname{sim}(z_i, z_i^+)/\tau)}{\sum_{j} \exp(\operatorname{sim}(z_i, z_j)/\tau)}\]
  • Examples: SimCLR, MoCo, CPC, CLIP (image–text contrast).
  • Notes: Requires many negatives or memory queues; strong data augmentation is critical.

Masked / Denoising Prediction

Predict masked or corrupted parts of the input.

  • Language: BERT (masked language modeling), ELECTRA (replaced token detection).
  • Vision: MAE/SimMIM (masked image modeling) reconstruct pixels/latents.
  • Audio/Speech: masked time/frequency segments in spectrograms.
  • Notes: Stable optimization without explicit negatives; strong results for foundation models.

Autoregressive Modeling

Model the likelihood of the next token/patch/frame given context.

  • Language: GPT-style next-token prediction.
  • Vision/Audio: sequence modeling on tokens/patches for generative tasks.

Bootstrap / Self-Distillation (Negative-free)

Align two views without negatives via momentum encoders or stop-gradient tricks.

  • Examples: BYOL, SimSiam, DINO.
  • Notes: Avoids the need for large negative sets; relies on architectural asymmetry/predictor.

Generative Autoencoding

Encode–decode to reconstruct inputs with information bottlenecks or priors.

  • Examples: Autoencoders, VAEs, diffusion-based pretraining variants.

Data Augmentations by Modality

  • Vision: random crop & resize, color jitter, grayscale, blur, flips, patch masking.
  • Language: token masking, span corruption, permutation (careful to preserve grammar/semantics).
  • Audio: time/frequency masking, time stretch, noise injection, SpecAugment.
  • Multimodal: cross-view dropout, caption shuffling (negatives), modality dropout.

Choose augmentations that preserve task-relevant semantics while creating diversity.

A Practical Training Recipe

  • Backbone: start simple (ResNet/ViT-small for vision; BERT-base for text).
  • Projection head: 2–3 layer MLP for contrastive objectives.
  • Optimizer: AdamW; LR ~ 1e-3 (heads) / 1e-4 (backbone); weight decay 1e-4–1e-2.
  • Batch size: large helps contrastive learning; use queues (MoCo) if limited.
  • Temperature (τ): tune 0.05–0.2 for contrastive losses.
  • Regularization: dropout, mixup/cutmix (vision), label smoothing for fine-tuning.
  • Checkpoints: save both backbone and projection head for reproducibility.

Evaluation Protocols

  • Linear probe: freeze the encoder; train a simple classifier on labeled data.
  • Fine-tuning: initialize from SSL; train end-to-end for the downstream task.
  • k-NN evaluation: fast proxy on representations (common in vision).
  • Retrieval/zero-shot: especially for multimodal contrastive models like CLIP.
  • Report mean±std over multiple seeds for robust claims.

Common Pitfalls and Fixes

  • Representation collapse (non-contrastive): use asymmetry (BYOL), predictors, stop-grad.
  • Over/under-augmentation: too strong harms semantics; too weak limits invariance.
  • Data leakage: avoid using downstream test data during pretraining or augmentation design.
  • Domain mismatch: pretrain data should be close to target domain when possible.
  • Small batch contrastive instability: use memory banks/queues or accumulate gradients.

When to Use What

  • Contrastive: retrieval, clustering, robust invariances, multimodal alignment (CLIP).
  • Masked modeling: strong general-purpose pretraining and transfer (BERT/MAE).
  • Autoregressive: generative modeling, open-ended text/audio synthesis.
  • Bootstrap/self-distillation: simpler pipelines without negatives, strong for vision.

References (Starter Pack)

  • SimCLR: A Simple Framework for Contrastive Learning of Visual Representations.
  • MoCo: Momentum Contrast for Unsupervised Visual Representation Learning.
  • BYOL: Bootstrap Your Own Latent.
  • SimSiam: Exploring Simple Siamese Representation Learning.
  • BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding.
  • MAE: Masked Autoencoders Are Scalable Vision Learners.
  • CLIP: Learning Transferable Visual Models From Natural Language Supervision.

This post introduces the main families of SSL methods and practical tips. Future posts will dive into modality-specific recipes and modern SSL trends (e.g., masked autoencoding vs. contrastive hybrids, multimodal instruction tuning).

This post is licensed under CC BY 4.0 by the author.