Course · Self-supervised pretraining: masked and contrastive learningPhase 17 · Study guide

What learning signal can unlabelled data provide?

Training Systems · Local CPULaptop CPU3 lessons (~5.3h)

Revision v0.18.1 ·

Self-supervised learning creates targets from the data itself. That makes the information boundary especially important: a hidden token or patch must remain a target rather than leaking into the input, and a contrastive positive must keep its source identity when views move around a batch. Work through one selected token, one patch and one row of a similarity matrix. Then read the recorded objectives beside their baselines and held-out checks. Saving and reloading an encoder gives the next exercise a concrete starting point; the evaluation determines whether the learned representation helps under a changed condition.

Preparation: Transformers & language models

Runtime: Executed CPU synthetic objectives; large-scale and human-feedback evaluation remain separate

Check your starting point

If an image reconstruction is perfect before training, what boundary should you inspect?

Compare your reasoning

Check whether hidden pixels entered the encoder or were copied into the prediction. A valid objective can still be defeated by leaked inputs.

If this is unfamiliar, work through Masked image modeling: reconstruct missing patches before attempting the project.

Build in stages

1. Masked language modeling: predict hidden tokens

Trace clean targets, corrupted IDs, attention axes and selected counts. Reproduce unequal-mask loss with a host calculation, derive the full logit gradient, and explain the final probability matrix.

2. Masked image modeling: reconstruct missing patches

Verify every patch on a rectangular RGB input, intervene on hidden pixels, and explain an ambiguous target that no deterministic decoder can reconstruct perfectly. Compare actual hidden targets with predictions.

3. Contrastive learning: views, positives and negatives

Derive a two-pair loss, change temperature without changing ranking, compare encoder gradients with finite differences, and diagnose broken identity or duplicate false negatives from the similarity matrix.

Try a changed condition

Make a prediction before opening the reasoning. Keep your answer and the evidence you would collect.

Two rows in a contrastive batch refer to the same semantic positive. What assumption does a diagonal-only target violate?

Compare an approach

It assumes one unique positive per row and treats the duplicate positive as a negative. Write the positive matrix before choosing an objective. A multi-positive loss or deduplication policy changes the task definition; report which one is used and keep evaluation groups separated from training.

Diagnose a likely failure

Symptom: A low masked loss does not transfer to the downstream task.

Check next: Check target leakage, mask distribution, encoder-versus-projection features and a held-out downstream protocol.

Decide what is ready

Complete stages 1–3 of training-methods with independent loss references, real training curves, changed masks or pairs and explicit synthetic-data limits. Add the new lesson evidence: unequal-count gradient oracle, rectangular patch/intervention checks, irreducible ambiguity example and temperature/ranking comparison. Explain each saved figure without copying its caption. Complete the saved-encoder handoffs: record data/mask/processor identities, reload the artifacts, evaluate held-out groups and report frozen probes against independent baselines. Keep the demonstrated MLM and MIM limitations visible rather than calling objective completion a quality pass.

Where to put your project code

Write your code in: projects/training-methods/my_methods.py (copy projects/training-methods/starter/methods.py first: cp projects/training-methods/starter/methods.py projects/training-methods/my_methods.py).

Verify your implementation: python3 projects/training-methods/tests/check.py --stage all --impl projects/training-methods/my_methods.py

Run the staged project checks on your implementation in projects/training-methods/my_methods.py and record your transfer experiment results in your portfolio.

Open An audited pretraining and adaptation objective toolkit

Open Trace a tiny bidirectional encoder from pretraining to retrieval

What still needs further work

Full BERT/ViT masked autoencoders, natural corpora, augmentation studies and downstream probe benchmarks remain extensions. The current labs execute small attention, linear reconstruction and embedding models.