Skip to content
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.

Written and reviewed by Last reviewed

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 (a vision transformer, which splits an image into patches and turns each into a list of numbers called a feature vector) outputs image features, while 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 is LLaVA. Take the patch features from a frozen vision encoder (one whose weights are not updated during training). Pass them through a small projection, meaning a linear layer or a small MLP (a few stacked linear layers). The projection maps them into the LLM’s embedding dimension, the size of the number-list the LLM uses for each token. Then prepend (place at the start) the results to the text tokens as “visual tokens.” The LLM 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 (placeholder vectors the model learns during training, which act like questions asked of the image) attend to the image features. They pull 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. Cross-attention is attention where the text positions look at a different source, here the image features, instead of at each other. The layers are gated: a learned dial starts at zero, so they begin as near no-ops and don’t break the pretrained LLM. This design 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/5
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?
Q5You must give a video model 2,000 frames, but an LLaVA-style projection would add hundreds of tokens per frame and overflow the context window. Which idea from this lesson helps most?

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.

Practice this in an interview

All questions
How do multimodal vision-language models combine images and text, and what role does CLIP play?

A multimodal vision-language model turns image regions into visual tokens, maps them into the language model's hidden representation, and combines them with text through attention. CLIP is a contrastively trained dual encoder that aligns image and text embeddings; it can provide a vision backbone or support retrieval and zero-shot classification, but it is not by itself a generative visual question-answering model.

What causes LLM hallucinations and how can they be reduced?

Hallucinations occur because an LLM is trained to produce plausible next tokens, not verified facts — it has no internal truth-checking mechanism, only statistical patterns. Common causes include rare or conflicting training data, overconfident decoding, and prompts that lead the model to extrapolate beyond what it learned. Mitigation strategies include retrieval-augmented generation, grounding responses to retrieved sources, lowering temperature, and calibrated refusal training.

What is SwiGLU and why did modern LLMs replace the ReLU/GELU MLP with it?

SwiGLU is a gated feed-forward layer that applies SiLU to one learned projection, multiplies it elementwise with a second projection, and projects the result back down. Many modern LLMs use it because this learned multiplicative gate often improves language-model quality at a similar parameter and compute budget, although it is not a universal replacement for GELU.

What causes hallucinations in LLMs and how do you mitigate them?

LLM hallucinations are fluent claims that are false or unsupported because language models predict likely text rather than verify facts against a source of truth. The strongest mitigation is layered: retrieve authoritative evidence, constrain answers to that evidence, use tools or deterministic checks for exact facts, verify claims, and measure both correctness and unsupported-claim rates.

Related lessons

Explore further