Research

Learning Transferable Visual Models From Natural Language Supervision

CLIP learns a shared image-text embedding space from 400 million image-caption pairs, enabling zero-shot image classification through natural-language prompts.

Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, Gretchen Krueger, Ilya SutskeverJul 18, 2021Proceedings of the 38th International Conference on Machine Learning (ICML 2021), PMLR 139:8748-876316 min readOpenAI
FOUNDATIONALComputer VisionAdvanced

Key takeaway

Train an image encoder and a text encoder to match correct image-caption pairs and separate mismatched pairs. At inference, compare an image embedding with embeddings of candidate class descriptions—no task-specific classifier training is required.

Updated on Nov 23, 2026

01

Abstract

Overview

CLIP learns visual representations from natural-language supervision. It is trained on 400 million image-text pairs collected from the internet. Instead of predicting a fixed set of labels, it learns to associate an image with its accompanying text. At inference, users describe candidate categories in natural language and CLIP scores how well each description matches an image. The paper evaluates transfer on more than 30 computer-vision datasets.

02

Background

Related work

CLIP builds on contrastive representation learning, including InfoNCE, and earlier work on learning visual features from captions. It draws on the Transformer for text encoding, ResNet and Vision Transformer image backbones, and prior natural-language supervision methods such as ConVIRT. Later systems including ALIGN, LiT, and SigLIP extend the broader vision-language pretraining paradigm.

03

Methodology

Core idea

Two encoders map images and text to vectors. In a batch of N matched pairs, the model assigns high similarity to the N correct pairings and low similarity to the N²−N incorrect pairings. This contrastive objective creates a shared embedding space. Candidate class descriptions can then act as a classifier without fitting a new classifier for each dataset.

Method

For each minibatch, encode all images and texts and compute the pairwise cosine-similarity matrix. Scale similarities using a learned temperature. Apply cross-entropy in both directions: image-to-text and text-to-image. The loss is the average of these two terms, with diagonal entries representing the true matched pairs. This symmetric contrastive objective is closely related to InfoNCE and multi-class N-pair loss.

Figure 1

Contrastive pre-training and zero-shot classification

(1) During pre-training, a batch of N image-caption pairs passes through an image encoder and a text encoder, each producing one embedding per input. The grid shows all N × N image-text similarity scores. Training raises the N correct pairs on the diagonal (blue) and lowers the N² − N mismatched pairs, so the model learns which caption belongs to which image instead of predicting the exact words of the caption. (2) To classify without labeled training data, each class name in the target dataset is placed in a prompt template such as "A photo of a {object}." and encoded by the text encoder. These text embeddings act as the weights of a linear classifier built from language alone. (3) A new image is embedded, compared with every class embedding, and assigned the class with the highest similarity, here "A photo of a dog." Standard image models train a fixed classifier over a fixed label set; CLIP's classifier can be rebuilt for any set of categories that can be written down.

Figure 1 from Radford et al. (2021), supplied by the user. Paper: ICML 2021.

Figure 2

Why CLIP uses a contrastive objective

Section 2.2 explains how the authors chose a training objective that scales. Their first attempt jointly trained an image CNN and a text Transformer to predict each image's exact caption (blue). It learned to recognize ImageNet classes three times more slowly than a simpler baseline that predicts a bag-of-words encoding of the same text (orange). Predicting exact captions is hard because many different captions can describe the same image. Switching to the contrastive objective, which only asks which caption goes with which image, gave a further 4x gain in efficiency (green). After 400M images, the contrastive model reaches about 41% zero-shot ImageNet accuracy against about 16% for the caption-predicting Transformer. This efficiency is what made training on 400 million image-text pairs practical.

Figure 2 from Radford et al. (2021), supplied by the user. Paper: ICML 2021.

04

Architecture

CLIP is a dual encoder. The image encoder is either a modified ResNet with attention pooling or a Vision Transformer. The text encoder is a causal Transformer using byte-pair encoding; its base model has 12 layers, width 512, eight attention heads, a 49,152-token vocabulary, and a maximum sequence length of 76. Each encoder output is linearly projected into a shared multimodal embedding space and L2-normalized. The strongest reported model is ViT-L/14@336px.

05

Training

Regularization and augmentation

Training uses Adam with decoupled weight decay on weights other than gains and biases, plus a cosine learning-rate schedule. The learned temperature is optimized directly and clipped to avoid unstable logits. Image augmentation is a random square crop of a resized image. Both encoders are trained from scratch rather than initialized from ImageNet or a pretrained language model.

Data and compute

The training corpus, called WIT (WebImageText), contains 400 million image-text pairs collected from publicly available internet sources. The authors train five ResNet variants and three Vision Transformers for 32 epochs, using a batch size of 32,768 and mixed precision. The largest ResNet (RN50x64) took 18 days on 592 V100 GPUs; the largest ViT took 12 days on 256 V100 GPUs. The best ViT-L/14 model received an additional epoch at 336-pixel resolution.

Implementation notes

A practical implementation needs image preprocessing, a tokenizer, an image encoder, a text Transformer, projection layers, and a symmetric contrastive loss. Normalize both embedding matrices, compute the scaled similarity matrix, and use matching batch indices as labels for cross-entropy in both directions. At inference, encode prompts such as “A photo of a {class}”, cache text embeddings, encode each image, and choose the class with the highest similarity. OpenAI released model code and pretrained weights.

Figure 3

The core of CLIP in a few lines

The pseudocode is the whole training objective. Each encoder (a ResNet or Vision Transformer for images, a Transformer for text) produces features, and a learned linear projection maps both into a shared embedding space, followed by L2 normalization so that dot products become cosine similarities. The n × n similarity matrix is scaled by a learned temperature t, so the sharpness of the softmax is trained rather than hand-tuned. Because the i-th image matches the i-th text, the correct labels are simply 0 to n − 1. Cross-entropy is applied along both axes, image-to-text and text-to-image, and the two losses are averaged, giving a symmetric contrastive loss. The paper keeps this deliberately simple: both encoders are trained from scratch, only linear (not non-linear) projections are used, and a random square crop is the only augmentation. The batch is very large, 32,768 pairs, so each image is contrasted with tens of thousands of wrong captions per step.

Figure 3 from Radford et al. (2021), supplied by the user. Paper: ICML 2021.

06

Results

Evaluation protocol

The paper evaluates zero-shot transfer by embedding natural-language class descriptions and comparing them with image embeddings, without training on the target dataset. It also reports linear-probe evaluations and compares against supervised systems across more than 30 datasets. Prompt engineering and prompt ensembling improve average zero-shot performance. Modern evaluation should add calibration, fairness, adversarial robustness, compositional reasoning, and contamination checks.

Figure 4

Zero-shot CLIP versus a supervised linear probe

Each bar compares zero-shot CLIP, which sees no training examples from the target dataset, with a fully supervised logistic-regression classifier trained on ResNet-50 features using the full labeled training set (Section 3.2). Green bars are datasets where zero-shot CLIP wins: 16 of 27, including ImageNet (+1.9). The largest wins are on fine-grained object categories such as cars and food, on geolocation (Country211) and on action recognition in video (Kinetics700, UCF101). The blue bars show the weakness: specialized, complex or abstract tasks such as satellite imagery (EuroSAT, RESISC45), counting objects (CLEVRCounts), lymph-node tumour detection (PatchCamelyon), traffic signs (GTSRB) and estimating distance to the nearest car (KITTI Distance). The authors question whether zero-shot evaluation is even meaningful for tasks, such as tumour classification, that most humans could not do without examples.

Figure 4 from Radford et al. (2021), supplied by the user. Paper: ICML 2021.

Figure 5

Linear-probe comparison with state-of-the-art vision models

Here CLIP is evaluated as a feature extractor: a linear classifier is trained on each model's frozen features, and the score is plotted against forward-pass compute per image (Section 3.3). Left: averaged over the 12 datasets of Kornblith et al. (2019), which are close to ImageNet. Right: averaged over all 27 datasets, which cover more varied tasks. Filled red stars are CLIP Vision Transformers and hollow red stars CLIP ResNets; dotted lines indicate evaluation at a higher resolution. The largest model, ViT-L/14 at 336 pixels, beats the previous best, Noisy Student EfficientNet-L2, by 2.6 points on average on the 12-dataset suite and by 5 points on the 27-dataset suite, so CLIP's advantage grows on more diverse tasks. Comparing the two red lines also shows that CLIP ViTs are about 3x more compute-efficient than CLIP ResNets.

Figure 6 from Radford et al. (2021), supplied by the user. Paper: ICML 2021.

Figure 6

Robustness to distribution shift

Left: each point is a model, with ImageNet accuracy on the x-axis and average accuracy on 7 natural distribution shift datasets on the y-axis. An ideally robust model would lie on the dashed y = x line. Standard ImageNet models (blue) and models using existing robustness techniques (grey) lose much more accuracy under shift than their ImageNet score suggests. Zero-shot CLIP models (purple) sit far closer to the ideal, shrinking this robustness gap by up to 75% (Section 3.4). Right: bananas, a class shared by 5 of the 7 datasets, show what changes: new photos, renditions and cartoons, unusual viewpoints, sketches and adversarially selected images. A ResNet-101 and the best zero-shot CLIP model both score 76.2% on ImageNet, yet CLIP keeps far more accuracy on the shifted sets, from 37.7% to 88.9% on ImageNet-R and from 2.7% to 77.1% on ImageNet-A. The authors suggest that models trained on ImageNet exploit patterns specific to that dataset, which zero-shot CLIP never sees.

Figure 7 from Radford et al. (2021), supplied by the user. Paper: ICML 2021.

07

Limitations

CLIP is not uniformly reliable. It can underperform on specialized or fine-grained tasks, struggle with counting and compositional relationships, and inherit social biases and harmful associations from web data. Zero-shot accuracy depends on prompt wording, class names, and label quality. The 400-million-pair dataset is not fully released as a reproducible public corpus, and training is expensive. Similarity scores are not automatically calibrated probabilities or explanations.

08

Conclusion

Contributions

The work demonstrates scalable image representation learning from natural-language supervision; introduces a practical contrastive dual-encoder recipe at 400-million-pair scale; establishes broad zero-shot transfer evaluation across more than 30 vision datasets; and shows that natural-language descriptions can dynamically define classification categories at inference time. It also analyzes robustness and prompt engineering.

Key takeaways

Contrastive learning turns paired images and captions into a shared semantic representation. A text encoder can generate classifiers dynamically from natural-language labels, enabling zero-shot transfer. Large web supervision is powerful, but data quality, prompt design, bias, and distribution shift remain important. CLIP is a dual encoder for matching and retrieval, not a generative image model.

FAQ

What does CLIP stand for? Contrastive Language–Image Pre-training.

How does CLIP learn? It matches correct image-caption pairs and distinguishes them from mismatched pairs in a batch.

What is zero-shot classification? Scoring an image against text descriptions of candidate classes without training on labeled examples from that target dataset.

How much data did the original paper use? 400 million image-text pairs, called WIT.

Is CLIP generative? No. Original CLIP is a dual-encoder representation and similarity model; it does not generate images or captions.

Continue reading

Related research

Browse all research