datarekha

Vision-language model architectures

CLIP aligns images and text; a vision-language model lets an LLM actually see — answer questions about an image, read a chart, reason over a screenshot. The core engineering question is how to connect a vision encoder to an LLM. Three answers — LLaVA's projection, BLIP-2's Q-Former, Flamingo's cross-attention — and why the simplest one won.

8 min read Advanced NLP & Transformers Lesson 39 of 44

What you'll learn

  • How an LLM is given sight — turning image features into tokens it can read
  • LLaVA-style projection — visual tokens prepended to the text
  • BLIP-2's Q-Former and Flamingo's gated cross-attention
  • Why the projection approach became the common default

Before you start

CLIP lets you compare images and text, but a vision-language model (VLM) does more: it lets an LLM see — describe an image, answer questions about it, read a chart, reason over a screenshot. The whole design problem is one question: a ViT outputs image features, an LLM consumes tokens — how do you connect them? There are three classic answers.

LLaVA: project image features into visual tokens

The simplest and now most common approach (LLaVA): take a frozen vision encoder’s patch features, pass them through a small projection (a linear layer or MLP) that maps them into the LLM’s embedding dimension, and prepend the results to the text tokens as “visual tokens.” The LLM then attends to them exactly like words:

import numpy as np
rng = np.random.default_rng(0)
llm_dim = 8

image_features = rng.standard_normal((4, 16))      # 4 patches, vision-encoder dim 16
projection     = rng.standard_normal((16, llm_dim))# learned linear: vision-dim -> LLM-dim
visual_tokens  = image_features @ projection        # 4 visual tokens, now in LLM space
text_tokens    = rng.standard_normal((3, llm_dim))  # 3 word tokens (already in LLM space)
sequence       = np.vstack([visual_tokens, text_tokens])

print(f"image -> {visual_tokens.shape[0]} visual tokens of dim {llm_dim}")
print(f"text  -> {text_tokens.shape[0]} text tokens of dim {llm_dim}")
print(f"LLM input: {sequence.shape[0]} tokens (visual + text) -> the LLM attends to both alike")
image -> 4 visual tokens of dim 8
text  -> 3 text tokens of dim 8
LLM input: 7 tokens (visual + text) -> the LLM attends to both alike

That’s the entire trick: a projection turns the image into tokens, they sit in the same sequence as the text, and the LLM’s self-attention does the cross-modal reasoning. LLaVA trains this with visual instruction tuning — image question-answer data (much of it generated by a stronger model) — and mostly just trains the small projector (and optionally the LLM), keeping the vision encoder frozen.

BLIP-2 and Flamingo: two other bridges

LLaVA: projectionViT featsMLP[visual tokens | text] → LLMprepend, attend like wordsBLIP-2: Q-Formerfroz. encoderQ-Former (learned queries)frozen LLMfew tokens, both big nets frozenFlamingo: cross-attnimage featsLLMx-attngated layers inserted into LLM
Three bridges from vision to an LLM: project into the token stream (LLaVA), distill via a Q-Former (BLIP-2), or cross-attend inside the LLM (Flamingo).
  • BLIP-2 (Q-Former). A lightweight Querying Transformer sits between a frozen image encoder and a frozen LLM. A small set of learned query tokens attend to the image features and extract the most relevant information into a fixed, small number of tokens. Keeping both big models frozen makes training cheap.
  • Flamingo (gated cross-attention). Instead of prepending tokens, insert new cross-attention layers into the (frozen) LLM that attend to the image features. They’re gated — initialized as near no-ops so they don’t break the pretrained LLM — and it naturally handles interleaved image-and-text sequences.

In one breath

  • A VLM lets an LLM see; the design question is how to feed image features (from a ViT) into a token-consuming LLM — three classic answers.
  • LLaVA (projection): an MLP maps patch features into the LLM’s embedding space as visual tokens, prepended to the text; the LLM’s self-attention does the cross-modal reasoning (the demo: 4 visual + 3 text → one 7-token sequence). Trained via visual instruction tuning, mostly the small projector.
  • BLIP-2 (Q-Former): learned query tokens distill the image into a few tokens between a frozen encoder and frozen LLM — cheap to train.
  • Flamingo (gated cross-attention): insert gated cross-attention layers into the LLM that attend to image features, handling interleaved image-text.
  • The projection approach won for simplicity and scaling — turn the image into tokens, drop them in the sequence, let the LLM reason.

Quick check

Quick check

0/4
Q1In a LLaVA-style VLM, how does an image get into the LLM?
Q2What is BLIP-2's Q-Former, and what's its advantage?
Q3How does Flamingo connect vision to the LLM differently?
Q4Why did the projection (LLaVA-style) approach become the common default?

Next

VLMs build on the CLIP image encoder and ViT, reusing the LLM’s self-attention for fusion. How specific model families differ — resolution, native-multimodal — is VLM model families.

Sign in to track your progress

Completed lessons, your XP, level, and streak save to your account — it's free and takes a few seconds.

Related lessons

Explore further

Skip to content