XYZNOT

Papers · arXiv 2103.00020

Learning Transferable Visual Models From Natural Language Supervision

Published cs.CVcs.LG arXivPDF

Read with translation and AI

Summary in three lines

  1. 🎯 Standard computer vision systems depend on fixed, predetermined label sets that require costly annotations and cannot generalize to novel visual concepts.
  2. 🔧 Contrastive Language-Image Pre-training (CLIP) jointly trains an image encoder and a text encoder to maximize cosine similarity for matched image-caption pairs across large batches using a symmetric cross-entropy loss.
  3. 📈 Matches the 76.2% top-1 accuracy of a fully supervised ResNet-50 on ImageNet zero-shot without using any of ImageNet's 1.28M labeled examples.

Abstract

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.

Reading guide

Problem and motivation

State-of-the-art vision models traditionally rely on crowd-labeled, closed-set classification benchmarks such as ImageNet. This fixed-label paradigm restricts their usability: recognizing any concept outside the target vocabulary requires collecting and annotating new data. Conversely, natural language processing had successfully shifted toward task-agnostic pre-training directly on web-scale text (e.g., GPT-3), producing models capable of zero-shot generalization via text-to-text interfaces. The authors investigate whether scaling natural language supervision on web-scale data can yield visual representations that generalize broadly across computer vision tasks without dataset-specific supervised fine-tuning.

Key ideas

  • Learning from Natural Language Supervision: Treating web-scraped (image, text) pairs as training signals connects visual features directly to rich natural language semantics, bypassing 1-of-N discrete class labeling.
  • Contrastive Learning for Efficiency: Predicting exact text tokens (generative captioning) is computationally wasteful. Formulating the objective as a contrastive matching task—distinguishing true (image, text) pairs from incorrect pairs across a minibatch—proves 4x more sample-efficient than bag-of-words prediction and far faster than generative modeling.
  • Zero-Shot Classification as Dynamic Linear Classifiers: Target dataset classes are embedded through the text encoder into feature vectors. These vectors serve as weights for a zero-shot linear classifier against the image embeddings.
  • Prompt Engineering and Ensembling: Zero-shot performance is sensitive to prompt syntax and context. Wrapping class names in full sentences (e.g., "A photo of a {label}.") and ensembling across multiple prompt variations improves zero-shot transfer by roughly 5 points on ImageNet.

Method (with the key equations)

CLIP constructs a multi-modal embedding space by jointly training an image encoder and a text encoder on a dataset of 400 million internet-scraped (image, text) pairs (WIT).

  1. Feature Extraction and Projection: Given a minibatch of image-text pairs for , each encoder maps inputs to a joint dimension with linear projections and :

  2. Similarity Matrix: Logits are computed via scaled cosine similarity: where is a learnable temperature parameter initialized to 0.07, clipped to prevent scaling logits beyond 100.

  3. Symmetric Cross-Entropy Loss: The total loss is the average of image-to-text and text-to-image classification losses over the pairing matrix:

  4. Zero-Shot Inference: For a dataset with classes, text templates (e.g., "a photo of a {class_name}") are encoded into . For test image , predicted probabilities are:

Results (with the most important numbers)

  • Zero-Shot ImageNet: CLIP (ViT-L/14@336px) reaches 76.2% top-1 accuracy (and 95% top-5 accuracy) zero-shot on ImageNet, matching the original supervised ResNet-50 without using its 1.28 million training images.
  • Zero-Shot vs. Supervised Baseline: Evaluated across 27 downstream datasets, zero-shot CLIP outperforms a fully supervised linear probe on top of standard ResNet-50 features on 16 of the 27 datasets.
  • Few-Shot Comparison: Zero-shot CLIP matches the average performance of a 4-shot linear classifier trained on the exact same CLIP feature representations, and rivals a 16-shot BiT-M ResNet-152x2 model.
  • Linear Probe Representation Quality: When evaluating frozen representations with supervised linear probes, CLIP's best model outperforms Noisy Student EfficientNet-L2 on 21 of 27 datasets, excelling in OCR, video action recognition (Kinetics-700: +14.5% over ResNet-50), and geo-localization.
  • Distribution Shift Robustness: Across 7 natural distribution shift datasets (ImageNetV2, ImageNet-R, ImageNet-A, ObjectNet, etc.), zero-shot CLIP reduces the drop between in-distribution and out-of-distribution accuracy by up to 75% compared to standard ImageNet-trained models.

Limitations and open questions

  • Abstract, Specialized, and Systematic Tasks: Zero-shot CLIP struggles severely with counting (CLEVRCounts), fine-grained tasks with narrow distinctions (FGVCAircraft, Flowers102), and domain-specific tasks outside web text commonality (tumor detection on PatchCamelyon; distance estimation on KITTI).
  • Truly Out-of-Distribution Data: On MNIST handwritten digits, zero-shot CLIP achieves only 88% accuracy—underperforming logistic regression on raw pixels—demonstrating that CLIP circumvents rather than solves out-of-distribution brittleness.
  • Compute Requirements: Reaching overall supervised state-of-the-art across all benchmarks purely zero-shot is estimated to require an estimated 1000x increase in compute with existing scaling trends.
  • Social Biases and Denigration: Probing with the FairFace benchmark reveals significant disparate failure modes, including non-human and crime-related misclassifications skewed toward Black individuals and youth, which vary heavily with class label design and thresholding.

Key terms

CLIP
Contrastive Language-Image Pre-training; a framework that jointly trains image and text encoders using a contrastive objective over paired web data.
WIT
WebImageText; OpenAI's curated dataset of 400 million (image, text) pairs collected from internet sources using 500,000 query terms.
Zero-Shot Transfer
Evaluating a model on unseen datasets and tasks using natural language concept descriptions without updating parameters on the target task.
Prompt Engineering
Formulating class names into natural language context templates (e.g., 'A photo of a {label}, a type of pet.') to bridge the pre-training text distribution gap.
Prompt Ensembling
Averaging the text embedding vectors generated from multiple different context prompts for the same class before computing classification similarity.
Effective Robustness
Improvements in out-of-distribution accuracy beyond what is expected from in-distribution performance according to standard baseline scaling trends.
Linear Probe
A supervised, regularized linear classification layer trained on top of frozen pre-trained feature representations to measure representation quality.
Attention Pooling
A modified spatial pooling layer for ResNet backbones implemented as single-layer multi-head QKV attention conditioned on global average-pooled features.

Questions

Why did CLIP choose contrastive learning over image caption generation?

Generative captioning models try to predict exact text tokens, which requires immense compute due to wide caption variability. Contrastive learning solves the simpler proxy task of matching full texts to images, proving 4x more compute-efficient than bag-of-words prediction and over an order of magnitude more efficient than generative models.

How does zero-shot classification work at test time in CLIP?

Every candidate class label is placed into a text prompt template and embedded via the text encoder. These normalized embeddings act as the fixed weight vectors of a dynamic linear classifier, evaluated against normalized image embeddings via cosine similarity and softmax.

Why is zero-shot CLIP more robust to distribution shifts than supervised ImageNet models?

Supervised ImageNet models frequently memorize spurious correlations and surface statistics specific to ImageNet's visual distribution. Zero-shot CLIP avoids fine-tuning on the target training distribution, substantially shrinking the performance gap when evaluated on distribution-shifted datasets like ImageNet-A, ObjectNet, and ImageNet-R.

Does training set overlap explain CLIP's strong zero-shot benchmark results?

No. Data de-duplication analysis found a median overlap of only 2.2% across 35 downstream datasets. Removing overlapping samples rarely changed evaluation accuracy by more than 0.1%, with a maximum detected improvement of just 0.6% on Birdsnap.

The overview on this page was written by AI from the paper and may contain mistakes. Read the paper for the details.

Read with translation and AI