Unit 6 of 7 · about 4 hours · explain, implement

Paired modalities: projector heads, alignment and zero-shot retrieval

Paired data aligns two geometries into one shared space. That space supports retrieval and zero-shot transfer, but alignment alone provides no reasoning or grounding.

You'll be able to

  • Explain the symmetric image-text objective over the similarity matrix.
  • Implement the two-directional loss with learned temperature and batched negatives.
  • Run zero-shot retrieval and state the slice limits of the alignment.

Covers

Projector heads and paired-modality alignmentModality imbalance and zero-shot retrieval vocabulary
1

Read

In this order, only the parts listed

0 of 4 done

  1. Symmetric contrastive objectiveCLIP - Learning Transferable Visual Models From Natural Language Supervision

    Section 2.3: possible pairings with maximization of the real-pair similarities; symmetric cross-entropy; temperature as a learned log-parameterized scalar

  2. Scale and temperature limitsCLIP - Learning Transferable Visual Models From Natural Language Supervision

    Section 2.5: minibatch 32,768; initialized to 0.07 and clipped to scale logits by at most 100

  3. Zero-shot transfer and promptsCLIP - Learning Transferable Visual Models From Natural Language Supervision

    Sections 3.1.2 and 3.1.4: zero-shot as text-generated classifier weights; A photo of a {label} gains 1.3 percent, 80-prompt ensembling adds 3.5 percent

  4. Projector heads and CLIP practiceStanford CS231n - transformer and self-supervised assignment slice

    cs231n/simclr/model.py class Model: ResNet-50 backbone giving the 2048-d feature , MLP head giving , both returned L2-normalized; CLIP_DINO.ipynb: get_similarity_no_loop, clip_zero_shot_classifier, CLIPImageRetriever.retrieve

2

Focus on

  • The loss makes decisions per batch: each image picks its text and each text picks its image from options.
  • Temperature is learned, not tuned: log-parameterized, started at 0.07, capped at 100x for stability.
  • Each pair trains against 32,767 in-batch negatives, so every step is a 32,768-way proxy classification.
  • Zero-shot builds the classifier from text at test time. Prompts are model inputs: the default template gains 1.3 percent and 80-prompt ensembling adds 3.5 percent on ImageNet.
Common mistakes · 3
  • Assuming aligned embeddings understand new words. The text encoder embeds prompts; unseen vocabulary and slices degrade, so alignment quality stays slice-dependent.
  • Training one direction only. CLIP optimizes both image-to-text and text-to-image jointly over the same matrix.
  • Mixing up the two evaluation spaces. Zero-shot retrieval must use the shared projected space, because that is where images and texts are compared. For a linear probe, also test the features before the projection; SimCLR Section 4.2 found them better in its setup.
3

Try it yourself

Closed-book, before checking anything

Closed-book, compute the symmetric loss for similarity matrix : row losses 0.1269 and 0.3133 with mean 0.2201 in both directions.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Batch of pairs: how many scores and how many decisions?Answer

    scores; decisions, per direction.

  2. 2.Why does CLIP learn , and with what guardrails?Answer

    It sets the logit range for the softmax; learning avoids tuning it. Init 0.07, clipped at 100x scaling to prevent instability.

  3. 3.What is a zero-shot classifier in CLIP terms?Answer

    Cosine softmax with L2-normalized inputs, text-generated weights, no bias and temperature scaling; the text encoder generates the classifier.

  4. 4.Prompt template plus ensembling: what gains on ImageNet?Answer

    1.3 percent from A photo of a {label}, another 3.5 percent from 80-prompt ensembling.

5

Practice

  • CS231n Assignment 3, Q4: CLIP zero-shot and retrieval

    CLIP_DINO.ipynb: get_similarity_no_loop for the cosine matrix, clip_zero_shot_classifier for prompt-based labels, CLIPImageRetriever.retrieve with top-.

    Precompute image features once in __init__ instead of per query, as the starter-code comment directs.

You're done when

You reproduce 0.2201 by hand, your Q4 functions label and retrieve COCO images, and you can state one slice where you would not trust the alignment.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 6 more in the section

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.

  • 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.

  • 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.

  • 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.