Maps to: UC Berkeley CS294-158 Deep Unsupervised Learning (Spring 2024), Lecture 7 · Thu 2/29/2024 · Self-Supervised Learning, third part (slides 187–318): text–image models (CLIP, LiT, SigLIP, FLIP, SLIP, CoCa, ImageBind, BLIP-2); reinforcement learning and control (CURL, R3M, MVP, MTM, Masked World Models, Multi-View MAE) — the “representation learning in RL” topic of earlier offerings; language (predicting neighbouring context, co-occurrence counts and SVD, n-gram models, word2vec, GloVe, BERT, RoBERTa, T5, UL2). Basis: The slides summarize papers. These notes test the central claim of each part on ShapeWorld, where captions are generated from the images and their distribution is known exactly: zero-shot classification and retrieval have a known ceiling (100%), the Bayes-optimal masked-language model can be computed by enumerating all 25,600 caption states, and n-gram models can be compared with the exact entropy of the caption language. For control, a small visual task (ReachWorld) is built from ShapeWorld frames so that every encoder of Lectures 11–15 can be tried as a frozen policy input. Code:
code/lecture15/(4 scripts +language_ssl.py+multimodal_ssl.py; PyTorch (CPU); script 03 runs in seconds; 01 and 04 take 8–40 minutes the first time and under a minute afterwards; the control script 02 about 5 minutes on every run, as its policies are not cached) Reading time: 3.5 hours including running the code
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Explain CLIP: two towers, a contrastive loss over a batch of image–caption pairs, and zero-shot classification by comparing an image with captions; why prompt ensembles help.
- Compare CLIP’s softmax loss with SigLIP’s sigmoid loss, and explain LiT (a locked pretrained image tower) — and when locking hurts.
- Describe the other text–image designs on the slides (FLIP, SLIP, CoCa, ImageBind, BLIP-2) by what they add to CLIP.
- Explain how self-supervised representations are used for control (CURL, R3M, MVP, MTM, MWM) and why the invariances that help recognition can hurt a policy.
- Explain word2vec and GloVe as models of co-occurrence (skip-gram with negative sampling factorizes a shifted PMI matrix), and what “distributional semantics” can and cannot learn.
- Explain BERT (masked tokens, 15%, the 80/10/10 rule), RoBERTa (dynamic masking), T5 (text-to-text, span corruption) and UL2, and what a bidirectional vs a causal objective puts into a sentence vector.
0.2 Prerequisites and scope
| Assumed | Introduced here | Developed later |
|---|---|---|
| Lectures 13–14 (pretext tasks, InfoNCE, SimCLR, the probe protocol) | CLIP, SigLIP, LiT; ReachWorld and behaviour cloning on frozen features | large language models (Lecture 16) |
| Lecture 4 (Transformers, tokens, ShapeWorld captions) | the exact caption distribution (CaptionWorld) | multimodal LLMs: LLaVA, Flamingo, BLIP-2 in depth (Lecture 22) |
| Lecture 1 (captions carry 11.97 bits) | n-gram, PPMI-SVD, word2vec, GloVe; BERT, GPT and span corruption on captions |
0.3 Map
§1 CLIP: contrastive learning of images and captions; zero-shot classification ← code 01, Parts 1-2
§2 variations: SigLIP, LiT, FLIP, SLIP, CoCa, ImageBind, BLIP-2 ← code 01, Parts 1, 3-4
§3 self-supervised representations for control ← code 02
§4 language before Transformers: n-grams, counts, word2vec, GloVe ← code 03
§5 language with Transformers: BERT, RoBERTa, T5, UL2 ← code 04
§6 summary §7 pitfalls §8 exercises §9 further reading §10 next lecture
0.4 Notation
an image, a caption (16 words for ShapeWorld); , the image and text towers, , ; a learned temperature (logit scale), a learned bias. A “prompt” is a caption written for a class. PMI.
0.5 How the experiments are run
- Pairs. Lecture 13’s 10,000 unlabeled training images, each with its ShapeWorld caption (“a huge ring at the top left and a tiny square at the bottom center.”): the caption names both shapes’ kinds and sizes, and the third of the panel in which each centre lies. Test: the 2,000 test images and their captions.
- Towers. Image: Lecture 13’s CNN encoder (128-d read-out) + a linear projection to 64; text: a 2-block bidirectional Transformer over the 16 words with a [CLS] token + a linear projection. 3,000 steps.
- The caption language exactly. A caption is a function of 8 word slots (size, kind, row word, column word per panel). Big and huge shapes always sit in the middle centre, so a panel has 20 (size, row, column) states and a caption 64 × 20 × 20 = 25,600 states; enumerating them gives the exact entropy (11.97 bits, Lecture 1) and the exact predictive distribution of any masked words.
- Probes and seeds as in Lectures 13–14; reruns print identical numbers.
1. CLIP: contrastive learning of images and captions
1.1 The method
CLIP (Radford et al., 2021) trains an image tower and a text tower so that, in a batch of image–caption pairs, each image is most similar to its own caption among the captions, and each caption to its own image — Lecture 14’s InfoNCE in both directions, with the matrix of cosine similarities times a learned temperature:
The slides’ dataset story: existing captioned datasets were small or noisy (YFCC100M’s “captions” are often file names), so OpenAI built 400 million (image, text) pairs from web searches for 500,000 queries. The payoff is zero-shot transfer: to classify into classes “dog”, “cat”, …, embed the prompts “a photo of a dog”, “a photo of a cat”, … and pick the class whose prompt is most similar to the image. No labeled example is needed; the classifier is written in language. CLIP’s paper found prompt engineering (“a photo of a {label}, a type of pet”) and prompt ensembling (averaging the embeddings of ~80 templates) worth several points. CLIP’s towers became components of other systems (unCLIP / DALL·E 2’s image embeddings, LLaVA’s vision encoder — Lectures 12 and 22).
1.2 Experiment: zero-shot classification and retrieval (script 01, Part 1)
Zero-shot classification of the left shape’s kind (8 classes) and size (4), by prompts only; retrieval among the 2,000 test pairs (a retrieved caption with the same text counts as correct, so the ceiling is 100%). “Ensemble”: the average embedding of 64 captions drawn from the exact caption distribution conditioned on the class; “one prompt”: “a big ⟨kind⟩ at the middle center and a big ⟨kind⟩ at the middle center.”
| model | in-batch match | zero-shot kind (ensemble) | zero-shot kind (one prompt) | zero-shot size (ensemble) | image → text R@1 | text → image R@1 |
|---|---|---|---|---|---|---|
| CLIP, batch 16 | 98.7% | 83.5% | 74.2% | 74.5% | 83.7% | 81.6% |
| SigLIP, batch 16 | 98.3% | 79.7% | 62.5% | 63.8% | 68.6% | 70.8% |
| CLIP, batch 64 | 96.8% | 92.9% | 75.8% | 88.6% | 99.9% | 100.0% |
| SigLIP, batch 64 | 96.8% | 89.3% | 57.4% | 86.4% | 99.9% | 100.0% |
| CLIP, batch 256 | 89.3% | 99.1% | 79.7% | 92.7% | 100.0% | 100.0% |
| SigLIP, batch 256 | 89.3% | 96.0% | 58.9% | 89.5% | 100.0% | 100.0% |
- Zero-shot works: 99.1% on the kind without a single label, and perfect retrieval from batch 64 on.
- Prompt ensembling matters a lot: a single prompt gets 57–80%, the ensemble 80–99%. One prompt commits to one right panel, one size, one position; the ensemble averages them out, leaving the direction that means “the left one is a triangle”. This is the same reason CLIP averages 80 templates.
- Bigger batches help (83.5% → 99.1%): more negatives per step, as in Lecture 14 — even though the in-batch matching task gets harder (98.7% → 89.3%).
1.3 What language puts into the image tower (script 01, Part 2)
| representation | left kind | size | top / bottom | same kind | left kind, 10 / class |
|---|---|---|---|---|---|
| CLIP batch 16, image tower | 100.0% | 100.0% | 95.2% | 57.4% | 88.5% |
| CLIP batch 256 | 100.0% | 100.0% | 89.0% | 58.8% | 95.1% |
| SigLIP batch 16 | 100.0% | 100.0% | 92.5% | 57.8% | 87.4% |
| SigLIP batch 256 | 100.0% | 100.0% | 82.0% | 55.3% | 95.9% |
The best few-label image features of Lectures 13–15 (95–96% with 10 labels per class; Lecture 14’s best was 90.1%). This is “weak supervision”: the captions name the attribute we probe. Language supervision is self-supervision only in the sense that nobody labeled the pairs for this task — the web did.
2. Variations on CLIP
- SigLIP (Zhai et al., 2023) replaces the softmax over the batch by an independent sigmoid per pair: every (image, caption) pair is a binary “do they belong together?” problem, with , . No normalization across the batch: simpler to distribute across devices, and the paper reports better results at small batch sizes. Plan vs reality: in our runs the sigmoid loss was slightly worse at every batch size (§1.2: 79.7 / 89.3 / 96.0% vs 83.5 / 92.9 / 99.1%) and much worse with a single prompt; its image tower probes as well or better with 10 labels (95.9%). With 15 negatives per positive (batch 16) the sigmoid’s per-pair decisions may lack the comparative signal the softmax provides.
- LiT (Zhai et al., 2022): “locked-image tuning” — take a strong pretrained image model, freeze it, train only the text tower to match it. Cheap, and on ImageNet better than training both towers from scratch, because the image tower was pretrained on far more labeled images than the image–text data contain.
- FLIP (Li et al., 2023): randomly mask 50–75% of the image patches during CLIP training (MAE’s trick): 2–4× faster per epoch, so more epochs fit the same compute.
- SLIP (Mu et al., 2022): add a SimCLR loss on the image tower to CLIP’s loss.
- CoCa (Yu et al., 2022): a contrastive loss and a captioning loss (an encoder–decoder with a text decoder that cross-attends to the image); the slides cite 91% ImageNet top-1 after fine-tuning, trained from scratch on JFT-3B (with templated class-name captions) and ALIGN.
- ImageBind (Girdhar et al., 2023): one embedding space for six modalities, trained only with (image, X) pairs and InfoNCE — images “bind” audio, depth, thermal and IMU data to text without any (audio, text) pairs.
- BLIP-2 (Li et al., 2023): connect a frozen image encoder and a frozen LLM through a small Q-Former (learned queries that cross-attend to the image), pre-trained in two stages — first image–text contrastive (ITC), image-grounded text generation (ITG) and image–text matching (ITM, with hard negatives), then generative training through the frozen LLM; 129M images with captions filtered and re-generated by a captioner (CapFilt). Lecture 22 builds models of this kind.
2.1 LiT on ShapeWorld (script 01, Part 3)
Lock a pretrained image tower from an earlier lecture and train only the text tower and the image projection:
| image tower | its linear probe: kind | … size | zero-shot kind | zero-shot size | image → text R@1 | text → image R@1 |
|---|---|---|---|---|---|---|
| CLIP from scratch (both towers trained) | 100.0% | 100.0% | 99.1% | 92.7% | 100.0% | 100.0% |
| locked: SimCLR, batch 256 (Lecture 14) | 100.0% | 100.0% | 66.3% | 77.6% | 74.0% | 81.7% |
| locked: MAE 75% (Lecture 13) | 94.4% | 93.7% | 72.2% | 68.7% | 97.5% | 96.2% |
| locked: diffusion U-Net at = 0 (Lecture 11) | 97.2% | 98.2% | 71.1% | 69.4% | 97.0% | 95.9% |
Plan vs reality: LiT was far below CLIP from scratch (zero-shot kind 66–72% vs 99.1%), although every locked tower makes the kind linearly readable (94–100% with 4,000 labels). Two lessons. (1) A locked tower can only be aligned with what it keeps: SimCLR discarded position (Lecture 14: top/bottom 63%), and the captions describe position, so retrieval — which needs every word to match — stays at 74%, while the position-keeping MAE and U-Net retrieve 96–98%. (2) Zero-shot accuracy through a learned linear projection of frozen features trained with a contrastive loss on 10,000 pairs is not the same as a probe trained on 4,000 labels of the target: the contrastive signal spreads over everything the captions say. LiT’s success on ImageNet comes from a tower pretrained on billions of labeled images whose features already align with words; ours were not.
2.2 Compositional generalization (script 01, Part 4)
Remove every training pair whose left panel holds a huge triangle (324 of 10,000), train CLIP, and test zero-shot on the 73 test images that have one:
| CLIP, batch 256 | huge triangles: kind | huge triangles: size | all other images: kind | … size |
|---|---|---|---|---|
| trained on all pairs | 100.0% | 91.8% | 99.0% | 92.7% |
| huge-triangle-left pairs removed | 100.0% | 100.0% | 99.1% | 92.7% |
Nothing is lost: “huge” and “triangle” were learned separately (from huge squares, small triangles, and huge triangles on the right) and combine at test time. In a world whose attributes are independent by construction, a contrastive model composes them freely; the failures of real CLIP models at composition (attribute binding, counting, spatial relations) come from data in which such combinations are rare and correlated with other cues.
3. Self-supervised representations for control
3.1 The slides’ methods
- CURL (Laskin, Srinivas & Abbeel, 2020): a contrastive loss (MoCo-style, random crops) on the RL agent’s encoder, trained alongside the RL objective; pixel-based control approaches the efficiency of state-based control.
- R3M (Nair et al., 2022): pretrain a ResNet on Ego4D human videos (3,500 hours, language-annotated) with (1) time-contrastive learning — frames close in time are closer than frames far apart, and frames of the same video closer than frames of other videos; (2) video–language alignment that should increase over the course of a video; (3) L1 / L2 penalties for compact features. Then a policy on the frozen features, learned from few demonstrations.
- MVP (Xiao, Radosavovic et al., 2022): an MAE pretrained on 700K frames of human–object interaction videos (Epic-Kitchens, 100 Days of Hands, Something-Something); a policy trained with PPO on the frozen features + proprioception, on a new benchmark (PixMC). Self-supervised features on in-the-wild data beat supervised ImageNet features and approach an oracle with hand-engineered state.
- MTM (Wu et al., 2023): treat trajectories (states, actions, returns, images) as token sequences and train a Transformer with random masking across time and modalities; missing modalities are simply masked, so heterogeneous datasets (1% with actions) can be used; one model then serves as policy, dynamics model or return predictor.
- Masked World Models and Multi-View MAE (Seo et al., 2022–2023): an MAE with convolutional feature masking (+ reward prediction) learns the visual representation, a recurrent world model learns dynamics on top; masking whole camera views teaches cross-view information and gives viewpoint-robust policies, transferred zero-shot from simulation to a real robot with hand-held cameras.
The common recipe: pretrain a visual encoder on lots of unlabeled (often out-of-domain) video, freeze it, learn the policy from little data. What the encoder should keep is now set by the policy’s needs.
3.2 Experiment: ReachWorld (script 02)
The task: the left panel shows the agent, the right panel the goal, each a tiny shape whose kind is random in every episode; the agent moves one pixel per step (up / down / left / right) and succeeds when its position in the left panel equals the goal’s in the right panel (8 × 8 positions each; the expert needs at most 14 steps, 7 on average). Every frame is a valid ShapeWorld image, so every encoder of Lectures 11–15 has seen such pictures — trained to tell kinds apart (here a nuisance), not to report exact positions (here everything). The policy is an MLP on standardized frozen features, trained by behaviour cloning on 10 / 50 / 250 expert episodes (49 / 264 / 1,294 transitions); success = reaching the goal within 30 steps, over 500 test episodes. Two read-outs per encoder: the per-panel average the probes use, and the full spatial feature map.
| encoder (frozen) | read-out | dim | 10 episodes | 50 episodes | 250 episodes |
|---|---|---|---|---|---|
| oracle: true coordinates (one-hot) | — | 32 | 17.4% | 61.8% | 100.0% |
| raw pixels | — | 288 | 18.6% | 41.8% | 70.0% |
| random CNN (untrained) | per-panel average | 128 | 11.0% | 21.0% | 39.2% |
| spatial map | 1,152 | 16.2% | 30.2% | 65.2% | |
| MAE 75% on ShapeWorld (Lecture 13) | per-panel average | 128 | 27.0% | 56.4% | 76.6% |
| spatial map | 2,048 | 23.4% | 54.2% | 81.2% | |
| SimCLR batch 256 (Lecture 14) | per-panel average | 128 | 5.6% | 10.6% | 10.6% |
| spatial map | 1,152 | 8.4% | 22.8% | 61.2% | |
| CLIP batch 256 image tower (§1) | per-panel average | 128 | 13.4% | 31.6% | 65.4% |
| spatial map | 1,152 | 14.2% | 45.0% | 78.6% | |
| diffusion U-Net, = 0 (Lecture 11) | per-panel average | 128 | 12.6% | 40.4% | 81.6% |
| MVP-style: MAE on this world’s frames | per-panel average | 128 | 34.8% | 71.0% | 87.2% |
| spatial map | 2,048 | 30.8% | 71.6% | 87.0% | |
| time-contrastive, negatives from other episodes | per-panel average | 128 | 8.6% | 13.6% | 26.8% |
| spatial map | 1,152 | 9.6% | 12.4% | 32.0% | |
| R3M-style: + same-episode frames ≥ 3 steps away | per-panel average | 128 | 8.8% | 15.4% | 34.2% |
| spatial map | 1,152 | 7.0% | 16.6% | 39.0% | |
| CNN trained end-to-end on the demonstrations | — | — | 20.8% | 63.8% | 92.6% |

- A representation is good for a task, not in general. SimCLR’s features read the kind perfectly (Lecture 14: 100%) and give a useless policy (10.6% even with 250 episodes): its pooled read-out was trained to ignore position. Representations trained to reconstruct keep position — MAE 76.6–81.2%, the diffusion U-Net 81.6% — and beat raw pixels (70.0%).
- The information is often still there, below the read-out: SimCLR’s and CLIP’s spatial maps recover 61.2% and 78.6%. Choosing what to read out of a frozen network is part of using it (MVP and R3M feed different layers and poolings to their policies).
- In-domain pretraining buys data efficiency: an MAE pretrained on 10,000 unlabeled frames of this world is the best frozen encoder (87.2%) and beats training the whole network end-to-end with 10 and 50 demonstrations (34.8% vs 20.8%; 71.0% vs 63.8%). With 250 demonstrations end-to-end training wins (92.6%) — MVP’s story in miniature.
- Even perfect features need data: the oracle’s coordinates give 17.4% with 10 episodes — the MLP must still learn to compare two positions.
- Plan vs reality. The time-contrastive encoders (R3M’s first objective, without its language alignment) were poor (26.8–39.0%). With negatives from other episodes only, consecutive frames can be matched by what is constant within an episode — the two shapes’ kinds — instead of the agent’s position; adding frames of the same episode at least 3 steps away as negatives helped only a little (26.8% → 34.2%). Our 2,000 trajectories of at most 15 frames are a far cry from Ego4D’s 3,500 hours.
4. Language before Transformers
4.1 Predicting neighbouring context
The slides’ language section starts where self-supervision on text started: a word is characterized by the company it keeps. A co-occurrence matrix (how often word appears within a window around word ), factorized by SVD, gives word vectors (latent semantic analysis); its problems — sparsity, cost, rare words, the dominance of frequent words — have fixes (PPMI, TF-IDF) but remain. n-gram language models estimate by counting. word2vec (Mikolov et al., 2013) learns vectors by predicting: CBOW predicts the centre word from the average of its context words; skip-gram predicts each context word from the centre word, and replaces the softmax over the vocabulary by negative sampling: raise for observed pairs, lower for random words drawn from the unigram distribution to the power 3/4. GloVe (Pennington et al., 2014) goes back to counts: fit by weighted least squares; ratios of co-occurrence probabilities encode meaning.
A precise link (Levy & Goldberg, 2014): skip-gram with negative sampling, at its optimum, sets — it is an implicit factorization of the shifted PMI matrix, the same object count-based methods factorize explicitly.
4.2 Experiment: the caption language (script 03)
n-gram models (add-0.01 smoothing) trained on the 10,000 training captions, bits per test caption (exact entropy 11.97):
| n | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| test bits / caption | 63.76 | 15.66 | 15.66 | 15.66 | 15.18 | 14.79 | 14.81 | 14.86 | 12.54 | 13.35 |
| train bits / caption | 63.78 | 15.68 | 15.68 | 15.67 | 15.15 | 14.72 | 14.73 | 14.71 | 11.78 | 11.65 |
Every step of this curve is a regularity of the language. Bigrams to 4-grams are identical: the words between the informative slots are fixed template words (“at the”, “and a”), so seeing more of them adds nothing. 5- and 6-grams reach back from a position word to the size word (big and huge shapes are always “middle center”). Only a 9-gram spans the copy rule (kind 1 at position 2, kind 2 at position 10), and gets within 0.57 bits of the exact entropy; a 10-gram starts to overfit (train 11.65, test 13.35). A count-based model needs an exact match of a long context; that is the data hunger neural language models remove.
Word vectors (16 dimensions; SVD: 8; all vectors mean-centred before comparing — raw GloVe vectors share one dominant direction, every pair of words having cosine ≈ 0.99):
| window | method | slot purity | nearest neighbour of huge / tiny / triangle / top / left | big : huge :: small : ? |
|---|---|---|---|---|
| 2 | SVD of raw counts | 87% | big / big / plus / bottom / right | tiny |
| 2 | SVD of PPMI | 91% | big / small / ring / bottom / right | tiny |
| 2 | word2vec skip-gram | 100% | tiny / huge / ring / bottom / right | tiny |
| 2 | word2vec CBOW | 96% | small / big / square / bottom / right | tiny |
| 2 | GloVe | 74% | small / huge / plus / left / right | square |
| 8 | SVD of raw counts | 87% | big / small / disk / bottom / right | tiny |
| 8 | SVD of PPMI | 61% | center / small / and / bottom / right | tiny |
| 8 | word2vec skip-gram | 91% | big / small / cross / bottom / right | tiny |
| 8 | word2vec CBOW | 91% | big / small / cross / bottom / right | tiny |
| 8 | GloVe | 39% | big / small / right / bottom / top | tiny |
(“Slot purity”: the fraction of the 27 words whose nearest neighbour is of the same type — size, kind, row word, column word or function word. Every method also solves “top : bottom :: left : ?” = right and “left : right :: top : ?” = bottom.)
- Words cluster by role for every method (purity up to 100%): sizes with sizes, kinds with kinds — they occupy the same slots.
- Within a role, the window decides what is learned. With a window of 2, all four size words have identical contexts (“a ⟨size⟩ ⟨kind⟩ at”), so which size is nearest to “huge” is noise (tiny, small or big). With a window of 8 the size–position correlation enters the window and every good method finds huge ≈ big (both always “middle center”) and tiny ≈ small (both can sit anywhere). That is distributional semantics in the exact sense: these words are distributionally similar in this language, and nothing else.
- The eight kinds stay interchangeable for every method: their contexts are identical except through the copy rule, eight words away. The “triangle” neighbours are arbitrary.
- The analogy “big : huge :: small : tiny” is solved, but on this corpus it is close to a coincidence of the size words’ geometry; with a window of 2 the four size words are equivalent.
Skip-gram factorizes shifted PMI: the correlation between the learned and PMI (PMI computed against the noise distribution) over the observed word pairs is 0.80 (window 2) and 0.92 (window 8); mean absolute difference 0.15 nats.
5. Language with Transformers: BERT, RoBERTa, T5, UL2
5.1 The methods
- BERT (Devlin et al., 2018): a bidirectional Transformer encoder pre-trained with (1) masked language modelling — 15% of the tokens are selected; of those, 80% are replaced by [MASK], 10% by a random token, 10% left unchanged (so the model cannot rely on [MASK] being present at fine-tuning time), and the loss counts only selected tokens; (2) next-sentence prediction (50% true next sentence vs random). Pre-trained on BooksCorpus and English Wikipedia (3.3B words), then fine-tuned per task (GLUE), using the [CLS] vector for sentence-level tasks; frozen features also work (named-entity recognition).
- RoBERTa (Liu et al., 2019): the same model trained better — dynamic masking (a new mask each time a sequence is seen; BERT fixed the masks in preprocessing), no next-sentence prediction, larger batches, more data, byte-level BPE (50K tokens).
- T5 (Raffel et al., 2020): every task as text-to-text with a task prefix (“translate English to German: …”), an encoder–decoder, and a span-corruption objective: contiguous spans are replaced by sentinel tokens and the decoder outputs the missing spans. A systematic study of architectures and objectives; its encoder later served as Imagen’s text encoder (Lecture 12).
- UL2 (Tay et al., 2022): a mixture of denoisers — extreme denoising (long spans or high corruption), regular low-corruption spans, and sequential (prefix-LM) denoising — with mode tokens; one model good both for fine-tuning and for few-shot prompting.
5.2 Experiment: masked words against the exact optimum (script 04, Part 1)
A 2-block Transformer (width 64), 3,000 steps, BERT’s 80/10/10 rule. On 2,000 test captions with random masks, bits per masked informative word (the 8 slots; template words are predicted perfectly by everyone):
| masked at test | EXACT, all masked words | EXACT, informative words | BERT trained at 15% | at 40% | at 75% |
|---|---|---|---|---|---|
| 15% | 0.660 | 1.318 | 1.324 | 1.323 | 1.335 |
| 40% | 0.702 | 1.411 | 1.419 | 1.417 | 1.424 |
| 75% | 0.799 | 1.596 | 1.615 | 1.601 | 1.601 |
The tiny BERT is within 0.01–0.02 bits of the Bayes-optimal masked-language model at every ratio, and the training ratio barely matters: each caption is short and fully determined by 8 slots, so every model sees enough masked slots of every kind. Masking 75% of a caption still leaves the question well-posed (1.60 bits per informative word vs 1.32 at 15%) — the text analogue of Lecture 13’s “how much is still predictable” table, and M3AE’s observation that high text masking can work.
5.3 What one vector per caption holds (script 04, Part 2)
Linear probes trained on 2,000 captions’ vectors:
| caption vector | left kind | left size | same kind |
|---|---|---|---|
| bag of words (counts) | 79.1% | 63.3% | 55.0% |
| average of word2vec vectors | 79.8% | 62.5% | 55.8% |
| BERT 15% — [CLS] | 99.5% | 99.9% | 97.3% |
| BERT 40% — [CLS] | 99.2% | 99.7% | 98.8% |
| BERT 75% — [CLS] | 99.0% | 96.3% | 95.7% |
| T5-style span corruption (one span of 4 words) — [CLS] | 100.0% | 99.4% | 94.5% |
| GPT (causal LM) — last token | 100.0% | 99.8% | 73.2% |
| GPT — mean of its 16 word positions | 100.0% | 100.0% | 62.0% |
- Bags of words cannot tell left from right: “a triangle … and a ring” and “a ring … and a triangle” have the same counts (79% on the left kind; the relation at chance).
- Bidirectional objectives make the relation readable (95–99%): to fill in a masked kind, BERT must use the other kind (the copy rule), so each kind token’s representation comes to encode the other’s identity, and [CLS] — which attends to both — exposes the comparison.
- The causal LM’s vectors do not (73%, 62% averaged), although GPT predicts the second kind from the first just as well. Its states hold what helps predict the next word; after the second kind has been predicted, “were they the same?” is no longer needed by anything. What is linearly readable is what the objective needed at that position.
5.4 Static vs dynamic masking (script 04, Part 3)
| model | final training loss (bits / masked word) | fresh masks, training captions | test captions |
|---|---|---|---|
| BERT 15%, static masks (original BERT) | 0.490 | 0.779 | 0.748 |
| BERT 15%, dynamic masks (RoBERTa) | 0.611 | 0.677 | 0.664 |
(Exact optimum on the test masks: 0.660.) With masks fixed once, the model sees the same 15% of each caption 38 times and memorizes them: a lower training loss, a worse model on fresh masks. A new mask every time is a free form of data augmentation — RoBERTa’s change.
6. Summary
- CLIP turns captions into classifiers: zero-shot 99.1% on the left kind without a label, perfect retrieval from batch 64, with prompt ensembles far better than single prompts (57–80% → 80–99%) and bigger batches better. Its image tower gives the best few-label features of Lectures 13–15 (95–96% with 10 labels per class) — the captions name exactly the attribute we probe.
- SigLIP’s sigmoid loss was slightly worse than the softmax at every batch size here; LiT with locked towers stayed far below CLIP from scratch (66–72%): a locked tower can only align what it kept. Composition of independent attributes worked: huge triangles were recognized without a single training example.
- For control, what a representation keeps matters more than its probe score. SimCLR’s pooled features (100% on the kind) gave a 10.6% policy; position-keeping reconstruction features 77–82%; their spatial maps recovered much of what pooling had discarded; an in-domain MAE (MVP-style) beat end-to-end training with 10–50 demonstrations. Time-contrastive pretraining did poorly in our setup.
- Count-based language models need = 9 to reach the copy rule (12.54 vs 11.97 bits); word vectors cluster words by role, and the context window decides what else can be learned (huge ≈ big only with a window of 8); skip-gram’s dot products track the shifted PMI matrix (correlation 0.80–0.92), as Levy & Goldberg proved for the optimum.
- A tiny BERT is within 0.01–0.02 bits of the exact optimal masked-language model; bidirectional objectives make the copy relation readable from one vector (95–99%), a causal LM’s vectors do not (62–73%); static masks overfit, dynamic masks (RoBERTa) fix it.
7. Common pitfalls
- One prompt for zero-shot classification. A single caption commits to irrelevant details (the other panel, a size, a position); ensembles of prompts average them out (57–80% → 80–99% here).
- Expecting a locked tower to align with everything the text says. LiT can only align what the tower kept; a position-invariant tower cannot match position words.
- Calling caption supervision “unsupervised”. Captions name the concepts; that is why CLIP’s features excel at exactly those concepts.
- Using recognition features for control without asking what the policy needs. A pooled, shift-invariant representation can be useless for a policy that must act on positions.
- Time-contrastive learning with only other-video negatives. It can match frames by whatever is constant within an episode — a shortcut; negatives from the same video far apart in time remove it (R3M).
- Over-reading word analogies. On a corpus where words are distributionally identical, “analogies” can be geometry noise; check what the contexts actually contain.
- Comparing sentence vectors from different positions as if they were the same thing. A causal LM’s last token, a BERT [CLS], and a mean of states hold different information.
- Static masks. They overfit; mask dynamically.
8. Exercises
Exercise 1 (zero-shot as a classifier). Show that zero-shot classification with prompt embeddings is a linear classifier on the normalized image embedding , and explain why averaging the embeddings of many prompts of class can only help when the prompts differ in class-irrelevant ways.
Answer
The prediction is : a linear classifier with weight vectors (and no bias). A single prompt’s embedding = (class direction) + (directions of the irrelevant details it happens to mention). Averaging prompts whose irrelevant details vary independently keeps the class direction and shrinks the irrelevant part like (or cancels it if the details are balanced), so the weight vector points closer to the class direction. If all prompts shared the same irrelevant detail, averaging could not remove it.
Exercise 2 (softmax vs sigmoid). For a batch of pairs, how many terms does each loss have, and which quantities must be communicated across devices if the batch is split over devices?
Answer
Both score pairs. The softmax needs, for each image, the normalizer over all captions (and vice versa): each device must see all embeddings of the other modality and the row/column sums require a global reduction. The sigmoid loss is a sum of independent pair terms: devices can exchange embedding chunks in a ring and accumulate their own loss terms, with no global normalization — SigLIP’s efficiency argument.
Exercise 3 (SGNS and PMI — derivation). For one word–context pair with co-occurrence count , negatives drawn from , show that the expected skip-gram objective is maximized at .
Answer
The part of the objective that depends on : . Setting the derivative to zero gives , i.e. . Script 03 measures correlations 0.80–0.92 between the learned dot products and this target.
Exercise 4 (the 9-gram). Explain why bigrams, trigrams and 4-grams give exactly the same bits per caption in script 03, and why the 9-gram is the first to capture the copy rule.
Answer
Between informative slots sit fixed template words: position 3 “at” and 4 “the” follow the kind; 7 “and”, 8 “a” follow the column word. A 2–4-gram context of an informative slot contains only template words or, at most, the slot just before it, which in this language is independent of it (size and kind are independent; row and column words depend on the size, which is 4–5 positions back). The size → row/column dependency needs –6; the second kind (position 10) depends on the first (position 2), eight positions back, so the context must contain 8 words: a 9-gram.
Exercise 5 (BERT’s 80/10/10). Why does BERT not replace all selected tokens by [MASK]? What would a model trained only on [MASK]ed inputs do on a sentence with no [MASK] at all?
Answer
At fine-tuning and feature-extraction time there is no [MASK] token; a model trained only with [MASK] at the predicted positions could learn that only those positions need contextual representations, and its representations of ordinary tokens could be poor or mismatched. Random replacements (10%) force the model to doubt every token; unchanged selected tokens (10%) force it to produce good representations of real tokens too, bridging the train–test mismatch.
Exercise 6 (why the causal vector forgets the relation). In script 04, GPT predicts the second kind from the first, so “same kind” information exists inside it at position 10. Why might it not be linearly readable at the last position?
Answer
At position 9 (predicting the kind word at 10) the model must represent the first kind; after the second kind is read, no later prediction depends on whether they matched: the remaining words (position, ”.”), given everything before, do not depend on the relation. Training puts no pressure on later positions to keep a feature that no later prediction needs; residual connections may carry some of it (73% > 56% chance), but not in a clean linear form. A bidirectional model is asked to predict either kind from the other at the same time, which makes the comparison useful everywhere.
Exercise 7 (compositional generalization). In script 01, Part 4, removing “huge triangle on the left” from training did not hurt. Design a world in which it would.
Answer
Make the held-out combination’s appearance not decomposable: e.g. render huge triangles with a distinctive texture or orientation that no other shape uses, or correlate “huge” with “square” in the training data so that the model can use kind to predict size. Then “huge” learned from squares and “triangle” learned from small triangles do not add up to a huge triangle’s image features. Real image–text data have such correlations (attribute–object co-occurrence), which is one source of CLIP’s binding errors.
Exercise 8 (coding). In script 02, give the policy the per-panel average read-out of SimCLR features and the flattened map of a random CNN. Predict the result and check.
Answer
(Run it.) The random map carries positions (65% with 250 episodes alone), SimCLR’s pooled features carry kinds (irrelevant here); the combination should behave like the random map, possibly slightly worse with few demonstrations because the irrelevant dimensions add noise to a small training set.
9. Further reading
From the slides
- A. Radford et al. Learning Transferable Visual Models From Natural Language Supervision (CLIP), ICML 2021; X. Zhai et al. LiT, CVPR 2022; X. Zhai et al. Sigmoid Loss for Language Image Pre-Training (SigLIP), ICCV 2023; Y. Li et al. Scaling Language-Image Pre-training via Masking (FLIP), CVPR 2023; N. Mu et al. SLIP, ECCV 2022; J. Yu et al. CoCa, TMLR 2022; R. Girdhar et al. ImageBind, CVPR 2023; J. Li et al. BLIP-2, ICML 2023.
- M. Laskin, A. Srinivas, P. Abbeel. CURL, ICML 2020; S. Nair et al. R3M, CoRL 2022; T. Xiao, I. Radosavovic et al. Masked Visual Pre-training for Motor Control (MVP), 2022; P. Wu et al. Masked Trajectory Models, ICML 2023; Y. Seo et al. Masked World Models for Visual Control, CoRL 2022; Multi-View Masked World Models, ICML 2023.
- T. Mikolov et al. Efficient Estimation of Word Representations in Vector Space / Distributed Representations of Words and Phrases, 2013; J. Pennington, R. Socher, C. Manning. GloVe, EMNLP 2014.
- J. Devlin et al. BERT, NAACL 2019; Y. Liu et al. RoBERTa, 2019; C. Raffel et al. Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer (T5), JMLR 2020; Y. Tay et al. UL2, ICLR 2023.
Added by these notes
- O. Levy, Y. Goldberg. Neural Word Embedding as Implicit Matrix Factorization, NeurIPS 2014.
- P. Sermanet et al. Time-Contrastive Networks, ICRA 2018.
- M. Yuksekgonul et al. When and Why Vision-Language Models Behave like Bags-of-Words, ICLR 2023 — CLIP’s compositional failures.
10. Next lecture
Lecture 16 (the guest lecture by Hao Liu) turns to large language models: the autoregressive objective at scale, compute , scaling laws and the compute-optimal split between parameters and tokens — which we will fit on a text whose irreducible loss we know exactly — long contexts through blockwise and ring attention, what limits inference (the KV cache, memory bandwidth, MQA / GQA, mixtures of experts), and reasoning by writing out intermediate steps.