1 Two towers, one space
CLIP is two separate networks. The image tower is a Vision Transformer: it cuts the 224×224 image into a 7×7 grid of 32-pixel patches, adds one extra "class" token, and passes all 50 tokens through 12 attention blocks. The text tower is a 12-block transformer that reads up to 77 word pieces (this page passes it 32, which is plenty for a prompt). Each tower ends in a projection to the same 512-dimensional space, and its output is scaled to length 1.
Training pulled each image towards its own caption and away from the 32,767 other captions in the same batch. Afterwards, the cosine between an image vector and a text vector says how well that text would caption that image. That gives you a classifier for any list of labels you can type, with no retraining. This is called zero-shot classification.
Each label is put into the template, tokenized, and run through the text tower. The softmax uses CLIP's learned temperature (×100).
Zero-shot prediction (click a label for its map)
The map darkens the patches that match the selected label least. It uses MaskCLIP (Zhou et al. 2022): each patch is embedded separately in the last block, then compared with the text. CLIP's own patch tokens give inverted, noisy maps, because the model was only ever trained to describe the whole image.
How the text tower sees a prompt
Text is split into pieces from a vocabulary of 49,408, learned from the same captions. Common words are one piece; rare ones are spelled out in fragments. A dot marks a word end.
Layer by layer
2 It reads
Captions on the web often describe text in the picture: a sign, a label, a product name. Matching an image to its caption is often easiest if you can read, so CLIP learned to read. The side effect is that a word written on an object can outweigh the object itself. This is the typographic attack Goh et al. (2021) showed with an apple labelled "iPod".
Type a word, click the image to place it, and watch the zero-shot prediction above (same labels and template) change.
Prediction with the text
3 Residues of the web
Collect 400 million images from the web and you get a lot of watermarked stock-photo previews, memes, screenshots and product shots. CLIP never saw a label saying "stock photo", but it saw "shutterstock" next to thousands of watermarked images. You can see this when you compare an image with prompts that name web artefacts, before and after adding a faint watermark.
Cosine similarity of the image above with each prompt; the bar shows the change from the clean image. On the six sample photos, a faint repeated watermark reading "lumen studio", a made-up name, raises the mean similarity to shutterstock from 0.206 to 0.265 and to iStock from 0.218 to 0.258. A row of © signs alone raises shutterstock to 0.251. A photo stays at 0.22. Any faint text repeated over a photo looks like a stock-photo preview to CLIP.
What CLIP draws for a caption
Turn the question around: start from noise and change the pixels until the image embedding points at a text. This is the same feature visualisation as on the VGG page, with a caption as the target instead of a class. Each step, CLIP looks at 16 random crops, so only patterns that work at every scale survive. The images below took 400 steps each, offline.
For most of these captions CLIP draws writing: brand names, "STOP", the word "love", logos, credits, watermark tiles. It learned from text that sat next to pictures, and often the surest sign that a caption fits is the same words appearing inside the picture. An ordinary object such as a cat comes out almost text-free. Click a render to use it as the input image above.
Dream it live
Gradient ascent on the pixels, run by onnxruntime-web. The gradient of the cosine is part of the exported graph. Each step shifts and mirrors the image at random before the gradient is taken, and the gradient is spread evenly over frequencies. It is cruder than the offline renders, but the same words and shapes tend to appear after a few dozen steps.