How a vision-language model works
/AI/4 min read
A VLM cuts an image into 14-pixel patches, encodes them, and feeds them to a language model as if they were words. A 336-pixel image becomes 576 tokens — about as much context as 443 words — and a minute of video at one frame a second is 34,560.
A vision-language model — VLM — takes images and text together and responds in text. Show it a photo of a receipt and ask for the total; give it a chart and ask what changed; hand it a screenshot and ask which button to press.
Most VLMs are not built from scratch. They are a language model that has been taught to read a new kind of token: pieces of an image.
The three parts
1. A vision encoder. Usually a vision transformer (ViT), often one pre-trained to match images with captions. It cuts the image into a grid of small square patches — commonly 14 × 14 pixels — and turns each patch into a vector, with attention letting each patch take in context from the others.
2. A projector. The vision encoder's vectors live in a different space from the language model's word embeddings. A small network — sometimes just a linear layer or two-layer MLP — maps each patch vector into the language model's embedding space. After this, an image patch looks to the language model like a token.
3. A language model. The projected image tokens are placed into the sequence alongside the text tokens, and the language model processes them all together with ordinary attention. Its answer is generated as text, one token at a time, exactly as for a text-only prompt.
That is the whole architecture. The language model does not "see" in any special way: it reads a sequence where some tokens came from words and some came from patches.
How many tokens an image costs
With 14-pixel patches, an image of side s pixels becomes (s / 14)² tokens:
| image size | patch grid | image tokens | after 2×2 merging |
|---|---|---|---|
| 224 × 224 | 16 × 16 | 256 | 64 |
| 336 × 336 | 24 × 24 | 576 | 144 |
| 448 × 448 | 32 × 32 | 1,024 | 256 |
| 1,008 × 1,008 | 72 × 72 | 5,184 | 1,296 |
A modest 336-pixel image is 576 tokens — about the context cost of 443 words of text. A high-resolution image is several thousand. Many models therefore merge neighbouring patches, typically 2 × 2 into one token, cutting the count four-fold at some cost to fine detail.
Video multiplies it. Sampling one frame per second, a one-minute clip at 576 tokens a frame is 34,560 tokens; even with merging, 8,640. Video understanding is, to a large extent, a context-length and token-budget problem.
How it is trained
Typically in stages:
- Alignment. Freeze the vision encoder and the language model, and train only the projector on image–caption pairs, so image tokens land where the language model can make sense of them.
- Instruction tuning. Unfreeze some or all of the model and train on image-and-question examples with good answers: describing, counting, reading text, reasoning about charts, following visual instructions.
- Preference training. As with text models, refine behaviour with human or automated feedback — including penalising descriptions of things that are not in the image.
Handling real images
Real images are not 336-pixel squares. Documents are tall, screenshots wide, and small text needs high resolution. Common approaches:
- Tiling. Cut a large image into several tiles at the encoder's native resolution, encode each, and add a low-resolution thumbnail of the whole for context.
- Native resolution. Encoders that accept variable image sizes and aspect ratios, with position encodings that handle any grid.
- Token budgets. Let the caller choose detail level, trading accuracy on fine print against cost and latency.
What VLMs are good and bad at
Good: describing scenes, reading printed text, answering questions about documents, charts and screenshots, comparing images, following visual instructions.
Weaker: precise counting of many objects, exact spatial relationships ("is the cup left of the plate from the person's viewpoint?"), reading tiny or stylised text at low resolution, and anything requiring pixel-level measurement. And like text models, they can hallucinate — confidently describing details that are not there, especially when the question presumes them.
What to take away
A vision-language model cuts an image into patches, encodes them with a vision transformer, projects them into a language model's embedding space, and lets the language model read them alongside text. The language model is otherwise unchanged.
Images are expensive in tokens: 576 for a 336-pixel image, over 5,000 at high resolution, 34,560 for a minute of video at one frame per second. Patch merging, tiling and resolution choices are how VLMs balance detail against context and cost.