AnyLearn
All lessons
AIintermediate

Vision-Language Models (VLMs): how machines read images

How models like CLIP, GPT-4V, and Claude visual learn to talk about pictures. Cover the contrastive trick behind CLIP, the difference between embedding models and generative VLMs, and where each one shines.

Not signed in — your progress and quiz score won't be saved.
Lesson progress1 / 8

What a VLM actually is

A Vision-Language Model is any model that takes images and text as input and produces meaningful output that mixes the two. Two families dominate:

  • Embedding VLMs (CLIP, SigLIP, EVA): produce a vector for an image and a vector for a piece of text in the same space. Two things that match score high.
  • Generative VLMs (GPT-4V, Claude 4 visual, Gemini, LLaVA): take image+text in, generate free-form text out.

Different tools for different jobs. Embeddings are cheap and great at search/classification. Generative models are flexible but slow and pricey.

Full lesson text

All 8 steps on one page — for reading, reference, and search.

Show

1. What a VLM actually is

A Vision-Language Model is any model that takes images and text as input and produces meaningful output that mixes the two. Two families dominate:

  • Embedding VLMs (CLIP, SigLIP, EVA): produce a vector for an image and a vector for a piece of text in the same space. Two things that match score high.
  • Generative VLMs (GPT-4V, Claude 4 visual, Gemini, LLaVA): take image+text in, generate free-form text out.

Different tools for different jobs. Embeddings are cheap and great at search/classification. Generative models are flexible but slow and pricey.

2. The contrastive trick (how CLIP learned)

OpenAI's CLIP was trained on 400M (image, caption) pairs scraped from the web. The clever bit: it learned not by predicting captions but by pulling matching pairs together and pushing mismatched pairs apart in a shared embedding space.

For each batch of NN pairs you get an N×NN \times N similarity matrix. The diagonal should be high (each image matches its own caption); off-diagonal should be low. The loss is symmetric cross-entropy on both rows and columns. That's it — no labels, no human annotation, just "these two go together, those two don't". Astonishingly, this produced a model that could classify images by writing a prompt instead of training a classifier.

3. CLIP's training objective

Two encoders, one shared space, contrastive matching.

flowchart LR
  Img["Image"] --> ImgEnc["Image encoder"]
  Txt["Caption"] --> TxtEnc["Text encoder"]
  ImgEnc --> Space["Shared embedding space"]
  TxtEnc --> Space
  Space --> Loss["Contrastive loss"]

4. Zero-shot classification, the killer demo

Because CLIP embeds images and text in the same space, you can classify images without training a classifier. Define each class by a natural-language prompt, embed those prompts, then pick whichever prompt is closest to your image embedding.

import open_clip, torch
model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32', pretrained='laion2b_s34b_b79k')
tokenizer = open_clip.get_tokenizer('ViT-B-32')

labels = ["a photo of a cat", "a photo of a dog", "a photo of a car"]
img = preprocess(Image.open("input.jpg")).unsqueeze(0)
with torch.no_grad():
    img_emb = model.encode_image(img)
    txt_emb = model.encode_text(tokenizer(labels))
    probs = (100 * img_emb @ txt_emb.T).softmax(dim=-1)
print(labels[probs.argmax()])

No training data, no fine-tuning. The prompts are the classes.

5. Generative VLMs: stapling vision to an LLM

Models like GPT-4V, Claude 4 visual, and LLaVA take a different route: they stick a vision encoder onto a pretrained LLM and train the connection so the LLM can "see".

A common recipe (LLaVA-style):

  1. Take a vision encoder (often CLIP's image tower).
  2. Pass its features through a small projection MLP.
  3. Insert the projected features as if they were token embeddings in front of the LLM.
  4. Fine-tune the projection (and sometimes the LLM) on image-text pairs.

The result: a language model that can answer questions about images, describe scenes, transcribe charts, OCR sloppy handwriting. The vision tower contributes perception; the LLM contributes reasoning and language.

6. Embedding VLM vs generative VLM — when to use which

NeedUse
Image search across a million photosEmbedding VLM
Classification with a fixed label setEmbedding VLM
"Describe this medical scan in detail"Generative VLM
OCR + reasoning on a receiptGenerative VLM
Find duplicate or near-duplicate imagesEmbedding VLM
Tag user-uploaded images with arbitrary categoriesEither; embedding is cheaper

Embedding VLMs are ~1000x cheaper per query and run on a single GPU. Reach for a generative VLM only when you actually need natural-language output.

7. What VLMs are bad at

VLMs are not infallible. Known weaknesses:

  • Counting: "how many people are in this picture" routinely wrong past ~5.
  • Spatial reasoning: "what's to the left of the lamp" is shaky, especially in cluttered scenes.
  • Fine-grained discrimination: telling apart breeds of a dog, or two similar product SKUs.
  • Reading small text: most do OCR well at large sizes but fall apart on tiny print.
  • Bias from training data: web-scale image scrapes reflect the web's biases.

For production, treat VLMs as a useful but imperfect signal. Combine with traditional CV (OCR engines, object detectors) when accuracy matters.

8. Open vs closed VLMs

Closed (GPT-4V, Claude 4 visual, Gemini): best quality on hard reasoning, easiest to use, pay per call. Good default.

Open (LLaVA, Qwen-VL, InternVL, OpenCLIP for embeddings): self-hostable, predictable cost, customisable. Quality has caught up dramatically for common tasks. Use them when (a) data can't leave your infra, (b) you need to fine-tune on a niche domain, or (c) you're running at high volume where per-call pricing hurts.

For embeddings specifically, open beats closed handily: OpenCLIP variants are essentially free to run and competitive with closed embeddings. For generative tasks, closed still has an edge on the hardest cases, but the gap is closing every few months.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Which task is *embedding* VLMs (like CLIP) better suited to than generative VLMs (like GPT-4V)?
    • Writing a paragraph describing what's in an image
    • Answering follow-up questions about an image
    • Searching a million-image library for ones that look like a query
    • Extracting structured fields from a complex form
  2. What does CLIP's contrastive loss actually compare?
    • Predicted captions against ground-truth captions
    • Image embeddings against text embeddings within each training batch
    • Pixel-level predictions against the original image
    • Class probabilities against one-hot labels
  3. You need a VLM to flag medical X-rays as "normal" or one of 12 specific conditions. Which approach is the cheapest path that can work?
    • Send each scan to GPT-4V with a long prompt listing every condition
    • Fine-tune a generative VLM on your labelled data
    • Embed each image with CLIP and compare to embeddings of 13 textual prompts
    • Train a classifier from scratch on the scans
  4. Which weakness should you most expect from a generative VLM in production?
    • Refusing to process images entirely
    • Counting objects accurately past a small number
    • Identifying common objects like cats and cars
    • Recognising widely-known landmarks
  5. In a LLaVA-style architecture, what role does the projection MLP play?
    • It does the actual classification of the image
    • It maps vision encoder features into the LLM's token embedding space
    • It generates captions from image features
    • It compresses the LLM to fit on a GPU

Related lessons