Home Knowledge Base Contrastive Learning

Contrastive Learning is the self-supervised and supervised representation learning framework that trains models by pulling similar (positive) pairs close together and pushing dissimilar (negative) pairs apart in embedding space — producing high-quality feature representations without requiring labeled data, forming the foundation of CLIP, SimCLR, and modern embedding models.

Core Principle

InfoNCE Loss (Standard Contrastive Loss)

$L = -\log \frac{\exp(sim(z_i, z_j^+)/\tau)}{\sum_{k=0}^{K} \exp(sim(z_i, z_k)/\tau)}$

SimCLR (Visual Self-Supervised)

1. Take an image, create two random augmentations (crop, color jitter, flip). 2. Encode both through a ResNet backbone → projector MLP → embeddings z₁, z₂. 3. These two views are the positive pair. 4. All other images in the mini-batch are negatives. 5. Minimize InfoNCE loss. 6. After training: Discard projector, use backbone features for downstream tasks.

CLIP (Vision-Language Contrastive)

Key Design Choices

FactorImpactBest Practice
Batch sizeMore negatives → betterLarge batches (4096-65536)
Temperature τLower = sharper distinctions0.07-0.1 for vision
Augmentation strengthDetermines what's "invariant"Strong augmentation essential
Projection headImproves representation qualityMLP projector, discard after training
Hard negativesTraining signal qualityMine semi-hard negatives

Beyond SimCLR

Contrastive learning is the dominant paradigm for learning general-purpose representations — its ability to leverage unlimited unlabeled data to produce embeddings that transfer across tasks has made it the foundation of modern embedding models, multimodal AI, and self-supervised pretraining.

contrastive learningsimclrcontrastive lossself supervised contrastiveclip training

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.