Learning Transferable Visual Models From Natural Language Supervision (CLIP)
- Paper: Learning Transferable Visual Models From Natural Language Supervision
- Authors: Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, Gretchen Krueger, Ilya Sutskever
- Lab, year: OpenAI, 2021
- Video: Watch the YouTube Short on Backprop Daily
Summary
CLIP (Contrastive Language–Image Pre-training) learns to see from text found on the internet instead of from a fixed list of labels. It has two parts: an image encoder and a text encoder. Both turn their input into a vector in the same embedding space. During training, CLIP gets a batch of (image, text) pairs and learns to give each image the highest similarity with its own text.
The paper trains CLIP on 400 million (image, text) pairs collected from the internet (Section 2.2). After training, CLIP can classify images without any training examples for the task: you write the class names as text (for example “a photo of a dog”), and CLIP picks the text that best matches the image (Section 3.1.2). This way the best CLIP model reaches 76.2% top-1 accuracy on ImageNet, matching the original ResNet-50 without using any of ImageNet’s 1.28 million labeled training images (Section 3.1.3, Table 1).
What Problem Does It Solve
A normal image classifier learns a fixed set of classes, such as the 1,000 ImageNet classes. To recognise a new kind of object, you must collect and label new pictures and train again.
CLIP learns from pictures together with the words people wrote next to them. Because it connects pictures to language, you can ask it about new classes just by writing their names. It is like learning to read a picture dictionary instead of memorising a stack of flashcards: once you can connect words to pictures, you can look up words you have not been tested on.
Core Idea
- Learn from natural language: text that comes with images on the internet is a much larger and richer source of supervision than hand-made class labels (Sections 1 and 2.2).
- Contrastive, not predictive: an earlier version tried to predict the exact words of each caption. This was slow, so CLIP only predicts which text in the batch belongs to which image. In Figure 2 this contrastive objective was 4 times more efficient than predicting a bag of words, which was itself 3 times more efficient than a transformer language model (Section 2.3).
- Shared embedding space: both encoders map into a shared embedding space (512-d for ViT-B/32, Table 20). For N pairs in a batch, CLIP raises the cosine similarity of the N real pairs and lowers it for the N² − N wrong pairings, with a symmetric cross-entropy loss (Section 2.3, Figure 3).
- Zero-shot classification: the class names, written as text, become the weights of a classifier, so no task-specific training is needed (Section 3.1.2).
Key Method Details
- Encoders: the image encoder is a modified ResNet or a Vision Transformer; the text encoder is a 63M-parameter, 12-layer, 512-wide Transformer with 8 attention heads (Section 2.4).
- Linear projections: each encoder’s output goes through a single linear projection into the shared space; there is no non-linear projection head (Section 2.3).
- Learned temperature: the temperature that scales the similarities is learned during training. It starts at the equivalent of 0.07 and is clipped so the logits are never scaled by more than 100 (Sections 2.3 and 2.5).
- Training: 32 epochs with Adam, decoupled weight decay and a cosine learning-rate schedule, with a minibatch of 32,768 pairs. The largest ResNet took 18 days on 592 V100 GPUs (Section 2.5).
- Prompts: writing “A photo of a {label}.” instead of just the class name helps; ensembling 80 prompts and prompt engineering together improve ImageNet accuracy by almost 5% (Section 3.1.4).
- Limitations: CLIP is weak on fine-grained classes (car models, flower species, aircraft variants), on abstract tasks such as counting objects, and on data very unlike its training data, such as handwritten MNIST digits, where it reaches only 88% (Section 6).
Simplifications in This Notebook
- Tiny synthetic data: 800 training pictures (32×32) of 3 shapes in 6 colours, so only 18 different captions, instead of 400 million (image, text) pairs from the internet.
- Tiny encoders: a 3-layer MLP image encoder and a character-level, 1-layer GRU text encoder, both ending in a 128-d embedding (1,855,745 parameters in total), instead of a ResNet or Vision Transformer and a 12-layer Transformer with a 512-d space for ViT-B/32.
- Short, small-batch training: batches of 64 for 20 epochs with Adam, instead of batches of 32,768 for 32 epochs.
- Easy “zero-shot” test: the 18 prompts used for classification are exactly the training captions, and there is no prompt ensembling.
What the Notebook Result Shows
- Training worked: the contrastive loss fell from 4.0918 after the first epoch (close to ln(64) ≈ 4.159, random guessing in a batch of 64) to 1.3982 after 20 epochs, and the learned temperature rose from 14.29 to 16.42. With only 18 captions, a batch holds many identical captions, so the loss cannot reach 0.
- “Zero-shot” accuracy was 100% (200/200), but the prompts are the training captions, so this only shows that the model matches pictures to captions it has seen. It does not show the paper’s transfer to new datasets.
- Loss check: equal logits give exactly ln(4) = 1.386 for 4 pairs, as expected.
Influence
OpenAlex lists about 65,500 citations (65,539 when checked on 2 December 2026). OpenAI released the code and trained models on GitHub. CLIP became a building block of text-to-image models: DALL-E 2 generates images from CLIP image embeddings, and Stable Diffusion v1 uses a frozen CLIP ViT-L/14 text encoder to condition on text prompts. Open re-implementations such as OpenCLIP train CLIP models on public data.
Resources
| File | Description |
|---|---|
| README.md | This overview — a 5-minute read covering the paper’s summary, core idea, key method details, influence, and a plain-English explanation of the problem it solves |
| solution.ipynb | From-scratch PyTorch implementation of a tiny CLIP (MLP image encoder, GRU text encoder, contrastive loss) on synthetic coloured shapes, with a zero-shot classification demo |
| CODE_ARCHITECTURE.md | Section-by-section breakdown of the notebook — what each cell does, data flow, tensor shapes, and key design decisions |
| TALK.md | Press coverage, Q&A (answers from the paper), citations, and common misconceptions about the paper |