Learn › VLMs & Multimodal
·FREE·PAPER·7 min read

Paper Deep Dive — CLIP: Putting Words and Images on One Map

A reading of the CLIP paper (Radford et al., 2021) grounded strictly in its own text: how the in-batch positives and negatives work, why zero-shot classification is really a hypernetwork trick, the five points that prompt wording is worth, and the long list of limits the authors wrote themselves.

Key points

  • CLIP is contrastive learning that predicts which image goes with which sentence in a batch, using symmetric cross-entropy over N positives and N²−N negatives.
  • An image encoder and a text encoder are trained jointly, with embeddings from one linear projection. The batch size is 32,768.
  • In zero-shot classification, the text encoder acts as a hypernetwork that generates the weights of a linear classifier.
  • Using A photo of a {label}. as the default adds 1.3% and ensembling 80 prompts adds another 3.5%, roughly 5% in total.
  • Among the limits, reaching state of the art needs around 1000× more compute, and CLIP scores only 88% on MNIST handwritten digits.

Learning Transferable Visual Models From Natural Language Supervision

Primary source — what this article is built on

undefined2021-02-26→undefined2026-08-065y 5mo later

Learning Transferable Visual Models From Natural Language SupervisionAlec Radford, Jong Wook Kim, Chris Hallacy et al. · 2021-02-26 · v1arXiv:2103.00020Paper page·PDF
undefined

State-of-the-art computer vision systems are trained to predict a fixed set of predetermined object categories. This restricted form of supervision limits their generality and usability since additional labeled data is needed to specify any other visual concept. Learning directly from raw text about images is a promising alternative which leverages a much broader source of supervision. We demonstrate that the simple pre-training task of predicting which caption goes with which image is an efficient and scalable way to learn SOTA image representations from scratch on a dataset of 400 million (image, text) pairs collected from the internet. After pre-training, natural language is used to reference learned visual concepts (or describe new ones) enabling zero-shot transfer of the model to downstream tasks. We study the performance of this approach by benchmarking on over 30 different existing computer vision datasets, spanning tasks such as OCR, action recognition in videos, geo-localization, and many types of fine-grained object classification. The model transfers non-trivially to most tasks and is often competitive with a fully supervised baseline without the need for any dataset specific training. For instance, we match the accuracy of the original ResNet-50 on ImageNet zero-shot without needing to use any of the 1.28 million training examples it was trained on. We release our code and pre-trained model weights at https://github.com/OpenAI/CLIP.


If it does not fit in one of a thousand boxes, it is invisible

State-of-the-art vision systems are trained to predict a fixed set of predetermined categories. That form of supervision limits their generality, because specifying any other visual concept means collecting more labelled data. That is where the paper opens (Abstract).

The weakly supervised work that came before sat in the same cage. The paper points out that those approaches carefully design — and in the process limit — their supervision to 1000 classes, or 18291 classes. They also predict through a static softmax classifier with no mechanism for dynamic outputs, which severely curtails flexibility and caps zero-shot ability (§1). Meanwhile the attempts to learn directly from natural language performed poorly: Visual N-Grams reached 11.5% zero-shot on ImageNet (§1).

So the authors collect 400 million (image, text) pairs from publicly available sources on the internet, searching for text containing one of 500,000 queries (words appearing at least 100 times in English Wikipedia, WordNet synsets and so on) and class-balancing with up to 20,000 pairs per query. They call it WIT, for WebImageText (§2.2).

Predicting the caption was the long way round

The first approach jointly trained an image CNN and a text transformer to predict the caption. Efficiency never came. Figure 2 shows the measurement: a 63-million-parameter Transformer language model — already using twice the compute of its ResNet-50 image encoder — learned to recognise ImageNet classes three times slower than a much simpler baseline that predicts a bag-of-words encoding of the same text (§2.3).

The reason is the task. Both are trying to predict the exact words that accompany an image, and given the variety of descriptions, comments and related text that co-occur with images, that is simply too hard. So the paper switches to an easier proxy: predict only which text as a whole is paired with which image, not the words. Swapping the same baseline's predictive objective for a contrastive one bought a further 4× improvement in the rate of zero-shot transfer (§2.3).

The dot product becomes the distance

The mechanism is plain. Given a batch of NN (image, text) pairs, predict which of the N×NN\times N possible pairings actually occurred. An image encoder and a text encoder are trained jointly to maximise the cosine similarity of the NN real pairs and minimise it for the N2−NN^{2}-N incorrect ones, optimising a symmetric cross-entropy loss over those similarity scores (§2.3). The embeddings come from a single linear projection of each encoder's representation — no non-linear projection.

FIG 1The better two vectors line up, the larger their dot product. Normalise both to unit length and the dot product is the cosine similarity — the single number CLIP uses to score an image against a sentence

Once training is done, images and sentences are unit vectors in the same space, and proximity is one dot product away. That is what "one map" means. The actual batch size is a very large 32,768, and the temperature τ\tau is optimised directly during training (§2.5).

What zero-shot classification actually is

Zero-shot classification is nothing more than reusing that pre-training capability. Take the names of every class in a dataset as the candidate texts, compute the cosine similarity against the image embedding, scale by the temperature, and normalise with a softmax (§3.1.2). Written out, with v\mathbf{v} denoting L2-normalised embeddings:

p(y=i∣I)=softmax⁡i ⁣(⟨vI,vTi⟩τ)p(y=i\mid I)=\operatorname{softmax}_i\!\left(\frac{\langle \mathbf{v}_I,\mathbf{v}_{T_i}\rangle}{\tau}\right)
(1)

⟨⋅,⋅⟩\langle\cdot,\cdot\rangle is the inner product — which, on normalised vectors, is exactly the cosine similarity — and τ\tau is the temperature. The paper describes this prediction layer as "a multinomial logistic regression classifier with L2-normalized inputs, L2-normalized weights, no bias, and temperature scaling" (§3.1.2). The temperature is learned, initialised to the equivalent of 0.07 and clipped so the logits are never scaled by more than 100 (§2.5).

FIG 2The same scores produce a sharper or flatter distribution depending on temperature. In CLIP the temperature is not a hand-set hyperparameter but a quantity optimised during training (§2.3)

Read this way, the text encoder is a hypernetwork that generates the weights of a linear classifier, and the image encoder is just a backbone (§3.1.2).

Wording the prompt is worth five points

Embedding bare class names creates two problems. One is polysemy: ImageNet contains both construction cranes and cranes that fly, and the boxer class in Oxford-IIIT Pets clearly means a dog breed in context, but to a context-free text encoder it could be an athlete. The other is a distribution gap — text in the pre-training data is usually a sentence, not a single word.

The fixes are concrete. Using A photo of a {label}. as the default alone improves ImageNet accuracy by 1.3%. For satellite imagery a satellite photo of a {label}. worked. Ensembling 80 different context prompts adds another 3.5%, for roughly 5% in total — comparable to using 4× more compute, and effectively free, since the ensemble is built in embedding space and amortises to the cost of a single classifier (§3.1.4).

The strengths and the failures are both sharp

Across the 27-dataset suite, zero-shot CLIP beats a supervised logistic regression fitted on ResNet-50 features on 16 of them. On ImageNet it reaches 76.2%, matching the original ResNet-50 without using a single one of the 1.28 million labelled examples, and on video action recognition it gains 14.5% on Kinetics700 and 7.7% on UCF101 (§3.1.3, §3.1.5).

The weak spots are equally clear: satellite imagery, lymph node tumour detection, counting objects in synthetic scenes, traffic signs, distance to the nearest car. Even on fine-grained tasks it loses by more than 10% on car models and aircraft variants. Measured as data efficiency, zero-shot is on par with a 4-shot logistic regression on the same feature space (§3.1.5).

Robustness deserves its own note. Across seven natural distribution shifts, ImageNet models lose a great deal of accuracy, and zero-shot CLIP closes up to 75% of that robustness gap. Yet adapting CLIP's features to ImageNet raises ImageNet accuracy by 9.2% to 85.4% while average accuracy under distribution shift slightly decreases. The paper says it does not have a confident answer for why (§3.3).

The limits the paper lists in §6

Note as of writing (2026) — an author's remark, not a claim of the paper: every number is this paper's own from 2021, with no later reproductions or improved variants included.

How this shows up on the job

CLIP shows up in production as similarity search for image retrieval and recommendation, as a moderation filter, and above all as a way to sift unlabelled image piles using words. In most of those cases nothing is trained.

The knobs are the prompt and the threshold. Do not feed bare class names; start from A photo of a {label}. and add domain words. Averaging several templates in embedding space and caching the result raises accuracy without raising cost (§3.1.4). The temperature is a learned value you simply use as-is.

Ways to get hurt. (1) Forget the L2 normalisation and the dot product stops being a cosine, so your threshold means nothing. (2) Polysemous class names — crane and boxer are the paper's own examples. (3) Counting and measuring barely work. (4) Nothing outside the class set can ever come out, so if you need "none of the above", write that sentence into the candidate set yourself (§3.1.5, §6).

Questions that come up in interviews. "Walk through zero-shot classification." — the text side builds a weight vector per class, take the dot product with the L2-normalised image embedding, divide by the temperature, softmax (§3.1.2). "Why contrastive rather than captioning?" — predicting exact words is too hard, and Figure 2 measured a 3× plus 4× efficiency gap (§2.3). "What does batch size affect?" — negatives come from the N2−NN^{2}-N mismatched pairs inside the batch, so the batch determines how many negatives you get. Note, though, that the paper never tests a smaller batch. For the image-side backbone, see the ViT paper deep dive.

Summary

Original paper: Radford et al., "Learning Transferable Visual Models From Natural Language Supervision" (arXiv:2103.00020, 2021)

References

  1. Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh et al.. (2021-02-26) Learning Transferable Visual Models From Natural Language Supervision. arXiv:2103.00020Paper page·PDF

This article is written from the source paper above. Where they differ, the original is authoritative.

Published by TechAthletes · Editorial policy · How we cite · Corrections

Comments

Sign in to comment