↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Zero-shot answer for I1 Loading… Both encoders · all 12 blocks and every head recorded · image encoder bidirectional, text encoder causal
Loading recorded inference…

What a contrastive dual encoder is

An image classifier is trained to pick one of a fixed list of labels. CLIP learns from captions instead. Two separate encoders, one for images and one for text, map their inputs into the same 512-dimensional space, and training pulls each image towards its own caption and away from the other captions in the batch. Afterwards any text can serve as a label: write each class as a caption, embed it, and pick the caption that lies closest to the image. That is zero-shot classification, with no training on the classes themselves.

The page records CLIP ViT-B/32 (151,277,313 parameters) on 4 images (coloured shapes, a cat, a beagle, an astronaut) and 5 captions: “a drawing of colored shapes”, “a photo of a cat”, “a photo of a dog”, “a photo of an astronaut” and “a photo of a beagle”. Each encoder runs once per input, and the page shows all 12 blocks of both.

Two encoders

The Image Encoder ViT-B/32 row is a Vision Transformer (see the ViT tab). The 224 × 224 image is cut into a 7 × 7 grid of 32-pixel patches, each projected to width 768, and a learned [CLS] token is prepended: 50 tokens. Position embeddings are added and a pre-LayerNorm applied, then 12 bidirectional blocks follow, with 12 heads of 64 and an MLP, 768 → 3072 → 768. The MLP uses QuickGELU, OpenAI CLIP's sigmoid approximation of GELU, with which these weights were trained:

The Text Encoder causal transformer row reads the caption as byte-pair tokens from a 49,408-token vocabulary. Every caption here is 7 tokens: start-of-text, five words and end-of-text (EOT). Its 12 blocks of width 512 with 8 heads use a causal mask, like a GPT decoder, so only EOT has read the whole caption; the text encoder therefore pools at EOT, as the image encoder pools at [CLS].

One shared space

The Pool & project columns take the pooled vector through a final LayerNorm and a bias-free projection into the shared space, 768 → 512 for images and 512 → 512 for text, then divide it by its length so it lies on the unit sphere:

On the unit sphere the dot product is the cosine. The Similarity matrix multiplies it by a learned logit scale; this checkpoint stores its logarithm, 4.6052, so the scale is 100.0:

The cosines themselves are small: the matching pairs score between 0.28 and 0.31 and the others between 0.13 and 0.24. Image and text vectors sit in different regions of the sphere, and only the differences between captions matter. The scale of 100 turns those differences into decisive logits. In the CLIP paper the same quantity is written as a temperature , initialised to 0.07 and clipped so that cannot exceed 100; trained CLIP sits at that cap. The page's is the stored logarithm, so the two notations differ.

Zero-shot classification

For one image, a softmax over the captions turns its row of the matrix into probabilities:

The Which caption? list shows them. Each image's top caption is a correct one: 99.9 % for the drawing, 99.3 % for the cat and 100.0 % for the astronaut. The beagle matches two captions and the softmax has to share between them: 88.8 % “a photo of a beagle” and 11.2 % “a photo of a dog”. These probabilities exist only relative to these five captions; another set of captions gives another softmax. The CLIP paper's prompts follow this pattern (“a photo of a {label}”), and it found that such templates classify better than bare class names.

Training with the symmetric contrastive loss

Training takes a batch of image–caption pairs and computes the full matrix of scaled similarities. Each image should pick out its own caption among the , and each caption its own image, so the loss averages a cross-entropy along the rows and one along the columns, with the matching pair as the target:

Each term is the InfoNCE loss of contrastive predictive coding, applied in both directions; ConVIRT had used this bidirectional form for medical images and their reports. The other captions in the batch serve as negatives, so larger batches give harder comparisons. CLIP trained on 400 million image–text pairs collected from the internet and matched the original ResNet-50's ImageNet accuracy zero-shot. The page records inference only.

Where it came from

ConVIRT (2020) introduced the bidirectional image–text contrastive objective on medical images and their reports. CLIP (Radford et al., 2021) scaled it to the open web, and ALIGN trained the same kind of dual encoder on over a billion noisy alt-text pairs. OpenCLIP retrained CLIP on public data and measured how it scales. SigLIP replaced the softmax over the batch with an independent sigmoid for every pair; a SigLIP encoder is the vision half of the VLM tab's SmolVLM. SAM 3 reads its concept prompts with a CLIP-style text encoder.

Papers

  1. Learning Transferable Visual Models From Natural Language Supervision Alec Radford et al. · ICML 2021 CLIP, the model this page records: dual encoders trained contrastively on 400 million image–text pairs, and zero-shot classification with captions.
  2. Contrastive Learning of Medical Visual Representations from Paired Images and Text Yuhao Zhang, Hang Jiang, Yasuhide Miura, Christopher D. Manning, Curtis P. Langlotz · MLHC 2022 ConVIRT: the bidirectional image–text contrastive objective that CLIP adopts.
  3. Representation Learning with Contrastive Predictive Coding Aaron van den Oord, Yazhe Li, Oriol Vinyals · arXiv 2018 The InfoNCE loss: pick the true pair among negatives with a softmax.
  4. An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale Alexey Dosovitskiy et al. · ICLR 2021 The Vision Transformer, CLIP's image encoder here with 32-pixel patches.
  5. Scaling Up Visual and Vision-Language Representation Learning With Noisy Text Supervision Chao Jia et al. · ICML 2021 ALIGN: the same dual-encoder recipe on over a billion uncurated alt-text pairs.
  6. Reproducible scaling laws for contrastive language-image learning Mehdi Cherti et al. · CVPR 2023 OpenCLIP: CLIP retrained on public LAION data, with scaling laws for model, data and compute.
  7. Sigmoid Loss for Language Image Pre-Training Xiaohua Zhai, Basil Mustafa, Alexander Kolesnikov, Lucas Beyer · ICCV 2023 SigLIP: a per-pair sigmoid loss in place of the batch softmax.

See also