TL;DR
CLIP is a vision model trained on 400 million (image, caption) pairs taken from the web. Nobody labelled the images with a fixed list of categories. Instead, the model learns to pick out which caption belongs to which image, and that single task turns out to teach it a broad set of visual concepts.
After training, you can name a new set of classes in plain English and CLIP will classify images into them without any further training. The paper reports that the best model matches a fully supervised ResNet-50 on ImageNet zero-shot, without using any of ImageNet's 1.28 million training images.
Where you'll see it: as the image-text backbone of text-to-image systems and image search, as a zero-shot classifier you can point at any label list, and as the vision encoder inside many later multimodal models.
The problem
Computer vision systems of the mid-2010s learned from crowd-labelled datasets such as ImageNet. Each dataset fixed a list of categories, usually around 1,000, and the trained model could only name those categories. To recognise a new concept, you needed a new labelled dataset and a new training run.
NLP had moved on. Pre-training on raw text with objectives such as masked language modelling, followed by zero-shot use through a text prompt, had produced models that handled many tasks with little or no task-specific data. The authors asked whether the same recipe could work for images: learn from the free supervision that already sits next to images on the web, namely their captions, and get a model that can name concepts it was never explicitly labelled with.
Two obstacles stood in the way. The public image-text datasets were small (MS-COCO and Visual Genome have about 100,000 training photos each), and training an image model to generate captions word by word was too slow to scale.
Key idea
Treat the caption as a whole, not as a sequence of words to predict exactly. Given a batch of images and their captions, the model only has to answer one question: which caption goes with which image? Pairs that really belong together should get high similarity scores, and every other pairing in the batch should get low ones.
flowchart LR
I[Image batch] --> IE[Image encoder]
T[Caption batch] --> TE[Text encoder]
IE --> SIM[N x N cosine similarity matrix]
TE --> SIM
SIM --> LOSS[Symmetric cross entropy: diagonal is correct]
Because the learned embedding space puts images and sentences side by side, a class name can become a classifier. Write one sentence per class, embed each sentence with the text encoder, and the image whose embedding sits closest to one of them gets that label. The paper calls this a zero-shot classifier. It is built at test time from language, not learned from labelled images.
The method
Contrastive objective
Take a batch of (image, text) pairs. Let be the normalised image embedding and the normalised text embedding of the -th caption. The similarity of pair is
and the logits are , where is a temperature. The correct pairings sit on the diagonal of the matrix. The symmetric loss averages two cross-entropy terms, one that reads each image row to find its caption and one that reads each caption column to find its image:
Each term is a Softmax over one row or column followed by the negative log probability of the correct entry. The denominator contains the one correct pair and wrong ones, so the loss pushes the correct similarity up and the wrong ones down. The paper notes that this batch construction and objective have earlier names: the multi-class N-pair loss in deep metric learning, and InfoNCE in Contrastive Learning.
The temperature is a learned scalar. It is stored as a logarithm, initialised at 0.07, and clipped so that the logits never scale by more than 100. The clip was needed for stable training.
Architecture
The image encoder comes in two families:
- ResNet-50 and larger ResNets. Standard Convolutional Neural Network backbones with three changes: ResNet-D tweaks, anti-aliased blur pooling, and an attention pooling layer in place of global average pooling. The attention pooling is one layer of transformer-style multi-head attention whose query comes from the average-pooled feature map.
- Vision Transformers. ViT-B/32, ViT-B/16 and ViT-L/14, following the Vision Transformer (ViT) design with one extra layer normalisation after the patch and position embeddings.
The text encoder is a 12-layer, 512-wide Transformer with 8 attention heads and 63 million parameters. Text is lower-cased, split into byte-pair-encoding tokens from a vocabulary of 49,152, and truncated to 76 tokens. A [SOS] token and an [EOS] token bracket the sequence. The activation at the [EOS] position, after layer normalisation and a linear projection, is the caption embedding. The text encoder uses masked self-attention, which keeps the option to initialise it from a pre-trained Language Model later.
Two design choices are worth noticing. Both encoders end in a single linear projection into the shared space, not a multi-layer head. And the only data augmentation is a random square crop.
Efficiency
Why not predict the exact caption words? The authors trained a 63M-parameter transformer to predict captions and measured how fast the resulting image encoder learned to recognise ImageNet classes. It was three times slower than a much simpler baseline that predicted a bag-of-words encoding of the same caption. Switching that baseline's objective from predicting words to contrastive matching gave another four-fold gain in zero-shot transfer efficiency. Most of the speed came from not having to model the many ways the same picture can be described.
Scale
The dataset, WebImageText (WIT), has 400 million pairs. Searches were built from 500,000 queries, drawn from Wikipedia words, bi-grams, article titles and WordNet synsets, and the result was approximately class-balanced at up to 20,000 pairs per query. The largest ResNet, RN50x64, took 18 days on 592 V100 GPUs. The largest ViT took 12 days on 256 V100 GPUs. The batch size was 32,768.
Results
The zero-shot protocol is simple. For each dataset, write a prompt per class, embed the prompts with the text encoder, cache the resulting classifier weights, and classify each image by the highest cosine similarity.
| Dataset | Visual N-Grams (2017) | CLIP (best model) |
|---|---|---|
| aYahoo | 72.4 | 98.4 |
| ImageNet | 11.5 | 76.2 |
| SUN | 23.0 | 58.5 |
The 76.2 comes from the largest vision-transformer model, ViT-L/14 fine-tuned for one extra epoch at 336-pixel resolution (the paper's appendix table of per-dataset zero-shot results gives the same figure). The ImageNet top-5 accuracy of that model is 95%, which matches Inception-V4. The paper cautions that this comparison is not controlled: CLIP uses a dataset ten times larger, a model with nearly 100 times more compute per prediction, and a transformer.
A note on counting, because the paper uses several numbers. The abstract says "over 30 datasets". The head-to-head comparisons with supervised baselines and linear probes use a suite of 27 datasets. The scaling study uses 39 evaluations on 36 datasets, a different and larger set. They are different suites, not conflicting figures.
Across the 27-dataset suite, zero-shot CLIP beats a supervised logistic regression fitted on ResNet-50 features on 16 of them. Large wins include Stanford Cars and Food101, where the gap is over 20 points, and Kinetics700, where the gap is 14.5 points. Losses are large on specialised tasks: satellite imagery, lymph node tumours, counting objects, and German traffic signs. Zero-shot CLIP is also competitive with a few-shot linear probe. It matches a 4-shot logistic regression on average, and nearly matches the best 16-shot classifier.
Prompt engineering helps. A bare class name is ambiguous (the word "crane" can mean a bird or a machine). The template "A photo of a class." adds 1.3 points on ImageNet. Ensembling 80 prompts adds 3.5 more, and together the two gain almost 5 points.
Robustness is a second headline. Standard ImageNet models lose a lot of accuracy on new natural image distributions such as ImageNetV2, ImageNet Sketch and ObjectNet. Zero-shot CLIP shrinks this gap by up to 75 percent. But fitting CLIP to ImageNet adds 9.2 points on ImageNet itself, to 85.4 percent, while average accuracy under distribution shift slightly drops. The robustness comes from not having seen the target distribution, and it disappears as in-distribution training data grows.
Scaling is smooth. Averaged across 39 evaluations on 36 datasets, error follows a log-log linear trend over a 44 times range of compute across five CLIP ResNets.
Worked example: classifying one image
Suppose three classes, dog, cat and car, and a temperature of . The image embedding has cosine similarities 0.30, 0.25 and 0.10 with the three text embeddings.
- Divide by the temperature: logits are , , .
- Subtract the largest logit for stability: , , .
- Exponentiate: , , . Their sum is .
- Divide each by the sum: dog , cat , car .
The prediction is "dog" with about 65 percent confidence. The softmax is over three classes here; in training it is over the batch. Notice that the temperature sets how sharp the distribution is. A smaller makes the top class dominate.
Why it mattered
CLIP showed that natural language is a practical source of training signal for vision at web scale. It turned zero-shot classification into a default option, so a model could be pointed at a new label set with a sentence rather than a dataset. Its text-image embedding space became a building block for later systems, including text-to-image generators, which use a CLIP-style text encoder to condition on prompts, and image retrieval by text.
It also reframed evaluation. The paper argued that zero-shot performance measures what a model can do with a task described in words, and that broad suites of datasets are better than a single benchmark for judging general capability. It raised the question of social bias in web-scale training data, a concern the paper examines in its broader impacts section. Later work on data filtering, prompt design and few-shot adaptation followed directly from the gaps the authors listed.
Limitations the authors state
CLIP is weak on fine-grained and abstract tasks, close to chance on some novel ones. It generalises poorly to truly out-of-distribution inputs: zero-shot accuracy on handwritten MNIST digits is 88 percent, and a logistic regression on raw pixels beats it. It can only choose among concepts it is given. The model is also data hungry in a different way: it scales well, but the authors estimate that reaching overall state of the art with zero-shot CLIP would require about a 1,000 times increase in compute. The training data is unfiltered and carries social biases.
Reading guide
Read in this order. Each line names the prerequisites that matter for that part of the paper.
- Section 1 and Section 2.1 (motivation and natural language supervision). Needs Word Embedding to see why text can act as a training signal, and Self-Supervised Learning for the contrast with unsupervised methods.
- Section 2.2 (the WIT dataset). Needs nothing beyond this lesson. It is a data-collection section, but note that the caption sits next to the image as its label.
- Section 2.3 (pre-training objective). Needs Contrastive Learning, Softmax and Cross-Entropy Loss. The symmetric loss is the central equation of the paper.
- Section 2.4 (architectures). Needs Convolutional Neural Network, Transformer, Vision Transformer (ViT) and Layer Normalization.
- Section 2.5 (training). Needs Adam Optimizer and Softmax Temperature for the learned temperature. Gradient Descent underlies the rest.
- Section 3.1 (zero-shot transfer). Needs Zero-Shot Learning, the idea of a classifier built without labelled examples. Figure 3 in the paper is the pseudocode.
- Section 3.2 (representation learning). Needs Transfer Learning, Representation Learning and Linear Regression for linear probes.
- Section 3.3 (robustness to distribution shift). Needs Covariate Shift and Data Augmentation. The robustness gap is the central phenomenon.
- Sections 4 to 9 (human comparison, data overlap, limitations, impact, related work). Mostly self-contained. The related-work section is easier once you have read Efficient Estimation of Word Representations in Vector Space (word2vec) and BERT: Pre-training of Deep Bidirectional Transformers (for the NLP pre-training context).
Check yourself
QuestionWhy does CLIP use a contrastive objective instead of predicting the exact caption words?Show answer
QuestionA batch has N = 4 pairs. How many similarity scores are computed, and how many are the correct pairings?Show answer
QuestionCompute the softmax of logits 2.0, 1.0 and 0.0 over three classes. Which class wins, and what does the answer say about a temperature of 0.07?Show answer
QuestionYou want a classifier for a new set of bird species, and you have a few labelled photos for each. Under what conditions would you still prefer zero-shot CLIP?Show answer
QuestionWhy does the paper say that zero-shot CLIP's robustness gap shrinks while supervised adaptation to ImageNet does not give the same benefit?Show answer
Sources
- Radford et al., Learning Transferable Visual Models From Natural Language Supervision, 2021. https://arxiv.org/abs/2103.00020
- van den Oord et al., Representation Learning with Contrastive Predictive Coding, 2018 (InfoNCE). https://arxiv.org/abs/1807.03748
- Dosovitskiy et al., An Image is Worth 16x16 Words, 2020 (ViT). https://arxiv.org/abs/2010.11929
- OpenAI CLIP repository. https://github.com/OpenAI/CLIP