- Year of appearance
- 2021
- Researchers
- 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
- Organisation
- OpenAI
- Architecture type
- Dual-encoder contrastive model
- Learning mechanism
- self-supervised
- Tasks
- Zero-shot classification, Image–text retrieval
An image encoder and a text encoder trained together with a contrastive loss on 400 million image-text pairs, so they learn a shared space that enables classification without training examples.
Architecture diagram
Displayed configuration: CLIP ViT-B/32: 224 image + 77-token text, shared space 512 — A ViT-B/32 image encoder and a Transformer text encoder of width 512.
Layer table (13 nodes)
| Layer | Type | Input | Output | Repetition | Parameters | Formula | MACs |
|---|---|---|---|---|---|---|---|
| 224×224 image | input | 3 × 224 × 224 | 1 | 0 | — | ||
| Text (77 BPE tokens) | input | 77 | 1 | 0 | — | ||
| 32×32 patches + [class] + position | patch | 3 × 224 × 224 | 50 × 768 | 1 | 2,398,464 | From the reference PyTorch implementation | 115,605,504 |
| LayerNorm before the encoder | ln | 50 × 768 | 50 × 768 | 1 | 1,536 | From the reference PyTorch implementation | 0 |
| Transformer encoder × 12 (768, 12 heads) | encoder | 50 × 768 | 50 × 768 | 12 | 7,087,872 | From the reference PyTorch implementation | 357,734,400 |
| LayerNorm on [class] | ln | 768 | 768 | 1 | 1,536 | From the reference PyTorch implementation | 0 |
| Linear projection → 512 | projection | 768 | 512 | 1 | 393,216 | From the reference PyTorch implementation | 393,216 |
| Token + position embedding | embed | 77 | 77 × 512 | 1 | 25,336,320 | From the reference PyTorch implementation | 0 |
| Transformer with masked attention × 12 (512, 8 heads) | masked_mha | 77 × 512 | 77 × 512 | 12 | 3,152,384 | From the reference PyTorch implementation | 248,292,352 |
| LayerNorm on the [EOS] token | ln | 77 × 512 | 77 × 512 | 1 | 1,024 | From the reference PyTorch implementation | 0 |
| Linear projection → 512 | projection | 512 | 512 | 1 | 262,144 | From the reference PyTorch implementation | 262,144 |
| Cosine similarity × e^t | process | 512, 512 | N × N | 1 | 1 | Learned logarithmic temperature (logit_scale) | 512 |
| Symmetric contrastive loss | loss | N × N | L | 1 | 0 | — |
Configuration figures: CLIP ViT-B/32: 224 image + 77-token text, shared space 512
- Input shape
- A 3×224×224 image and a 77-token text
- Output shape
- Two 512 representations + similarity
- Depth
- 12 + 12 layers
- Complexity
- The two encoders are independent: image and text representations can be precomputed for retrieval.
- MACs note
- For one image and one text (77 tokens).
MAC = a multiplication followed by an addition. The figures are for one forward pass of one sample with the stated dimensions; they are an analytical calculation, not a measurement of run time.
Scientific explanation
Historical background
Published at ICML 2021 by OpenAI; it matched ResNet-50 on ImageNet without using any image from its data, and its text and image encoders became components in generative models such as Stable Diffusion.
The problem it addresses
Vision models trained on fixed classes do not generalise to new concepts without labelled data.
Core idea
Learning from the natural supervision in the text that accompanies images: predicting which text goes with which image within the batch.
Architecture description
An image encoder (ResNet or ViT) and a text encoder (Transformer), two linear projections into a shared space, and a learned temperature.
Data flow
Image → ViT → u; text → Transformer → v; s = cos(u, v)/τ → contrastive loss. For classification: “a photo of a {class}” for each class → highest similarity.
Inputs
An image and a text.
Outputs
Two representations in a shared space and a similarity score.
Training procedure
A batch of 32,768 pairs, Adam with weight decay, a cosine schedule, and 32 epochs on the WIT dataset (400 million pairs).
Loss functions
Symmetric cross-entropy on the similarity matrix (InfoNCE).
Computational complexity
Two independent encoders; about 7.4 billion multiply-adds for an image and a text in ViT-B/32 (computed here).
Computational requirements
The largest model, ViT-L/14, was trained for 12 days on 256 V100 GPUs.
Advantages
- Classification without training examples
- Strong transferable representations
- Efficient retrieval with two independent encoders
Limitations
- Weak at counting and spatial relationships
- Biases of web data
- Sensitive to the wording of the text (prompt engineering)
Equations
Symmetric contrastive loss Symmetric contrastive loss (InfoNCE)
\mathcal{L} = \frac{1}{2}\left[\frac{1}{N}\sum_{i=1}^{N} -\log \frac{e^{s_{ii}/\tau}}{\sum_{j} e^{s_{ij}/\tau}} + \frac{1}{N}\sum_{i=1}^{N} -\log \frac{e^{s_{ii}/\tau}}{\sum_{j} e^{s_{ji}/\tau}}\right],\quad s_{ij} = \frac{\mathbf{u}_i^\top \mathbf{v}_j}{\lVert \mathbf{u}_i \rVert \lVert \mathbf{v}_j \rVert}Each image must match its text among the N texts in the batch, and vice versa.
Symbols: τ: learned temperature, u: image representation, v: text representation
Zero-shot classification Zero-shot prediction
\hat{y} = \arg\max_{c} \; \cos\!\big(f_I(\mathbf{x}),\, f_T(\text{“a photo of a } c\text{”})\big)Each class is represented by a text that describes it.
Symbols: f_I, f_T: the encoders
Projection into the shared space Joint embedding
\mathbf{u} = \frac{W_i f_I(\mathbf{x})}{\lVert W_i f_I(\mathbf{x}) \rVert},\quad \mathbf{v} = \frac{W_t f_T(\mathbf{t})}{\lVert W_t f_T(\mathbf{t}) \rVert}A linear projection, then L2 normalisation.
Applications
Related models
- LLaVA (Large Language and Vision Assistant) — The vision encoder from CLIP. Compare
- Uses a component of Vision Transformer (ViT) — The image encoder is a ViT. Compare
- Uses a component of Stable Diffusion — The text encoder in Stable Diffusion comes from CLIP. Compare
- Successor of BLIP (Bootstrapping Language-Image Pre-training) — BLIP adds generation and matching. Compare
- Stable Diffusion — The text encoder from CLIP. Compare
- Uses a component of LLaVA (Large Language and Vision Assistant) — LLaVA uses a CLIP image encoder. Compare
- Vision Transformer (ViT) — The image encoder in CLIP is a ViT. Compare
- Uses a component of Transformer — The text encoder is a Transformer. Compare
- Latent Diffusion Model — A CLIP text condition in Stable Diffusion. Compare
References
- Original 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. ICML 2021 (PMLR 139). arXiv:2103.00020 Verified
- Related reference Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, Jakob Uszkoreit, Neil Houlsby. (2021). An image is worth 16x16 words: Transformers for image recognition at scale. ICLR 2021. arXiv:2010.11929 Verified
Version 1 — last updated 2026-11-15.
