Maps to: UC Berkeley CS294-158 Deep Unsupervised Learning (Spring 2024), Lecture 7 · Thu 2/29/2024 · Self-Supervised Learning, first part (slides 1–85): representations matter, LeCun’s cake, what self-supervised learning is; reconstructing from a corrupted or partial version (denoising autoencoders and their stacked and “emphasized” variants, diffusion features / EmerDiff, context encoders, predicting one view from another: colorization and split-brain autoencoders, tracking emerging from colorization, the masked autoencoder MAE and its masking ratio, BEiT, VideoMAE, SiamMAE, Audio-MAE, MultiMAE, M3AE); “visual common sense” puzzles (relative patch position, jigsaw puzzles, rotation). Basis: The slides on these methods are mostly figures and result tables from the papers. These notes rebuild the argument behind each method and then test it on ShapeWorld, where the Bayes-optimal solution of every pretext task can be computed exactly: the best possible denoiser, the best possible inpainting of masked patches (from all visible pixels, or only from the neighbouring ones), the best colorizer, and the best possible rotation and jigsaw solvers. That separates two questions the papers can only answer together: how well is the pretext task solved? and how useful is what the network learned? Code:
code/lecture13/(4 scripts +ssl_tools.py, the toolkit of Lectures 13–15; PyTorch (CPU); 21 networks of 3,000 steps each, cached; first runs 2–25 minutes per script) 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:
- Say what self-supervised learning is (withhold part of the data, predict it from the rest) and how its result is evaluated: linear probes on frozen features, few-label probes, and fine-tuning.
- Explain the denoising autoencoder: why corruption prevents the trivial identity, the kinds of corruption, “emphasizing corrupted dimensions”, and its link to diffusion models.
- Explain MAE’s design (an encoder that sees only visible patches, a light decoder, a high masking ratio, the loss on masked patches) and argue — with numbers — why images can be masked far more heavily than text.
- Explain why a pixel-wise loss makes inpainting blurry, and why that blur is the optimum, not a failure.
- Explain when colorization teaches semantics, and why L2 colorizations are desaturated.
- Analyse pretext puzzles (relative position, jigsaw, rotation): what makes them solvable, what makes them useful, and how shortcuts break them.
- Read a self-supervised leaderboard: what frozen probes and fine-tuning each measure.
0.2 Prerequisites and scope
| Assumed | Introduced here | Developed later |
|---|---|---|
| Lecture 1 (ShapeWorld with exact , the “find my twin” puzzle and linear probes) | the probe protocol of Lectures 13–15 (ssl_tools.py) | contrastive and joint-embedding methods, JEPA (Lecture 14) |
| Lectures 7–8 (autoencoders, VAEs), Lecture 11 (diffusion as denoising, Tweedie) | DAE, MAE, context encoders, colorization, puzzles | CLIP, self-supervision for control, BERT (Lecture 15) |
| Lecture 4 (Transformers, patch tokens) | exact Bayes-optimal pretext solvers | semi-supervised learning (Lecture 18) |
0.3 Map
§1 why representation learning; what self-supervision is; how it is evaluated
§2 denoising autoencoders ← code 01, Parts 1-2
§3 generative models as feature extractors: diffusion features ← code 01, Part 3
§4 masked autoencoders (MAE) and why images are masked at 75% ← code 02
§5 predicting missing pieces and other views: context encoders, colorization ← code 03
§6 visual common sense: relative position, jigsaw, rotation -- and shortcuts ← code 04, Parts 1-2
§7 the Lecture 13 leaderboard ← code 04, Part 3
§8 summary §9 pitfalls §10 exercises §11 further reading §12 next lecture
0.4 Notation
an image (12 × 24 binary pixels); a corrupted or partial version; , the visible and the masked pixels; an encoder, a decoder or task head. A pretext task is the self-supervised problem the network is trained on; a downstream task is what we want the representation for. Bits are .
0.5 How the experiments are run (the protocol of Lectures 13–15)
- Data. The same 10,000 training images every generative model of Lectures 3–12 was trained on (unlabeled); a labeled pool = the first 4,000 of them with labels; 2,000 test images.
- Four downstream targets: the left shape’s kind (8 classes, the course’s label), its size (4), whether its centre is in the top or bottom half (2), and whether the right panel repeats the left kind — the copy rule (“same kind”, 56.25% yes).
- Read-out. Every encoder produces a feature map; the representation is its average over the left panel concatenated with its average over the right panel (128 numbers for our networks), so “left” stays linearly separable from “right”.
- Probes. A multinomial logistic regression on frozen, standardized features, solved by L-BFGS with a unit Gaussian prior on the weights (no learning rate to tune): with all 4,000 labels, and with 10 labels per class (mean of 5 draws). Fine-tuning: the whole encoder plus a new linear head trained on 10 labels per class (500 Adam steps, mean of 3 draws).
- Networks. One CNN encoder (4 convolutions, 93K parameters) for every convolutional method, one small ViT (4 blocks of width 64, 3 × 3 patches → 32 tokens) for MAE; every pretext network gets the same budget: 3,000 steps of 128 images.
- Exact solvers. Every ShapeWorld image is a pair of panels, each one of 960 possible panel images, coupled only by the kinds. Any evidence that factorizes over pixels — “this pixel is visible and black”, “this pixel was possibly flipped” — gives the exact posterior over the 960 × 960 panel pairs with two matrix products and an 8 × 8 “message” (
ExactPanelPosterior, the same construction as Lecture 11’s exact denoiser). It reproduces Lecture 1’s exact to .
1. Why representation learning, and what self-supervision is
Representations matter. The slides open with Goodfellow’s classic picture: the same data points are hard to separate with a line in Cartesian coordinates and trivial in polar coordinates. A classifier, a policy or a retrieval system is only as good as the coordinates it is given, and deep networks build their coordinates layer by layer, each refining the previous.
The goal of this lecture: pre-train a network so that it can be adapted to a downstream task with little labeled data. Generative models (autoregressive models, flows, VAEs, GANs, diffusion) can do this too — §3 measures it — but this lecture is about methods that are not generative models.
LeCun’s cake. If intelligence is a cake, unsupervised (self-supervised) learning is the cake itself, supervised learning the icing, reinforcement learning the cherry: the number of bits a learner receives per sample is a few for a reward, ~10–10,000 for a label, millions for the data itself. Most of what a system knows has to come from the data.
Self-supervised learning is unsupervised learning in which the data supervises itself: withhold some part of the data and train a network to predict it from the rest. The details — what is withheld, what is predicted, with which loss — define the pretext task. If the pretext task can only be solved by understanding the content, good “semantic” features appear without labels. If it can be solved some other way, they do not.
That last sentence is the lecture’s main theme. Every experiment below asks two separate questions, which real datasets cannot separate but ShapeWorld can:
- How solvable is the pretext task, and how well did the network solve it? (We compute the Bayes-optimal solution.)
- How useful are the learned features for the downstream targets? (Probes and fine-tuning.)
2. Denoising autoencoders
2.1 The idea
A plain autoencoder with a wide code can learn the identity and nothing else. Vincent et al. (2008, 2010) proposed to corrupt the input and ask for the clean version:
The identity no longer works: the network must undo the corruption, which requires knowing what clean data looks like. The geometric picture of the slides: data lie near a low-dimensional manifold; corruption pushes points off it; the denoiser learns to project them back. The corruptions of the paper: masking noise (a random fraction of input components set to 0), salt-and-pepper noise (a fraction set to random extremes) and additive Gaussian noise.
Two refinements from the paper:
- Emphasizing corrupted dimensions. Weight the reconstruction loss by on the corrupted components and on the others; “full emphasis” (, ) only scores what had to be inferred. (MAE’s loss on masked patches only is exactly this choice.)
- Stacking. Train one denoising layer, freeze it, train the next on its codes — the way deep networks were pre-trained before end-to-end training of deep networks became easy.
Link to diffusion. A denoiser trained with squared error learns the posterior mean ; for Gaussian noise, Tweedie’s formula turns that into the score (Vincent, 2011; Lecture 11 §2). A diffusion model is a denoising autoencoder trained at every noise level at once — §3 uses it as one.
2.2 How much does each corruption destroy? (script 01, Part 1)
Before training anything, the exact posterior tells us how hard each denoising problem is — the best possible per-pixel loss, and how much of the left shape’s identity survives the corruption. On 1,000 test images:
| corruption | pixels changed per image | best denoising loss (bits / image) | (left kind | corrupted) | Bayes accuracy, left kind |
|---|---|---|---|---|
| none | 0 | 0.00 | 0.000 bits | 100.0% |
| masking noise 25% | 17.8 | 0.07 | 0.005 | 100.0% |
| masking noise 50% | 35.8 | 1.77 | 0.081 | 98.1% |
| masking noise 75% | 53.8 | 23.34 | 0.604 | 84.6% |
| salt-and-pepper 25% | 36.0 | 1.05 | 0.051 | 98.7% |
| Gaussian, σ = 0.5 | (91.7 after rounding) | 0.54 | 0.026 | 99.3% |
(An image carries 17.80 bits; the left kind 3 bits.) Two observations. First, ShapeWorld is so redundant that removing a quarter of the ink costs almost nothing to a perfect reasoner (0.07 bits per image): the shapes are rigid templates, and a few pixels pin them down. Second, at 75% masking the problem changes character: 23 bits of uncertainty remain and the kind itself is ambiguous in 15% of images. Light corruption can be undone by local reasoning; heavy corruption requires deciding which shape it is.
2.3 Experiment: DAEs and their features (script 01, Part 2)
Seven encoder–decoder networks (the CNN encoder, a lighter mirrored decoder, per-pixel cross-entropy), 3,000 steps each:
| model | test denoising loss (bits / image) | exact optimum | gap |
|---|---|---|---|
| plain autoencoder (no corruption) | 0.35 | 0.00 | +0.35 |
| DAE, masking 25% | 15.41 | 0.07 | +15.34 |
| DAE, masking 50% | 39.72 | 1.77 | +37.95 |
| DAE, masking 75% | 87.31 | 23.34 | +63.97 |
| DAE, masking 50%, loss on corrupted pixels only | 46.94 (all pixels) | 1.77 | +45.17 |
| DAE, salt-and-pepper 25% | 32.97 | 1.05 | +31.92 |
| DAE, Gaussian σ = 0.5 | 30.39 | 0.54 | +29.85 |
The networks are far from the optimal denoiser — 15 to 64 bits per image worse — even where the optimum is nearly free. They learn local cleanup, not template matching. Now the features:
| representation | dim | left shape | left size | top / bottom | same kind | left shape, 10 / class |
|---|---|---|---|---|---|---|
| raw pixels | 288 | 64.6% | 78.0% | 99.4% | 50.6% | 42.2% |
| PCA, 64 components | 64 | 66.0% | 69.8% | 97.7% | 53.6% | 33.1% |
| random CNN encoder (untrained) | 128 | 77.0% | 81.0% | 91.6% | 53.8% | 42.5% |
| plain autoencoder | 128 | 72.7% | 86.7% | 92.8% | 54.5% | 37.4% |
| DAE, masking 25% | 128 | 80.7% | 87.8% | 95.1% | 56.6% | 35.8% |
| DAE, masking 50% | 128 | 82.9% | 93.5% | 98.4% | 55.9% | 39.4% |
| DAE, masking 75% | 128 | 82.5% | 96.0% | 99.5% | 56.0% | 41.6% |
| DAE, masking 50%, corrupted-only loss | 128 | 86.5% | 95.8% | 99.3% | 57.1% | 45.9% |
| DAE, salt-and-pepper 25% | 128 | 84.9% | 83.4% | 96.4% | 56.1% | 40.3% |
| DAE, Gaussian σ = 0.5 | 128 | 80.1% | 81.6% | 96.5% | 56.1% | 38.8% |
What the table says:
- The plain autoencoder is worse than an untrained encoder at the shape kind (72.7% vs 77.0%). Its code (64 channels × 3 × 6 = 1,152 numbers for 288 pixels) is over-complete, it learns to copy (0.35 bits per image), and copying needs no notion of shapes. Corruption fixes that: every DAE beats the random encoder.
- Emphasizing corrupted dimensions helps, as Vincent et al. found: scoring only the pixels that had to be inferred gives the best DAE (86.5%, and the best 10-label probe of the family, 45.9%).
- Size and position become very readable (up to 96% / 99.5%) — that is what local denoising needs. The kind improves less, and the copy rule (same kind) barely moves from chance (56%): no DAE needs to look across panels.
- Few labels. With 10 labels per class no DAE beats raw pixels by much (35.8–45.9% vs 42.2%): the kind is present in the features (a linear classifier with 4,000 labels finds it) but not simple enough to be found from 80 examples.
Plan vs reality. The networks are undertrained relative to their task: a calibration run of the 50% masking DAE reached 78.3% at 2,000 steps (loss 0.171 bits per pixel) and 84.5% at 6,000 steps (0.089) — still far from the optimum, and with its 10-label probe stuck at ~39.5%. We kept one budget (3,000 steps) for every method of the lecture; the DAE family’s ranking is not an artifact of it, its absolute numbers partly are.
3. Generative models as feature extractors
The slides’ aside: generative models “can also achieve this”, and EmerDiff (Namekata et al., 2024) reads semantic segmentations out of Stable Diffusion’s internal features. Our course has already trained generative models of the same 10,000 images. Script 01, Part 3 probes two of them without any new training: Lecture 7’s VAE (its 16-dimensional encoder mean) and Lecture 11’s diffusion U-Net (160K parameters), whose bottleneck and first decoder stage are read out after noising the input to level (the recipe of Xiang et al., 2023, Denoising Diffusion Autoencoders are Unified Self-supervised Learners):
| representation | left shape | left size | top / bottom | same kind | left shape, 10 / class |
|---|---|---|---|---|---|
| Lecture 7 VAE, encoder mean (16 dims) | 80.8% | 68.0% | 99.8% | 55.6% | 58.1% |
| diffusion U-Net, = 0.0 | 97.2% | 98.2% | 96.4% | 71.8% | 63.0% |
| = 0.1 | 99.0% | 99.6% | 93.8% | 67.6% | 78.1% |
| = 0.2 | 99.6% | 99.8% | 92.8% | 66.5% | 81.2% |
| = 0.3 | 98.5% | 99.1% | 90.8% | 65.9% | 81.2% |
| = 0.5 | 91.2% | 92.5% | 88.2% | 64.9% | 74.3% |
| = 0.7 | 65.2% | 68.8% | 77.5% | 60.2% | 50.0% |
| = 0.9 | 24.1% | 35.6% | 60.2% | 55.0% | 16.6% |

The diffusion U-Net is the best feature extractor of the whole lecture — near-perfect kind and size probes, 81% with 10 labels per class, and the only representation that makes the copy rule clearly readable (up to 72%). The best noise level is intermediate ( ≈ 0.2–0.3), as Xiang et al. report for real images: at = 0 the network has nothing to denoise and passes pixels through; at high the input is mostly noise. A DAE trained at all noise levels with a good architecture and 10,000 steps (Lecture 11) beats every single-level DAE of §2 by a wide margin — the same idea, done thoroughly.
4. Masked autoencoders
4.1 From BERT to MAE
BERT (Devlin et al., 2018; Lecture 15) masks 15% of a text’s tokens and predicts them. The same idea for images had been tried for years (context encoders, §5) without matching contrastive methods. MAE (He et al., 2021) made it work with three choices:
- A Vision Transformer, so “masking” means removing tokens, and the encoder can simply not see the masked patches: it processes only the visible ~25%, which makes pre-training several times cheaper (the paper reports 3× or more) and avoids a train/test mismatch ([mask] tokens never enter the encoder).
- A light decoder that receives the encoded visible tokens plus a shared learned [mask] token at every masked position (with position embeddings) and reconstructs the pixels. It exists only for pre-training; its narrowness forces the encoder to do the work.
- A high masking ratio — 75% — and the loss on the masked patches only.
The paper’s masking-ratio sweep peaks around 75% for both fine-tuning and linear probing (with linear probing much more sensitive). Its explanation: images are spatially redundant — “a missing patch can be recovered from neighboring patches with little high-level understanding” — whereas words are dense in information. A low masking ratio lets the network interpolate; a high one forces it to reason about objects. The slides then show the cousins: BEiT predicts the tokens of a discrete VAE instead of pixels; VideoMAE masks 90–95% of space-time tubes, works with only ~3K training videos (the slide lists 87.4% on Kinetics-400, 75.4% on Something-Something V2), and notes that data quality and domain shift matter more than quantity; SiamMAE shows a past frame fully and masks 95% of a future frame, which pushes the network to model motion; Audio-MAE masks spectrogram patches, with local-window attention in the decoder; MultiMAE masks across RGB, depth and segmentation (pseudo-labels for the extra modalities); M3AE masks images and text together and finds a 75% masking ratio works for text too — when the text is paired with an image.
4.2 Is the redundancy argument true? (script 02, Part 1)
On ShapeWorld we can measure it. For random masks of 3 × 3 patches at four ratios, the exact posterior gives the best prediction of every masked pixel (a) from all visible pixels and (b) from the visible pixels of the 8 neighbouring patches only — a perfect reasoner that is allowed to look just around the hole. Bits per masked pixel on 1,000 test images:
| masked | patches | pixel prior | local average | exact, neighbours only | exact, all visible | joint bits / image | (left kind | visible) | Bayes accuracy, left kind |
|---|---|---|---|---|---|---|---|---|
| 15% | 5 of 32 | 0.730 | 0.511 | 0.042 | 0.001 | 0.01 | 0.00 | 99.9% |
| 50% | 16 of 32 | 0.726 | 0.592 | 0.169 | 0.023 | 0.34 | 0.09 | 97.6% |
| 75% | 24 of 32 | 0.730 | 0.685 | 0.379 | 0.159 | 2.80 | 0.51 | 86.8% |
| 90% | 29 of 32 | 0.729 | 0.762 | 0.574 | 0.434 | 9.08 | 1.45 | 65.3% |
(“Pixel prior”: each pixel’s ink frequency; “local average”: the smoothed ink fraction of the visible pixels within 2 pixels; “joint”: for all masked pixels together.)
At 15% masking, the neighbours alone almost determine the hole (0.042 bits per pixel): local continuation suffices, nothing about “which shape” is needed. At 75%, the neighbours leave 0.379 bits, while everything visible gives 0.159 — more than half of what is predictable needs non-local inference, i.e. recognizing the shape. That is MAE’s argument in numbers. At 90% the task becomes genuinely ambiguous (the kind itself is uncertain in a third of the images).
4.3 A tiny MAE at four ratios (script 02, Part 2)
The ViT (228,585 parameters including the decoder), 3,000 steps per ratio, tested on the same masks:
| model | test bits / masked pixel | exact, neighbours only | exact, all visible |
|---|---|---|---|
| MAE, 15% masked | 0.153 | 0.042 | 0.001 |
| MAE, 50% | 0.265 | 0.169 | 0.023 |
| MAE, 75% | 0.420 | 0.379 | 0.159 |
| MAE, 90% | 0.577 | 0.574 | 0.434 |
| MAE, 75%, loss on all patches | 0.423 | 0.379 | 0.159 |
| representation | left shape | left size | top / bottom | same kind | left shape, 10 / class |
|---|---|---|---|---|---|
| MAE, 15% masked | 92.3% | 95.2% | 98.5% | 59.9% | 59.3% |
| MAE, 50% | 95.1% | 97.1% | 99.6% | 54.2% | 66.2% |
| MAE, 75% | 94.4% | 93.7% | 98.2% | 59.8% | 66.4% |
| MAE, 90% | 93.0% | 96.1% | 95.6% | 72.0% | 64.8% |
| MAE, 75%, loss on all patches | 93.2% | 96.1% | 99.2% | 62.5% | 65.5% |

- Every MAE is a much better feature learner than the DAEs (92–95% vs ≤ 86.5%; 59–66% vs ≤ 46% with 10 labels), at the same budget — although its reconstructions are worse than even the neighbours-only optimum. Solving the pretext task well and learning good features are different things.
- Masking more helps, but less sharply than in the paper. 15% gives the weakest 10-label probe (59.3%); 50–90% are close. The relational target “same kind” is best read at 90% masking (72.0%): when most of one panel is hidden, predicting it from the other panel through the copy rule becomes worth learning.
- Loss on masked patches only vs all patches makes no difference here (94.4% vs 93.2%), consistent with the paper’s small gap.
Plan vs reality. We expected a clear optimum near 75%. Our probes are flat between 50% and 90%; with 32 tokens and 3,000 steps, the sweep resolves “low vs high” but not the paper’s fine structure.
5. Predicting missing pieces and other views
5.1 Context encoders and the blur (script 03, Part 1)
The context encoder (Pathak et al., 2016) is a convolutional encoder–decoder that fills a large hole (the image centre) from its surroundings. With a pixel-wise L2 loss its fills are blurry; the paper adds an adversarial loss (Lecture 9) to make them sharp, and fine-tunes the encoder for classification, detection and segmentation.
Is the blur a failure of the network? The loss is minimized by the posterior mean , and when several completions are plausible, their average is a blur by definition. Two holes, 3,000 steps each, compared with the exact posterior:
| hole | test bits / hidden pixel | exact | exact joint bits / image | pixel uncertainty, network | … exact mean | (kind in hole | visible) |
|---|---|---|---|---|---|---|
| centre 6 × 6 of each panel | 0.126 | 0.025 | 0.21 | 0.043 | 0.008 | 0.08 bits |
| the whole right panel | 0.713 | 0.702 | 8.49 | 0.239 | 0.238 | 2.22 bits |
(“Pixel uncertainty” = mean of over hidden pixels: 0 for a sharp prediction.) Hiding the whole right panel and predicting it from the left is “predicting one view from another”: the network gets within 0.011 bits per pixel of the optimum, and its prediction is exactly as blurry as the exact posterior mean (0.239 vs 0.238) — while every exact posterior sample is a crisp, valid shape. The blur is the optimum of the loss; sharp outputs need a different objective (adversarial, as in the paper, or a generative model of the hole).
The features:
| representation | left shape | left size | top / bottom | same kind | left shape, 10 / class |
|---|---|---|---|---|---|
| context encoder: centre holes | 86.6% | 89.0% | 96.7% | 54.5% | 47.9% |
| context encoder: right panel hidden | 91.8% | 79.5% | 87.8% | 58.6% | 73.7% |
Predicting the right panel needs the left kind (the copy rule: same kind 56% of the time) and nothing about the left panel’s size or position — and that is exactly what its encoder makes readable: the left kind at 91.8% (73.7% with 10 labels), the left size worse than the centre-hole encoder. The pretext task decides which information the encoder keeps.
5.2 Colorization: when does it teach semantics? (script 03, Part 2)
Colorization (Zhang, Isola & Efros, 2016) predicts the color channels from the lightness channel. Two design points from the slides: an L2 loss gives desaturated colors (the mean of many plausible colors is grayish), so the paper classifies each pixel into quantized color bins (with class rebalancing and an “annealed mean” for display); and colorization works as a pretext task. The split-brain autoencoder (Zhang et al., 2017) predicts each channel group from the other and concatenates the two encoders. Tracking emerges by colorizing videos (Vondrick et al., 2018): learning to copy colors from a reference frame learns correspondences.
Why should predicting color teach a network about objects? Only if color and content are correlated — grass is green, sky is blue. We test exactly that, with one switch. Colored ShapeWorld (8 palette colors) in two worlds: independent colors (homework 1’s colored ShapeWorld: a panel’s color is uniform and unrelated to anything), and tied colors (with probability 0.8 a shape has its kind’s own color — squares red, frames green, disks blue, …; otherwise uniform). The input is the binary image; the output, for every ink pixel, is the color.
| model | test loss | exact optimum on these test pixels | predicts the kind’s own color | predicts the true color | chroma of predictions |
|---|---|---|---|---|---|
| independent colors, 8-way classification | 3.094 bits / ink pixel | 3.000 | 14.5% | 12.9% | 0.932 |
| tied colors, 8-way classification | 1.154 | 1.131 (expected value 1.160) | 99.9% | 83.0% | 0.883 |
| tied colors, L2 regression of RGB | 0.262 (squared error) | — | 99.6% | 82.8% | 0.730 |
(True colors have chroma 0.875 on average; with tied colors the kind’s own color is the true one 82.5% of the time.) With tied colors, the best possible colorizer must recognize the kind — and the network does (99.9% of its most likely colors are the kind’s color). L2 regression’s colors are desaturated (chroma 0.73 vs 0.875): it predicts the mean, a mix of the preferred color with the others. In the independent world nothing can be learned beyond “3 bits per ink pixel”.
| representation | left shape | left size | top / bottom | same kind | left shape, 10 / class |
|---|---|---|---|---|---|
| colorizer, independent colors | 80.0% | 73.9% | 84.8% | 53.8% | 40.9% |
| colorizer, tied colors, classification | 100.0% | 95.8% | 96.7% | 61.4% | 85.8% |
| colorizer, tied colors, L2 | 100.0% | 95.0% | 90.8% | 56.9% | 92.7% |
The same network, the same pretext task, the same images: 80.0% → 100.0%, and 41% → 86–93% with 10 labels per class — the best few-label probes of the lecture. Colorization teaches semantics exactly to the extent that color depends on semantics. Whether a pretext task is good is a property of the task and the data.
Plan vs reality. Both colorizers’ training losses ended below the population optimum (2.92 bits < 3.00 for independent colors; 1.134 < 1.160 for tied): each training image’s colors were drawn once, and the network partly memorized them. On test pixels the losses are above the optimum, as they must be.
6. “Visual common sense” puzzles, and shortcuts
6.1 Three puzzles
- Relative patch position (Doersch, Gupta & Efros, 2015): show a patch and one of its 8 neighbours; predict which neighbour. To stop the network from matching edges across the boundary, patches are separated by gaps and randomly jittered. Even so, the network found a shortcut: chromatic aberration in camera lenses varies with the position in the frame, so a patch’s color fringes reveal its absolute position. The fix was to drop color information from patches.
- Jigsaw puzzles (Noroozi & Favaro, 2016): cut a 3 × 3 grid of tiles, shuffle them with one of a fixed set of permutations (a subset of the 9! = 362,880, chosen to be far apart in Hamming distance), predict the permutation. Tiles are processed by a shared network separately (a “context-free network”) and only combined at the end, again to prevent low-level shortcuts; gaps between tiles prevent edge matching.
- Rotation (Gidaris, Singh & Komodakis, 2018): rotate the image by 0°, 90°, 180° or 270° and predict the rotation. It works on photographs because they have a canonical orientation — gravity: skies are up, people stand upright — and recognizing “upright” requires recognizing objects.
6.2 How solvable are they on ShapeWorld? (script 04, Part 1)
The exact solver scores each candidate answer by of the un-rotated (or re-ordered) image — or, with gaps, by — and picks the most probable (ties split evenly). Both panels are rotated by the same angle, or cut into their four 6 × 6 quadrants and permuted the same way (24 permutations); 1,000 test images:
| puzzle | Bayes ceiling | equally good answers (mean) | images with a triangle | images without |
|---|---|---|---|---|
| rotation (4 choices) | 39.9% | 3.40 | 100.0% | 25.0% |
| rotation + a “timestamp” pixel in each panel’s corner | 100.0% | 1.00 | 100.0% | 100.0% |
| jigsaw, 4 quadrants per panel (24) | 96.8% | 1.20 | 95.9% | 97.1% |
| jigsaw with 1-pixel gaps (24) | 86.4% | 1.69 | 87.7% | 86.0% |
Rotation is unsolvable for 7 of the 8 shapes: squares, frames, disks, rings, diamonds, plusses and crosses look identical after a quarter turn, and their positions are symmetric too. Only triangles point somewhere. The ceiling, 39.9%, is “solve the 19.9% of images that contain a triangle, guess the rest”. ShapeWorld has no gravity. Jigsaw, in contrast, is almost always solvable: shapes are rigid, so only one order of the quadrants gives a valid image.
6.3 What the puzzle networks learn (script 04, Part 2)
| puzzle | train accuracy | test accuracy | Bayes ceiling | test, with a triangle | test, without |
|---|---|---|---|---|---|
| rotation | 42.3% | 40.1% | 39.9% | 100.0% | 25.2% |
| rotation + marker | 100.0% | 99.9% | 100.0% | 100.0% | 99.9% |
| jigsaw | 95.1% | 94.5% | 96.8% | 92.0% | 95.1% |
| jigsaw + gaps | 76.0% | 76.8% | 86.4% | 81.9% | 75.5% |
| representation | left shape | left size | top / bottom | same kind | left shape, 10 / class |
|---|---|---|---|---|---|
| rotation | 86.2% | 75.0% | 90.3% | 54.4% | 53.6% |
| rotation + marker (shortcut) | 63.9% | 77.5% | 92.8% | 53.5% | 29.6% |
| jigsaw | 81.4% | 96.4% | 99.2% | 57.9% | 46.2% |
| jigsaw + gaps | 78.8% | 82.8% | 90.5% | 53.5% | 44.6% |
- The rotation network solves its puzzle exactly as well as possible (40.1% on test vs the 39.9% ceiling — 100% on triangles, chance on the rest). Its features are nevertheless the second-best of the convolutional pretext tasks on the kind (86.2%): telling a sideways triangle from an upright one, and both from everything else, requires a shape detector.
- The shortcut: add one ink pixel at each panel’s corner — a “camera timestamp” that rotates with the image — and the puzzle becomes trivially solvable (99.9%). The network learns to find the pixel and nothing else: its features are worse than raw pixels at the kind (63.9% vs 64.6%) and at 10 labels per class (29.6% vs 42.2%). Doersch’s chromatic aberration, in one pixel.
- Puzzle accuracy says nothing about feature quality: 99.9% (marker) gives the worst features, 40.1% (rotation) some of the best. The right panel of the figure plots exactly that.
- Jigsaw is learned well (94.5% of a 96.8% ceiling) and makes size and position very readable (96.4% / 99.2%) — matching quadrants is about where ink sits — but the kind less so. Gaps lowered the puzzle accuracy and did not improve the features here (78.8% vs 81.4%) — plan vs reality: on real photographs gaps remove an edge-continuity shortcut; on our shapes, edge continuity is how the shapes are recognized.
7. The Lecture 13 leaderboard (script 04, Part 3)
The best variant of each family (by the 4,000-label kind probe), three contrast rows, the baselines, and fine-tuning with 10 labels per class:
| representation | left shape | size | top / bottom | same kind | 10 / class (frozen) | fine-tune, 10 / class |
|---|---|---|---|---|---|---|
| raw pixels | 64.6% | 78.0% | 99.4% | 50.6% | 42.2% | — |
| PCA, 64 components | 66.0% | 69.8% | 97.7% | 53.6% | 33.1% | — |
| random CNN / CNN from scratch | 77.0% | 81.0% | 91.6% | 53.8% | 42.5% | 52.5% |
| random ViT / ViT from scratch | 76.4% | 86.2% | 92.0% | 59.0% | 30.4% | 61.1% |
| Lecture 7 VAE encoder mean | 80.8% | 68.0% | 99.8% | 55.6% | 58.1% | — |
| Lecture 11 diffusion U-Net, = 0.2 | 99.6% | 99.8% | 92.8% | 66.5% | 81.2% | — |
| plain autoencoder (contrast) | 72.7% | 86.7% | 92.8% | 54.5% | 37.4% | 41.4% |
| DAE, masking 50%, corrupted-only loss | 86.5% | 95.8% | 99.3% | 57.1% | 45.9% | 48.4% |
| MAE, 50% masked | 95.1% | 97.1% | 99.6% | 54.2% | 66.2% | 73.5% |
| context encoder, right panel hidden | 91.8% | 79.5% | 87.8% | 58.6% | 73.7% | 76.4% |
| colorizer, independent colors (contrast) | 80.0% | 73.9% | 84.8% | 53.8% | 40.9% | 50.7% |
| colorizer, tied colors, L2 | 100.0% | 95.0% | 90.8% | 56.9% | 92.7% | 75.4% |
| rotation | 86.2% | 75.0% | 90.3% | 54.4% | 53.6% | 72.6% |
| rotation + marker (contrast: shortcut) | 63.9% | 77.5% | 92.8% | 53.5% | 29.6% | 40.5% |

How to read it:
- What the pretext task needs is what the encoder keeps. Right-panel prediction keeps the kind and drops the size; jigsaw keeps positions; tied colorization keeps the kind because color depends on it.
- Frozen probes and fine-tuning answer different questions. Fine-tuning a pretrained encoder beats training from scratch for every useful pretext task (73.5–76.4% vs 52.5% / 61.1%), and is hurt by the bad ones (plain AE 41.4%, the shortcut 40.5%: a bad initialization is worse than a random one). But the best frozen features (tied colorization, 92.7%) lose accuracy when fine-tuned on 80 images (75.4%) — 80 labels are enough to damage a good representation, as Lecture 1 found with 1 label per class.
- Few-label frozen probes separate methods most. With 4,000 labels many methods reach 86–100% on the kind; with 10 per class they range from 29.6% to 92.7%.
- The diffusion model, a generative model, is the strongest general-purpose representation here — on every target, not only the one its pretext task favours. Reconstruction at many noise levels over a whole image is a demanding pretext task.
8. Summary
- Self-supervised learning withholds part of the data and predicts it from the rest. A pretext task produces semantic features only if solving it requires the semantics; we evaluate with frozen linear probes (with many and with few labels) and with fine-tuning.
- Denoising autoencoders avoid the identity by corrupting the input. Ours were far from the exact optimal denoiser (15–64 bits per image) yet better than a random encoder; scoring only the corrupted pixels (“emphasis”) gave the best DAE (86.5%). An over-complete plain autoencoder learned to copy and was worse than random (72.7% vs 77.0%).
- A diffusion model is a DAE at every noise level; Lecture 11’s U-Net read at ≈ 0.2 was the best representation of the lecture (99.6%, 81% with 10 labels per class).
- MAE encodes only the visible patches and masks heavily. Exactly computed, at 15% masking the neighbours of a hole almost determine it (0.042 bits per pixel) — local continuation suffices; at 75% more than half of the predictable information needs the whole image. Higher ratios gave better few-label features (59% → 66%) and the best copy-rule probe at 90%.
- Pixel losses produce blur because the posterior mean is blurry: our right-panel context encoder was within 0.011 bits per pixel of the optimum and exactly as blurry as the exact posterior mean.
- Colorization teaches semantics exactly when color depends on semantics: the same network went from 80% to 100% (41% → 93% with 10 labels) when colors were tied to kinds. L2 colorizations are desaturated (chroma 0.73 vs 0.875).
- Puzzles need a canonical structure (rotation is unsolvable for 7 of our 8 shapes: ceiling 39.9%, reached by the network) and break on shortcuts (a corner pixel made rotation 100% solvable and the features worse than pixels). Puzzle accuracy is not feature quality.
- Fine-tuning beats training from scratch from every useful pretext task, but can damage the best frozen features when labels are very few.
9. Common pitfalls
- Judging a pretext task by its own accuracy or loss. The shortcut network solved its puzzle 99.9% of the time and learned nothing useful; the rotation network solved 40% and learned a lot. Always probe.
- An over-complete autoencoder without corruption or a bottleneck. It copies its input (0.35 bits per image here) and its features can be worse than random.
- Reading blur as a bug. Under a pixel-wise loss the best prediction of an uncertain hole is its posterior mean, which is blurry; sharpen with a different loss, not with more training.
- Masking too little. In redundant data a low masking ratio is solved by local continuation; the network never needs the global content.
- Low-level shortcuts: chromatic aberration, edge continuity, compression artifacts, watermarks, a pixel in the corner. Ask what else could solve the task.
- Assuming a pretext task transfers across datasets. Rotation needs canonical orientations; colorization needs color–content correlation. ShapeWorld has neither by default.
- Under-trained baselines and under-trained pretext networks. Our DAEs kept improving with more steps; Lecture 1 found the same for its supervised baseline. Compare at equal, reported budgets.
- Fine-tuning everything on a handful of labels. With 80 labels, fine-tuning lost 17 points of the best frozen representation. Try the frozen probe first.
10. Exercises
Exercise 1 (the identity). An autoencoder with a code larger than its input can represent the identity. Explain why a denoising autoencoder with the same architecture cannot simply learn the identity, and what it learns for masking noise on binary images, where a 0 can be either “background” or “erased ink”.
Answer
The target is the clean but the input is ; the identity outputs and pays for every corrupted component. The optimum is : an observed 1 stays 1 (masking only erases), an observed 0 becomes the posterior probability that ink was erased there — high where neighbouring ink suggests a shape continues, low elsewhere. Computing it requires a model of which ink patterns are plausible.
Exercise 2 (emphasis). With masking noise of rate and full emphasis (, ), which pixels contribute to the loss? Why might that produce better features than scoring every pixel?
Answer
Only the pixels chosen for corruption (whether or not they held ink). Uncorrupted pixels are easy: an observed 1 must stay 1, and many observed 0s are certainly background; scoring them rewards copying and dilutes the gradient. Emphasis spends the whole loss on what must be inferred, as MAE does by scoring masked patches only. Script 01: 86.5% vs 82.9% for the same corruption.
Exercise 3 (the posterior mean is blurry — derivation). For a hidden binary pixel and visible evidence , show that the prediction minimizing and the one minimizing the cross-entropy are both . When is strictly between 0 and 1?
Answer
Squared error: with , minimized at . Cross-entropy: , derivative . is fractional whenever the evidence does not decide the pixel — for a whole hidden panel, almost everywhere (pixel uncertainty 0.238 in script 03). A sharp output would be a sample, which these losses never favour.
Exercise 4 (neighbours vs everything). In script 02 at 15% masking, the best prediction from the neighbouring patches costs 0.042 bits per pixel and from everything 0.001. At 75% the numbers are 0.379 and 0.159. Explain both gaps, and connect them to MAE’s choice of masking ratio.
Answer
At 15%, a hidden 3 × 3 patch is almost always surrounded by visible patches; a rigid shape’s pixels on the hole’s border continue across it, so the neighbours nearly determine the hole — no need to know the kind. At 75% the surroundings are mostly hidden too; what remains predictable comes from distant visible pieces of the same shape (and the other panel through the copy rule), i.e. from recognizing the shape. A network trained at 15% can minimize its loss with local continuation and never needs the global content; at 75% it must model it. MAE picks the ratio at which the cheap solution stops working.
Exercise 5 (the rotation ceiling — derivation). Each panel’s kind is uniform, the right kind copies the left with probability 1/2, and only triangles reveal a rotation. Compute the Bayes ceiling of the 4-way rotation puzzle and compare with script 04’s 39.9%.
Answer
P(no triangle in either panel) = P(left ≠ triangle) · P(right ≠ triangle | left ≠ triangle) = (7/8) · (1 − (1/2)(1/8)) = (7/8)(15/16) = 0.8203. With a triangle the rotation is identified (accuracy 1), without it all four answers are equally likely (1/4): ceiling = 0.1797 + 0.8203/4 = 0.385. The test sample has 19.9% triangle images instead of 18.0%, giving 0.199 + 0.801/4 = 0.399 — the measured 39.9%.
Exercise 6 (tied colors — derivation). With probability = 0.8 a panel gets its kind’s color, otherwise a uniformly random one of = 8. Compute , and the expected loss of a colorizer that ignores the kind.
Answer
P(own color) = = 0.825, P(each other color) = = 0.025. bits. Ignoring the kind, the marginal color is uniform: 3 bits. The 1.84-bit difference is what recognizing the kind is worth to the colorizer — the pressure that makes its encoder semantic.
Exercise 7 (L2 desaturation). In the tied world, what RGB value does an L2 colorizer predict for a square’s ink, and what is its chroma? (Palette values: red (1, 0, 0), green (0, 1, 0), blue (0, 0, 1), yellow (1, 1, 0), magenta (1, 0, 1), cyan (0, 1, 1), white (1, 1, 1), orange (1, 1/3, 0).)
Answer
The posterior mean: 0.825 · red + 0.025 · (sum of the other seven colors). The other seven add up to green (0, 1, 0) + blue (0, 0, 1) + yellow (1, 1, 0) + magenta (1, 0, 1) + cyan (0, 1, 1) + white (1, 1, 1) + orange (1, 1/3, 0) = (4, 4.33, 4). So the prediction is (0.825 + 0.100, 0.108, 0.100) = (0.925, 0.108, 0.100): chroma 0.825 instead of 1 for pure red. For the plus, whose own color is white (chroma 0), the same computation gives (0.925, 0.908, 0.900), chroma 0.025. Averaged over the kinds, the predictions lose saturation — script 03 measures 0.730 against the true 0.875.
Exercise 8 (shortcuts). Propose a shortcut for the jigsaw puzzle on ShapeWorld that a network could exploit if each quadrant were cut with a 1-pixel gap only on its inner edges, and explain why script 04’s gap (a frame around every quadrant) does not have it.
Answer
With gaps only on inner edges, a quadrant’s blank strips sit on the sides that faced the panel centre — bottom-right for the top-left quadrant, and so on. After shuffling, the position of a tile’s blank strips reveals where it came from whenever ink touches those strips, without looking at the content. A frame around every tile is identical for all positions, so it carries no information about the origin. (Doersch’s chromatic aberration is the photographic version: an artifact correlated with absolute position.)
Exercise 9 (coding). Train rotation on a world in which shapes have a canonical orientation: replace every “diamond” by a shape that is not symmetric under quarter turns (e.g. an “L”), so that two kinds reveal the rotation. Predict the new Bayes ceiling and check whether the features improve.
Answer
(Run it.) With two asymmetric kinds, P(no informative shape in either panel) = (6/8) · (1 − (1/2)(2/8)) = 0.656, so the ceiling rises to 0.344 + 0.656/4 = 0.508. More images make the network look at shapes; expect the kind probe to rise — the experiment is a small version of “rotation works because photographs have gravity”.
11. Further reading
From the slides
- P. Vincent et al. Extracting and Composing Robust Features with Denoising Autoencoders, ICML 2008; Stacked Denoising Autoencoders, JMLR 2010.
- K. Namekata et al. EmerDiff: Emerging Pixel-level Semantic Knowledge in Diffusion Models, ICLR 2024.
- D. Pathak et al. Context Encoders: Feature Learning by Inpainting, CVPR 2016.
- R. Zhang, P. Isola, A. Efros. Colorful Image Colorization, ECCV 2016; Split-Brain Autoencoders, CVPR 2017; C. Vondrick et al. Tracking Emerges by Colorizing Videos, ECCV 2018.
- K. He et al. Masked Autoencoders Are Scalable Vision Learners, CVPR 2022; H. Bao et al. BEiT, ICLR 2022; Z. Tong et al. VideoMAE, NeurIPS 2022; A. Gupta et al. Siamese Masked Autoencoders, NeurIPS 2023; P.-Y. Huang et al. Masked Autoencoders that Listen (Audio-MAE), NeurIPS 2022; R. Bachmann et al. MultiMAE, ECCV 2022; X. Geng et al. Multimodal Masked Autoencoders Learn Transferable Representations (M3AE), 2022.
- C. Doersch, A. Gupta, A. Efros. Unsupervised Visual Representation Learning by Context Prediction, ICCV 2015; M. Noroozi, P. Favaro. Unsupervised Learning of Visual Representations by Solving Jigsaw Puzzles, ECCV 2016; S. Gidaris, P. Singh, N. Komodakis. Unsupervised Representation Learning by Predicting Image Rotations, ICLR 2018.
Added by these notes
- P. Vincent. A Connection Between Score Matching and Denoising Autoencoders, Neural Computation 2011.
- W. Xiang et al. Denoising Diffusion Autoencoders are Unified Self-supervised Learners, ICCV 2023.
- A. Kolesnikov, X. Zhai, L. Beyer. Revisiting Self-Supervised Visual Representation Learning, CVPR 2019 — how much the architecture and evaluation protocol change the ranking of pretext tasks.
12. Next lecture
Lecture 14 drops reconstruction altogether. Contrastive methods (CPC, SimCLR, MoCo) learn by telling the right partner apart from negatives — we will compute exactly why their InfoNCE loss is a bound on mutual information that saturates at , and train CPC on a toy speech world with exact phoneme and speaker posteriors. Methods without negatives (BYOL, SimSiam, DINO) risk a collapse that we will provoke on purpose; and I-JEPA predicts in representation space instead of pixel space. Everything enters the same probe protocol, and the leaderboard grows.