Paper Breakdowns  /  Flamingo
Paper 65~11 min readDeepMind · 2022worked math + runnable code
Paper Breakdown

Flamingo,
explained.

You have a brilliant language model and a brilliant vision model, each trained at enormous cost. How do you make them talk — without retraining either? Flamingo's answer is a bridge: freeze both, compress each image into a handful of tokens, and thread them into the language model through new attention layers that start switched off so they can't break what already works. The result learned new vision-language tasks from a few examples in the prompt, the way GPT-3 learned text tasks. Here's the connector, and the gate that makes it safe.

Video breakdown
The animated walkthrough is in production.
Read the full breakdown below in the meantime ↓
01

Bridging two frozen models

By 2022 the field had superb pretrained pieces: vision encoders like CLIP that turn images into rich features, and large language models fluent in text. The obvious goal was a model that could do both — read an image and reason about it in words. The expensive way is to train one giant multimodal model from scratch. Flamingo took the cheap, elegant route: keep both pretrained models frozen and train only a small connector between them.

Freezing is the whole strategy. It preserves the language model's hard-won abilities and the vision encoder's perception, and it makes training far cheaper — only the bridge learns. But it raises two engineering questions. Vision encoders emit a variable, often large number of features per image (and far more per video); how do you feed that into a language model expecting a tidy token stream? And how do you inject visual information into a frozen model without disrupting the delicate weights that make it work? Flamingo answers both.

The one-sentence version

Freeze a vision encoder and a language model; compress each image to a few tokens with a resampler, and inject them through cross-attention layers that start switched off so the language model is never broken.

02

The Perceiver Resampler

The first component solves the variable-size problem. A vision encoder might produce hundreds of feature vectors for one image, thousands for a video — and that count changes with resolution and length. The Perceiver Resampler maps any such set to a fixed, small number of latent tokens. It does this with cross-attention: a fixed set of learned query vectors (say 64 of them) attend to the visual features and absorb them, producing exactly 64 output tokens no matter how many features came in.

N visual features → Resampler → M fixed latent tokens (M ≪ N)  ·  compression = N / M

Because M is fixed, the cost of everything downstream — feeding vision into the language model — is constant, independent of image resolution or video length. A 576-feature image and a 2,304-feature one both become 64 tokens; the language model sees the same tidy, bounded input either way. The runnable version below confirms the fixed output and the constant downstream cost.

03

Gated cross-attention

Now the delicate part: inject those visual tokens into a frozen language model without wrecking it. Flamingo interleaves new gated cross-attention layers between the language model's existing (frozen) layers. Each new layer lets the text tokens attend to the visual tokens — but its output is multiplied by a learnable tanh(α) gate, with α initialized to zero:

output = text + tanh(α) · cross-attention(text → vision) ,   αinit = 0

At initialization tanh(0) = 0, so the cross-attention contributes exactly nothing and the model is bit-for-bit the original language model — untouched, unbroken. As training proceeds, the gates α gradually open, smoothly letting visual information flow in. This zero-init trick is what makes adding a modality to a frozen model safe: you begin from a known-good model and only ever add, never disrupt. The runnable version below shows the gate starting at 0 and opening.

04

Interleaved training

To get few-shot multimodal ability, Flamingo trains on interleaved image-and-text sequences — web pages and documents where images and words are naturally mixed, images appearing inline with the text about them. The model learns to predict the text given the interspersed images, with attention masking so each text span attends to the images that precede it.

Flamingo, assembled
Vision encoderFrozen. Turns each image into a set of features.
Perceiver ResamplerTrained. Compresses features → fixed latent tokens.
Gated cross-attnTrained. Injects visual tokens into the LM; tanh gate starts at 0.
Language modelFrozen. Generates text, now conditioned on vision.

Training on interleaved data is what teaches Flamingo to handle a prompt like "here's an image and its caption; here's a second; now caption this third image" — the multimodal analogue of in-context few-shot prompting. The same interleaving that appears in training appears at inference as the prompt format.

RUN IT YOURSELF

Fixed tokens, and a gate that opens

Flamingo's two ideas are each a couple of lines. The Perceiver Resampler outputs a fixed number of tokens no matter the input size — a 576-feature image and a 2,304-feature one both become 64 tokens (9× and 36× compression), so the downstream cross-attention cost is identical either way. And the gated cross-attention uses tanh(α) with α starting at 0, so at init the visual contribution is exactly zero and the frozen language model is preserved — then grows as α opens. Change the feature counts or the gate value and watch it hold.

CPython · WebAssembly
05

Few-shot vision-language

Flamingo's headline was few-shot multimodal learning — the ability GPT-3 brought to text, now for images:

ResultSignificance
In-context multimodalLearned new vision-language tasks from a few image-text examples in the prompt, no fine-tuning.
State-of-the-art few-shotBeat prior task-specific systems on many benchmarks — VQA, captioning — with just a handful of examples.
Cheap to buildBoth big models frozen; only the resampler and gated layers trained.
Images and videoThe fixed-token resampler handled both, and interleaving allowed multi-image prompts.

The few-shot result mattered because it showed multimodal models could be prompted like language models, rather than requiring a fine-tune per task. That flexibility — describe the task with examples, get an answer — is exactly what made LLMs so useful, extended to vision.

06

The template it set

Flamingo's architecture — freeze strong pretrained encoders, train a lightweight connector — became a dominant template for visual language models. The specific pieces recur throughout the field: resampler-style compression of visual tokens (and its cousins, like Q-Former in BLIP-2), and lightweight connectors that graft vision onto a frozen or lightly-tuned LLM (as in CLIP-plus-projector systems). The zero-initialized gate — adding a new capability by starting from a no-op — shows up wherever you want to extend a pretrained model safely.

Its deeper lesson is about composition. Rather than train one monolithic model to do everything, Flamingo showed you can take excellent specialist models and stitch them together with a small learned interface, inheriting both their strengths at a fraction of the cost. As pretrained components proliferate, that compositional approach — bridge, don't rebuild — has only grown more central to how multimodal systems are built.

Worth knowing

The Perceiver Resampler is a descendant of the Perceiver architecture, whose whole idea is to map arbitrarily large inputs onto a fixed-size latent array via cross-attention — decoupling model cost from input size, the same trick Flamingo uses for vision.

Frequently asked

Quick answers

What is Flamingo?

A visual language model that bridges a frozen vision encoder and a frozen LLM with a small trained connector, enabling few-shot multimodal in-context learning.

What does the Perceiver Resampler do?

Compresses a variable number of visual features into a fixed small set of latent tokens via cross-attention, so downstream cost doesn't grow with image size.

Why the zero-initialized gate?

tanh(α) with α=0 makes the new cross-attention contribute nothing at init, so the frozen language model is preserved; the gate opens during training.

Why did it matter?

It brought few-shot, prompt-based learning to vision-language and set a reusable template — freeze big models, train a light connector — for later VLMs.

Flamingo: a Visual Language Model for Few-Shot Learning · Alayrac, Donahue, Luc, Miech, et al. · DeepMind · NeurIPS 2022 · read the original paper on arXiv → · Vibe Engines · 2026
Finished this one? 0 / 101 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