Unit 2 of 7 · about 4 hours · derive, measure

Temperature, negatives and positive construction

Temperature and batch size set the difficulty of the discrimination game. The positive construction declares which variation the representation must ignore.

You'll be able to

  • Derive the sharpening of logits and gradients, and predict saturation at small .
  • Explain how batch size sets the negative count and when longer training closes the gap.
  • Build positives by augmentation composition and state the invariance each transform declares.

Covers

Temperature and batch-negative effectsPositive and negative construction
1

Read

In this order, only the parts listed

0 of 3 done

  1. Temperature and normalizationSimCLR - A Simple Framework for Contrastive Learning of Visual Representations

    Section 5.1, Table 5: 0.05, 0.1, 0.5 and 1.0 with L2 normalization; best Top-1 64.4 at ; the hard-negative weighting sentence

  2. Batch size and training lengthSimCLR - A Simple Framework for Contrastive Learning of Visual Representations

    Sections 2.2 and 5.2 with Figure 9: batch sizes 256 to 8192 with 16,382 negatives per positive at 8192; larger batches help early and the gap shrinks with longer training

  3. Augmentation compositionSimCLR - A Simple Framework for Contrastive Learning of Visual Representations

    Section 3.1 with Figures 5 and 6: single transforms fail while crop plus color distortion wins; color histograms alone suffice as a shortcut

2

Focus on

  • Dividing by multiplies every logit gap. Small sharpens toward ; large flattens toward uniform.
  • The positive-logit gradient is . Easy pairs saturate near zero gradient at small , so hard negatives drive learning.
  • Negatives per positive equal : 510 at batch 256 and 16,382 at batch 8192. Longer training closes much of the batch gap.
  • Random crop plus color distortion wins because it blocks the color-histogram shortcut, not because either transform is strong alone.
Common mistakes · 3
  • Pushing ever lower. Below 0.1 easy pairs saturate and a few hard negatives dominate; Table 5 drops from 64.4 at 0.1 to 59.7 at 0.05.
  • Assuming bigger batches always win. Figure 9 shows large gains at 100 epochs that mostly disappear with longer training on randomly resampled batches.
  • Letting labels choose positives and still calling the method self-supervised. SimCLR positives are two views of one image; once class labels pick positives, it is supervised contrastive learning and must be compared as such.
3

Try it yourself

Closed-book, before checking anything

Closed-book, write the NT-Xent gradient for the positive similarity. For similarities , compute the softmax with gradient -0.335, and the gradient of about -0.0005.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Similarities at : what is the positive probability?Answer

    . The remaining mass splits 0.245 and 0.090.

  2. 2.What happens to easy-pair gradients as goes to 0?Answer

    The softmax saturates to one-hot, so goes to 0 for decided pairs and learning concentrates on the remaining hard pairs; too small stalls training.

  3. 3.Batch 8192 gives how many negatives per positive, and why?Answer

    16,382. The batch holds views; excluding the anchor and its positive leaves negatives.

  4. 4.Positive-identification accuracy is near perfect but linear evaluation is poor. What went wrong?Answer

    The task is solvable by shortcut, such as color histograms under crop-only augmentation. Composition makes pairing harder and representations better.

5

Practice

  • TensorTonic: Implement Symmetric CLIP Contrastive Loss

    Named problem on the free language-modeling-from-scratch plan: implement the two-directional loss over an image-text similarity batch.

    Transfer your NT-Xent derivation: CLIP swaps augmentation pairs for image-text pairs and averages both softmax directions.

You're done when

You predict -sharpening and batch-size effects from the formulas, and your two-directional implementation passes the page tests.

Only when you can do this without notes.

Leads to

Notes

Resources · 1 for this unit, 7 more in the section
  • SimCLR - A Simple Framework for Contrastive Learning of Visual RepresentationsChen, Kornblith, Norouzi and Hinton (ICML 2020) · required

    Use Section 2.1 Eq. (1) and Algorithm 1 for NT-Xent, 2.3 for the linear-evaluation protocol, 3.1 with Figures 5-6 for augmentation composition and shortcuts, 4.2 for the projection head, and 5.1-5.2 with Table 5 and Figure 9 for temperature and batch-size effects.

Also in this section

  • Understanding Deep Learning - representation foundationsSimon J. D. Prince · primary

    Use 9.3.6-9.3.7 for transfer and self-supervision, 12.9-12.10 for image transformers, and 13.1-13.4 plus 13.10 for GNN vocabulary. Open notebooks 9.4, 12.4 and 13.1 only when a figure or mechanism is unclear.

  • D2L - Vision TransformerD2L authors · required

    Use vision-transformer.md for patch extraction, patch embeddings and a tested small encoder. Add a compact SimCLR-style or paired-data contrastive objective in the explicit training loop from Sections 2 and 3.

  • Stanford CS231n - transformer and self-supervised assignment sliceStanford University · support

    Use only the Assignment 3 components for transformers, self-supervised learning, CLIP or DINO that directly test representation and pairing. Keep the controlled local evaluator as the gate.

  • TensorTonic - patchify and symmetric CLIP lossTensorTonic · support

    Solve only Patchify a Batch of Images and Implement Symmetric CLIP Contrastive Loss. Transfer both into the controlled experiment and preserve local leakage and collapse tests.

  • Deep-ML candidate - InfoNCE LossDeep-ML · optional

    If the platform admission check passes, use problem 384 once after deriving the objective. Add local tests for temperature extremes, missing positives, duplicate pairs and normalized versus unnormalized embeddings.

  • CLIP - Learning Transferable Visual Models From Natural Language SupervisionRadford et al. (OpenAI, ICML 2021) · required

    Use Section 2.3 for the symmetric image-text objective and learned temperature, 2.5 for batch size and temperature limits, and 3.1.2 with 3.1.4 for zero-shot transfer and prompt ensembling.

  • SimSiam - Exploring Simple Siamese Representation LearningChen and He (CVPR 2021) · support

    Use Figure 2 and Table 1 for collapse under removed stop-gradient or predictor, including the per-channel spread diagnostic.