ML Systems Lab Open interactive version →
Intermediate 45 min read SimCLRcontrastive learningdata augmentationprojection headbatch size

SimCLR

Data augmentation, projection head, large-batch contrastive learning, SimCLRv2

A batch of 256 images becomes 512 views. Each image passes through ResNet-50, producing a 2048-dimensional representation h. A 2-layer MLP maps h to a 128-dimensional z. NT-Xent loss runs on z. At fine-tuning time, the MLP is thrown away and a linear layer attaches to h. That discard is the central puzzle of SimCLR: something you train and then immediately delete turns out to be critical.

The key to SimCLR's performance is not the architecture and not the loss—it is the augmentation composition. Random crop plus color jitter plus Gaussian blur forces the encoder to produce representations invariant to photometric and spatial perturbations. Ablate random cropping and accuracy drops sharply. Ablate color jitter and it drops further. Two random crops of the same 224×224 image can overlap by as little as 10% of the original area; the encoder must recognize the same object despite seeing drastically different local regions, which means texture matching fails and semantic encoding becomes necessary.

The projection head protects the encoder from a destructive force. Contrastive loss pressures representations to be invariant to augmentations. Color invariance is useful for the pretext task but harmful downstream—it destroys medical imaging features, defeats texture-based recognition, and removes color cues. The head takes this damage so the encoder does not have to. The encoder retains more information precisely because the loss does not reach it directly. This is not a subtle effect: removing the head and applying NT-Xent directly to h drops linear probe accuracy by roughly 10 percentage points.

SimCLR's practical bottleneck is the large-batch dependency. Good performance requires 4,096–8,192 batch size, which demands 32+ TPU cores for 100 epochs. This is not a fundamental constraint of contrastive SSL—it is an artifact of using in-batch negatives. MoCo solves this structurally with a momentum encoder and queue, decoupling negative count from batch size entirely.

NOT this. "You need a huge batch size for contrastive learning" is wrong—MoCo achieves the same representation quality at batch size 256 on a single 8-GPU machine. SimCLR's large-batch requirement is specific to the in-batch negative design, not to contrastive learning as a paradigm. Understanding why MoCo's queue solves the problem that SimCLR's batch size created is the conceptual test.

Key points

Takeaway

SimCLR's projection head is discarded at fine-tuning not out of habit but because the contrastive loss forces it to absorb destructive invariances—color, crop, blur—that would harm downstream tasks if they reached the encoder. The augmentation strategy is the actual performance driver: random crop forces semantic encoding by making local texture matching geometrically impossible, and this principle—not the architecture—is what transfers to new domains.

Recap

Check your understanding

Q1. Select the two true statements about what happens if you remove SimCLR's projection head and apply NT-Xent directly to the encoder's output.

Q2. A team replicates SimCLR on a proprietary medical image dataset and finds it does not benefit from the color jitter augmentation that is critical for ImageNet. Explain why and what they should do instead.

Q3. Explain the information bottleneck interpretation of the projection head. What information does each layer encode?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →