# Learning Transferable Visual Models From Natural Language Supervision

Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal and 6 more · arXiv · 2021-2-26

- **Problem** Vision models trained on fixed label sets need new labeled data for every new concept, and earlier text-supervised image models were small and narrowly scoped.
- **Method** Trains an image encoder and a text encoder from scratch on 400 million web image-text pairs with a batch contrastive loss, then builds zero-shot classifiers from class-name text.
- **Results** The best CLIP model reached 76.2% zero-shot top-1 accuracy on ImageNet, matching the original ResNet-50 without its 1.28 million training examples.

## Why fixed label sets limit vision models

Most vision models are trained to predict a fixed inventory of labels, so every new concept needs new labeled examples before the model can recognize it. Text that already accompanies images on the web names a much wider range of concepts, which raises the question of whether supervision taken directly from that text can produce image representations that transfer.

Language modeling offers a precedent. Objectives that learn from raw text, together with output formats that let one architecture serve many tasks, have carried over to new datasets without task-specific output heads. Computer vision still pre-trains on crowd-labeled sets such as ImageNet, which has 1.28 million training examples in the setting the authors compare against.

Earlier weakly supervised work moved toward web text but kept its supervision narrow, with 1000 and 18291 classes in the two cited cases and static softmax classifiers that cannot accept new class names at test time.

## Building a 400 million pair dataset

MS-COCO and Visual Genome are high quality but have about 100,000 training photos each, and YFCC100M has 100 million photos with sparse and uneven metadata. Keeping only images with English titles or descriptions shrank YFCC100M by a factor of 6, to about 15 million photos, roughly the size of ImageNet. The authors therefore built a new collection of 400 million (image, text) pairs from publicly available internet sources, which they call WIT.

Collection was query-driven. A pair was kept when its text matched one of 500,000 queries, and the queries came from frequent English Wikipedia words, bigrams, Wikipedia article names and WordNet synsets. To balance coverage, each query contributed up to 20,000 pairs, and the total word count is similar to that of WebText, the data used to train GPT-2.

## Why predict the pairing instead of the words

The first design was generative: an image CNN and a text transformer trained from scratch to produce the caption of each image, similar to VirTex.

The authors attribute the difficulty to caption variety: exact words are a hard target when many descriptions, comments and related texts co-occur with an image. Contrastive objectives were reported to learn better image representations than predictive ones, and generative image models needed over an order of magnitude more compute for the same performance, so the authors chose a proxy task instead: predict which text as a whole goes with which image.

Keeping the bag-of-words encoding and replacing its predictive objective with the contrastive objective gave a further 4x efficiency improvement in the rate of zero-shot transfer to ImageNet. Figure 2 plots zero-shot ImageNet accuracy against the number of images processed, from 2M to 400M, for the three objectives.

## The batch contrastive loss

Each batch holds N image-text pairs. The model must tell the N matched pairs apart from the N²−N mismatched combinations that the same batch creates. Each image and each text is encoded, mapped by a learned linear projection into a shared multimodal space, and L2-normalized, so that their dot products are cosine similarities.

The normalized similarities form an N×N matrix that is multiplied by the exponential of the learned temperature t: \\\[ \\text{logits} = I\_e\\,T\_e^{\\top}\\,\\exp(t) \\\] Cross entropy is taken along each axis of that matrix, with the index of each pair as its label, and the two terms are averaged: \\\[ \\text{loss} = \\tfrac{1}{2}\\,(\\text{loss}\_i + \\text{loss}\_t) \\\] The loss is symmetric, so a matched pair is treated as correct from both the image side and the text side.

The temperature is a learned log-parameterized multiplicative scalar, initialized to the equivalent of 0.07 and clipped so the logits are scaled by at most 100, which the authors found necessary for training stability.

Several parts of the usual recipe were dropped. The projection into the embedding space is linear rather than non-linear, and the authors did not notice a difference in training efficiency between the two. The sentence-sampling text transformation was removed because most pairs contain a single sentence, and the only image augmentation is a random square crop from resized images.

Training starts from scratch, without ImageNet weights or pre-trained text weights, and the authors argue that over-fitting is not a major concern at this data size.

## Image and text encoders

The ResNet-50 image encoder gets three changes: the ResNet-D improvements from He et al. (2019), antialiased rect-2 blur pooling, and attention pooling in place of the global average pooling layer. The attention pooling is one multi-head attention layer whose query is built from the global average-pooled image representation.

The second image encoder is the Vision Transformer, followed closely from its original implementation. The one added change is a layer normalization applied to the combined patch and position embeddings, together with a slightly different initialization. The text encoder is a transformer with the architecture modifications described for GPT-2, with a base size of 63M parameters, 12 layers, 512 width and 8 attention heads.

Text is lower-cased and encoded with byte pair encoding over a 49,152 vocabulary, and sequences are capped at 76 tokens and bracketed by start and end tokens. The top-layer activation at the end-of-sequence token is layer normalized and linearly projected into the shared space, and that vector is the text representation. Masked self-attention was kept so the encoder could later be initialized from a language model or trained with a language modeling objective; the authors left that for future work.

For the ResNets, extra compute is spread across width, depth and resolution together, following the Tan and Le (2019) finding, but with equal allocation instead of tuned ratios. The text encoder is scaled only in width, in proportion to the ResNet width increase, because the authors found CLIP less sensitive to text encoder capacity.

## Training configuration and cost

The series covers eight models, five ResNets and three Vision Transformers, including RN50x4, RN50x16 and RN50x64 with about 4x, 16x and 64x the compute of ResNet-50, and ViT-B/32, ViT-B/16 and ViT-L/14. All models train for 32 epochs with Adam, with decoupled weight decay on all weights except gains and biases, and a cosine learning rate schedule.

Initial hyper-parameters were set by grid search, random search and manual tuning on the ResNet-50 baseline trained for one epoch, then adapted heuristically for larger models because of compute limits.

The minibatch size is 32,768. Mixed precision, gradient checkpointing, half-precision Adam statistics and half-precision stochastically rounded text encoder weights reduce time and memory. The similarity computation is sharded so that each GPU computes only the pairwise similarities for its local batch of embeddings.

The largest ResNet, RN50x64, trained for 18 days on 592 V100 GPUs, and the largest Vision Transformer trained for 12 days on 256 V100 GPUs. ViT-L/14 received one extra epoch at a higher 336 pixel resolution, giving ViT-L/14@336px, which is the best zero-shot CLIP model in the robustness analysis.

## Zero-shot classification with class names

Here zero-shot transfer means generalization to unseen datasets rather than to unseen categories, and the authors use it as a proxy for task learning rather than only as a test of robustness.

At test time, the class names of the target dataset are embedded by the text encoder as candidate texts, and the image embedding is compared with each of them by cosine similarity. The similarities are scaled by the temperature and normalized with a softmax, so the prediction is a multinomial logistic regression with L2-normalized inputs and weights, no bias and temperature scaling.

Figure 1 summarizes the setup: pairs are matched in a batch during training, a classifier is built from label text, and predictions are made by scoring each image against those texts.

The text encoder acts as a hypernetwork that generates the weights of a linear classifier from the text describing each class. Because the generated classifier can be cached after it is computed, its cost is spread over every prediction made on a dataset.

## Prompt wording and ensembling

Many datasets name classes with a single label, and the text encoder cannot tell word senses apart without context. ImageNet contains both construction cranes and cranes that fly, and the word boxer in Oxford-IIIT Pets can mean a dog breed or an athlete.

Most pre-training texts are full sentences rather than single words, so the authors used the template A photo of a {label}. as a default, which raised ImageNet accuracy by 1.3% over label text alone. Task-specific wording also helped: a pet phrase for Oxford-IIIT Pets, a food phrase for Food101, an aircraft phrase for FGVC Aircraft, quotation marks around text for OCR, and a satellite phrase for satellite imagery.

Ensembling averages the text embeddings of several context prompts, such as a big and a small version of the template, so one averaged classifier can be cached. Across 36 datasets, prompt engineering and ensembling raised average zero-shot performance by almost 5 points over contextless class names.

## ImageNet and Visual N-Grams comparison

The best CLIP model reached 98.4 on aYahoo, 76.2% on ImageNet and 58.5 on SUN.

Its top-5 accuracy is 95%, which the authors describe as matching Inception-V4.

The comparison is not controlled. CLIP uses a dataset 10x larger, a vision model needing nearly 100x more compute per prediction, a transformer-based text model, and likely over 1000x the training compute. As a closer comparison, the authors trained a CLIP ResNet-50 from scratch on the same YFCC100M data and found it matched the reported ImageNet performance of Visual N-Grams within a V100 GPU day.

The wider evaluation covers over 30 datasets and compares against over 50 existing computer vision systems, with details in an appendix.

## Robustness under distribution shift

The authors compare zero-shot CLIP with ImageNet-trained models on seven natural distribution shift datasets, using ImageNet accuracy as the in-distribution reference. Zero-shot CLIP models improve effective robustness by a large amount and shrink the gap between ImageNet accuracy and accuracy under shift by up to 75%.

Adapting CLIP to ImageNet with an L2 regularized logistic regression fit on ImageNet training features raised ImageNet accuracy by 9.2% to 85.4%.

The authors do not know whether the robustness gap comes from ImageNet training, from the large and diverse pre-training data, or from natural language supervision. They have no confident answers on whether the pattern holds for end-to-end fine-tuning, or whether it is a general phenomenon.

Using a dataset-specific zero-shot classifier built from class names, rather than pooled ImageNet predictions, improved average effective robustness by 5%, with large gains on a few datasets.

## Bias probes on FairFace

The analysis uses FairFace, a face dataset built to balance age, gender and race, with gender split into two groups, female and male. Class design matters for this analysis because any developer can define a class and the model will return some result.

On the FairFace White category, zero-shot CLIP scores 58.3 on race classification, against 93.4 for the linear probe on CLIP features and 93.7 for the FairFace model. Its gender and age scores in that category are 95.9 and 57.1, against 96.5 and 63.8 for the linear probe on CLIP features.

On the grouped non-White categories, zero-shot CLIP scores 91.3 on race, against 75.4 for the FairFace model and 92.8 for the linear probe on CLIP features. Within the zero-shot results, race accuracy is far lower for the White category, at 58.3, than for the grouped non-White categories, at 91.3.

The authors present these bias probes as preliminary and call for broader, more contextual testing schemes so that developers can characterize bias in general purpose vision models.

## Limitations

Zero-shot CLIP is still weak on fine-grained classification such as car models, flower species and aircraft variants, and on counting objects. It can be near random on novel tasks such as judging the distance to the nearest car.

Zero-shot CLIP reaches only 88% accuracy on handwritten MNIST digits, and a logistic regression on raw pixels outperforms it. Near-duplicate and semantic retrieval both show that almost no pre-training images resemble MNIST digits, so the assumption that large, varied data makes everything in-distribution is easy to violate.

CLIP is limited to the concepts in its given zero-shot classifier, which is a real restriction compared with image captioning, which can generate novel outputs. The authors suggest that combining a contrastive and a generative objective, or searching over natural language explanations at inference time, could help, but the paper does not test either idea.

CLIP compensates for poor data efficiency with a source of supervision that scales to hundreds of millions of examples. At one image per second, the 12.8 billion images seen over 32 training epochs would take 405 years to iterate through.

## Paper info

- **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
- **Venue**: arXiv · Preprint
- **First published**: 2021-2-26
- **Added**: 2026-10-20
- **Updated**: 2021-2-26
- **Version**: v1
- **arXiv**: 2103.00020
- **Category**: cs.CV · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2103.00020v1) · [PDF ↗](https://arxiv.org/pdf/2103.00020v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

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 (2021). Learning Transferable Visual Models From Natural Language Supervision. arXiv:2103.00020v1. https://arxiv.org/abs/2103.00020v1

**BibTeX**

```
@misc{radford2021learning,
  title = {{Learning Transferable Visual Models From Natural Language Supervision}},
  author = {Alec Radford and Jong Wook Kim and Chris Hallacy and Aditya Ramesh and Gabriel Goh and Sandhini Agarwal and Girish Sastry and Amanda Askell and Pamela Mishkin and Jack Clark and Gretchen Krueger and Ilya Sutskever},
  year = {2021},
  eprint = {2103.00020},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2103.00020v1}
}
```

## Other paper commentary

- [An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale](https://refivu.com/en/papers/8a112940-90e3-4c6b-8fa0-d576b3ebd5d1-an-image-is-worth-16x16-words-transformers-for.md)
- [Deep Residual Learning for Image Recognition](https://refivu.com/en/papers/19d6446d-fd9a-4e80-b535-a4e333cad216-deep-residual-learning-for-image-recognition.md)
- [ArcFace: Additive Angular Margin Loss for Deep Face Recognition](https://refivu.com/en/papers/c413067c-e2eb-43a0-8011-b952f120296a-arcface-additive-angular-margin-loss-for-deep-face.md)
- [Memory as Dynamics: Learning Reliability-Guided Predictive Models for Online Video Perception](https://refivu.com/en/papers/9edb7769-5017-4985-b695-21eab77d07d7-memory-as-dynamics-learning-reliability-guided-predictive.md)
- [Breaking Semantic Artifacts for Generalized AI-generated Image Detection](https://refivu.com/en/papers/4e046749-44ad-45fe-a59b-ca849df10c45-breaking-semantic-artifacts-for-generalized-ai-generated.md)
- [Demographic Encoding is Not Exposure: Fairness and Privacy in Chest X-ray Foundation Models](https://refivu.com/en/papers/d91f434f-7371-40be-9129-9d3da0b4398c-demographic-encoding-is-not-exposure-fairness-and-privacy.md)
- [Efficient Estimation of Word Representations in Vector Space](https://refivu.com/en/papers/d295cb4b-dace-4ef1-9199-b860d9b1f123-efficient-estimation-of-word-representations-in-vector-space.md)
- [Sequence to Sequence Learning with Neural Networks](https://refivu.com/en/papers/2ac7aa06-39ab-48fb-868d-81dbac5767e6-sequence-to-sequence-learning-with-neural-networks.md)
- [Proximal Policy Optimization Algorithms](https://refivu.com/en/papers/831b67ec-e2f9-4c8f-914d-dc9387e23e27-proximal-policy-optimization-algorithms.md)
- [RoBERTa: A Robustly Optimized BERT Pretraining Approach](https://refivu.com/en/papers/3dc17b50-5c0f-4503-a368-4b0d9e86745c-roberta-a-robustly-optimized-bert-pretraining-approach.md)
- [Auto-Encoding Variational Bayes](https://refivu.com/en/papers/90411040-94ff-4aca-9d04-a1a99cad3eb4-auto-encoding-variational-bayes.md)
- [Deep contextualized word representations](https://refivu.com/en/papers/13952ebe-dec9-4497-bba2-03f142631507-deep-contextualized-word-representations.md)

## Terms in this paper

- [Accuracy](https://refivu.com/en/terms/1995c0cd6282-accuracy)
- [ResNet-50](https://refivu.com/en/terms/eb2323a60a89-resnet-50)
- [CLIP](https://refivu.com/en/terms/b5b5b48d5f4e-clip)
- [top-5 accuracy](https://refivu.com/en/terms/6de0752ac469-top-5-accuracy)
- [Vision Transformer](https://refivu.com/en/terms/143abf165d88-vision-transformer)
- [temperature parameter](https://refivu.com/en/terms/b658de9c95b2-temperature-parameter)
- [linear probe](https://refivu.com/en/terms/ac513e2ee27c-linear-probe)
- [Ensembling](https://refivu.com/en/terms/e69eb594db3c-ensembling)
- [zero-shot transfer](https://refivu.com/en/terms/a0916de197e6-zero-shot-transfer)
- [attention pooling](https://refivu.com/en/terms/a423ed742b94-attention-pooling)
- [contrastive objective](https://refivu.com/en/terms/f89b70b11f15-contrastive-objective)
- [effective robustness](https://refivu.com/en/terms/8d65c5848b7b-effective-robustness)
- [text encoder](https://refivu.com/en/terms/4db9b6de3471-text-encoder)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/c2ad57ff-fd96-4ad1-af27-4195a16c557d-learning-transferable-visual-models-from-natural-language)
