Vibe Engines
YouTube
Paper Breakdowns  /  CLIP
Paper 14~7 min readOpenAI · 2021
Paper Breakdown

CLIP,
explained.

Vision models and language models each lived in their own universe, unable to talk. This 2021 paper built a shared one — a single map where a photo of a golden retriever and the words "a photo of a dog" land in the same neighborhood. That bridge between pixels and language is what lets you type a sentence and get back a picture.

The delta

What changes here: the label set stops being fixed

Rung 1, so the comparison is against supervised image classification. A classifier is trained against a fixed list of categories, and that list is the ceiling on what it can ever say — recognising a new kind of thing means new labelled data and a new output layer. The labels are also expensive, which caps the data.

The change is to supervise with language instead of labels. Train an image encoder and a text encoder together on image-caption pairs so that a picture and its own caption land close together in one shared space, and mismatched pairs land apart — the contrastive objective from the vision ladder, with a caption in place of a second crop. The supervision now comes from text that already existed alongside the images, so the training set is roughly 400 million pairs scraped from the web rather than a hand-annotated corpus.

What falls out is the property that made it famous. Because the "labels" are arbitrary sentences, classification becomes a retrieval: write out candidate class names as short phrases, encode them, and pick whichever is nearest the image. You can classify into categories that were never a training target, define new ones at inference time by typing them, and — stated in units — match a strong supervised model on ImageNet without training on ImageNet at all. The fixed output layer is gone, replaced by a text encoder.

01

Two separate worlds

Before CLIP, a vision model was trained on a fixed list of labels — say, the 1,000 categories of ImageNet — and could only ever recognize those. Ask it about anything outside its list and it was helpless. Worse, building it meant an army of humans hand-labeling millions of images into rigid buckets.

Meanwhile language models understood rich, open-ended text. The two never met. What if a model could learn about images the way a person browsing the web does — from pictures paired with the captions people wrote for them?

02

The idea: one shared space

CLIP — Contrastive Language-Image Pre-training — trains two encoders at once: one that turns an image into a vector, one that turns text into a vector. The goal is to align them so that a picture and its matching description land at nearly the same spot in a single shared embedding space.

Once images and words live on the same map, you can measure how well any picture matches any sentence just by checking how close their vectors are. Pixels and language become directly comparable.

03

How: contrastive learning at scale

Take a batch of image-caption pairs. Embed every image and every caption. Now train so each image is closest to its own caption and far from every other caption in the batch — pull the true pairs together, push the impostors apart.

Match each image to its caption (diagonal = correct pairs)
"a dog"
"a car"
"a tree"
🐕 image
✓
·
·
🚗 image
·
✓
·
🌳 image
·
·
✓

Done across 400 million image-caption pairs scraped from the web — natural-language supervision, no hand-labeling — the two encoders converge into one aligned space. The scale of that freely-available data is what made it work.

The objective is precise. For a batch of N pairs, embed the images and captions, L2-normalize, and form the N×N cosine-similarity matrix scaled by a learned temperature. The correct match for row i is column i — the diagonal — so it's just cross-entropy, run both directions:

One batch of N pairs supplies N positives and N²−N negatives for free — which is why a huge batch is part of the recipe.

Pull the true pair together, push all N−1 impostors in the row apart, symmetrically for columns. That's the entire training signal — and the runnable version below builds the matrix, computes the loss, and does zero-shot classification with it.

04

The payoff: zero-shot classification

Here's the trick that stunned people. Because CLIP compares images to text, you can classify an image into categories it was never trained on — just describe them. Want to tell cats from dogs? Embed the phrases "a photo of a cat" and "a photo of a dog," embed the image, and pick whichever text is closest.

Worth knowing

CLIP matched the accuracy of a fully supervised ImageNet-trained ResNet-50 without training on a single ImageNet label — recognizing the classes purely from their text descriptions. Change the label set by just typing new words.

05

Why it mattered

CLIP was remarkably robust and general: it held up across dozens of datasets and unusual image styles where narrow supervised models fell apart, because it learned from the messy diversity of the whole internet rather than one curated dataset.

LabelsNew categories
Supervised vision modelFixed list, hand-labeledNeeds retraining
CLIPAny text you writeJust describe them
06

Why it still matters

CLIP became the connective tissue of multimodal AI. Text-to-image models lean on it to steer generation — measuring how well an emerging image matches the prompt, so a diffusion model can be nudged toward your words. It powers multimodal search ("find photos that look like this sentence"), content moderation, and image captioning, and its contrastive recipe seeded a wave of vision-language models.

Its lasting idea is simple and profound: put different kinds of data into one shared space and comparison becomes trivial. Once images and words share a map, the boundary between seeing and reading starts to dissolve.

Since then

What the authors admit, and what happened next

The paper is unusually thorough about its own weaknesses. Performance is poor on fine-grained distinctions, on counting, on abstract or systematic tasks, and on anything far from what web captions describe — the model learned the distribution of things people photograph and write about, which is not the distribution of things one might want recognised. Results are also sensitive to prompt wording, so a reported zero-shot number embeds prompt engineering, and the paper says so.

"Zero-shot" deserves the scrutiny it later received: with 400 million uncurated pairs, whether a category was genuinely unseen is unanswerable, so the term means "no task-specific training" rather than "no exposure". And because the supervision is uncurated web text, the space encodes the associations of that text, which the paper examines directly rather than leaving to critics.

How it held up: as the substrate for nearly everything multimodal. A shared image-text space is the text conditioning in latent diffusion, the backbone of cross-modal retrieval, and — most consequentially — the visual encoder that rungs 2 and 3 attach to a language model. This rung aligned the two modalities; the rest of the ladder is about what you can then build on top of that alignment.

SOLVE IT YOURSELF

Build the contrastive matrix and classify zero-shot

CLIP's training signal is one similarity matrix, and its magic trick is what you can do with it afterward. This embeds three images and three captions in a shared space, builds the N×N cosine matrix (watch the diagonal dominate), and computes the symmetric contrastive loss — tiny when captions are aligned, huge when they're shuffled. Then the payoff: zero-shot classification, picking an image's label by nearest text, with no training on those labels. Change the embeddings and re-run.

YOUR TASK

Write the body of clip_loss. Everything else in the file is already written; this is the function the paper is about. Press ▶ Run to check it against the 5 assertions below — they start red.

WHAT IT HAS TO SATISFY — 5 ASSERTIONS
  1. Each image's top match is its own caption (the diagonal)
  2. Misaligned captions cost more contrastive loss
  3. Zero-shot picks the right label with no training
  4. Softmax over a row is a probability distribution
  5. A higher temperature sharpens the match probability
CPython · WebAssembly
07

Why it still matters

CLIP's core idea is a shared embedding space for images and text: train an image encoder and a text encoder together so a picture of a dog and the words "a photo of a dog" land near each other. Once images and captions live in the same space, you can compare across modalities with a dot product — the foundation of multimodal AI.

The training trick was contrastive learning at scale: given a batch of image–text pairs, pull each real pair together and push all the mismatched pairs apart. No hand-labeled categories — just 400M noisy image–caption pairs from the web. That weak, abundant supervision is what let it learn broad visual concepts instead of a fixed label set.

The headline result was zero-shot classification: to classify an image, embed candidate labels as text ("a photo of a cat", "a photo of a car") and pick the nearest. No task-specific training or fine-tuning — a single model classifies categories it was never explicitly trained on, just by comparing embeddings. That flexibility was a genuine break from the train-one-classifier-per-task era.

CLIP became infrastructure. Its text–image space guides text-to-image generators (steering diffusion toward a prompt), powers image search and retrieval, filters and captions training data, and feeds the vision side of multimodal LLMs. The lasting lesson is the one that keeps recurring in AI: learn a good shared representation from cheap, plentiful data, and a huge range of tasks become "just" nearest-neighbor lookups in that space.

Check yourself

5 questions on this paper

Answer each one out loud before you open it. Recalling an answer is what makes it stick; recognising one you have just read is not. Your score is kept on this device.

What is CLIP?

Show answer

CLIP (Contrastive Language-Image Pre-training) is a 2021 model from OpenAI that trains an image encoder and a text encoder together on about 400 million image-caption pairs scraped from the internet. It learns to place a picture and its matching description close together in one shared vector space, so images and words become directly comparable.

What is contrastive learning in CLIP?

Show answer

Given a batch of image-text pairs, CLIP embeds every image and every caption, then trains so that each image's vector is closest to its own caption's vector and far from all the others. Pull matching pairs together, push mismatched pairs apart — repeated over hundreds of millions of pairs, this aligns the two encoders into a single shared space.

What is zero-shot classification?

Show answer

Because CLIP compares images to text, you can classify an image without training a classifier for those labels. Just write the candidate labels as text ('a photo of a cat', 'a photo of a dog'), embed them, and pick whichever text embedding is closest to the image embedding. CLIP can recognize categories it was never explicitly trained on, purely by describing them in words.

How does CLIP relate to text-to-image models?

Show answer

CLIP gives a way to measure how well an image matches a text prompt, all in one shared space. Text-to-image systems use that signal to steer generation — nudging a diffusion model's output toward images whose CLIP embedding is close to the prompt's. It's the bridge that lets words guide the picture being formed.

Why was training on internet captions important?

Show answer

Traditional vision models needed expensive hand-labeled datasets with fixed categories. CLIP learned from 400 million image-caption pairs freely available on the web — natural language supervision instead of rigid labels. That scale and flexibility are why it generalizes so broadly and can handle open-ended descriptions rather than a closed list of classes.

Where this sits

One model, many senses

Joining text to images, audio, video and finally to a robot arm. Starts with the contrastive objective the whole field standardised on.

  1. 1CLIP2021
  2. 2Flamingo2022
  3. 3LLaVA2023
  4. 4wav2vec 2.02020
  5. 5Whisper2022
  6. 6V-JEPA2024
  7. 7RT-22023
  8. 8Genie2024

All 110 papers, in 19 ladders →

Finished this one? 0 / 110 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns