v9.1.1
Menu

Chapter 4: Vision-Language Alignment

Week 4-5

Master the bridge architectures that connect vision encoders to language models. From simple linear projections to sophisticated Q-Former and Perceiver Resampler designs, understand how visual representations are translated into the language model's embedding space and how different approaches trade off between token efficiency, information preservation, and computational cost.

Topics
7
Videos
7
Min read
47

Chapter Overview

The alignment problem in VLMs is fundamentally about bridging two representation spaces that were trained independently: the vision encoder's feature space (optimized for visual similarity via contrastive learning) and the LLM's embedding space (optimized for next-token prediction of text). These spaces encode different types of information in different geometric structures, and the bridge module must translate between them faithfully.

The bridge architecture is arguably the most critical design decision in a VLM. It determines how much visual information reaches the language model, how many tokens the LLM must process (directly impacting inference cost), and whether the model can preserve fine-grained spatial details or must compress to a coarse summary.

The field has explored a rich design space:

  • Linear Projection (LLaVA): The simplest bridge---a single matrix multiply. Fast, preserves all spatial tokens, but limited in representational capacity.
  • Q-Former (BLIP-2): Learned query tokens cross-attend to image features, compressing 257 image tokens to just 32. Powerful but adds significant parameters and complexity.
  • Perceiver Resampler (Flamingo): Fixed latent tokens cross-attend to visual features. A clean, principled approach to information compression.
  • MLP Projectors (LLaVA-1.5): Multi-layer projectors with nonlinearity. The practical sweet spot that most modern VLMs use.
  • Dynamic Resolution (LLaVA-NeXT, SigLIP2): Handle arbitrary image sizes without distortion.

This chapter covers each approach in detail, with mathematical formulations, implementation walkthroughs, and a systematic comparison of trade-offs.

Chapter Roadmap

Click any topic to jump in

Explainer video
1
The Alignment Problem

Vision encoders and LLMs speak different languages. CLIP groups by visual similarity (dogs and cats are close), LLMs group by linguistic meaning (dogs and cats are far apart). A bridge module must translate between these two worlds.

Representational GapInformation Bottleneck PrincipleAlignment Training Objectives
Three competing solutions

Each takes a different approach to the same problem

2
Linear Projection (LLaVA)

The simplest possible bridge: one matrix multiply converts each image patch independently. Surprisingly competitive — if CLIP and the LLM are both strong, a simple coordinate transform is enough.

Linear Projection FormulaTraining Strategy: Two-Stage
3
Q-Former (BLIP-2)

32 learnable "question" tokens cross-attend to the image, each specializing to extract different info (objects, colors, layout). Compresses 257 image tokens down to just 32 — an 8x reduction.

Learned Query TokensCross-Attention to Image FeaturesThree-Stage Pre-training
4
Perceiver (Flamingo)

Fixed latent tokens iteratively refine themselves by repeatedly cross-attending to image features. Similar goal to Q-Former (compression) but with a cleaner, more principled architecture.

Perceiver Cross-AttentionLatent Token InitializationComparison with Attention Pooling
Evolution: add nonlinearity + handle real images
5
MLP Projectors

A 2-layer MLP (linear → GELU → linear) replaces the single linear projection. The nonlinearity lets it learn curved boundaries between concepts that a flat projection can't capture. This is what most modern VLMs actually use.

Two-Layer MLP ProjectorGated Cross-Attention AdaptersProjector Architecture Search
6
Dynamic Resolution

Real images come in all sizes and aspect ratios. AnyRes tiles a high-res image into patches processed separately, then merges. NaFlex uses flexible positional encodings. Both avoid distortion from resizing.

AnyRes Tiling (LLaVA-NeXT)NaFlex (SigLIP2)Token Compression for High-Resolution
Now you can compare them
7
Comparing Architectures

A decision framework: Linear/MLP preserves all detail but costs more LLM tokens. Q-Former/Perceiver compresses aggressively but may lose fine-grained info. The right choice depends on your task — OCR needs full tokens, classification doesn't.

Token Efficiency vs. Information PreservationPractical Decision MatrixBenchmark Comparison

Topics

7 topics in this chapter

A frozen CLIP ViT-L hands you 576 vectors of width 1024, trained so that an image lands near its caption under cosine similarity. A frozen Vicuna-7B expects vectors of width 4096, trained so that each one helps predict the next word. Neither model has ever seen the other's coordinates. How do you get the language model to read the picture? The previous chapter described the language backbone; this chapter is about the bridge (also called the connector or projector) that sits between the two. Three questions organize it. First, how different are the two spaces, and what kind of map is needed? Second, how much should the bridge compress: keep all 576 tokens, or squeeze them to 32 or 64, accepting the information-bottleneck trade-off? Third, how is the bridge trained: BLIP-2 pre-aligns a 188M-parameter Q-Former with three objectives on 129M images, while LLaVA trains a single linear layer on 595K caption pairs before instruction tuning. The rest of the chapter works through linear, Q-Former, Perceiver and MLP bridges, then dynamic resolution, and closes with a comparison.

Definition

The vision-language alignment problem is to learn a bridge Z=g(F)Z = g(F) that turns a vision encoder's features FF into inputs the language model can use. The bridge must change dimension (for example 1024 to 4096), translate between representations trained for different objectives, and choose how many tokens to pass on, trading information kept against the LLM's sequence cost.

In this topic

  1. 1Representational Gap
  2. 2Information Bottleneck Principle
  3. 3Alignment Training Objectives
1 of 3
Representational Gap

cos(fvision(dog),fvision(cat))≫cos(fLLM(dog),fLLM(cat))\text{cos}(f_{\text{vision}}(\text{dog}), f_{\text{vision}}(\text{cat})) \gg \text{cos}(f_{\text{LLM}}(\text{dog}), f_{\text{LLM}}(\text{cat}))

Why can't you just copy CLIP vectors into the LLM? The two spaces were shaped by different objectives. CLIP's contrastive loss places images near their captions, so features cluster by what things look like and how they are described; two dog breeds sit close together. The LLM's embeddings and hidden states are shaped by next-token prediction, so they encode what tends to come next. The formula's cos\text{cos} compares cosine similarity of the same pair, dog and cat, under the vision features fvisionf_{\text{vision}} and the LLM representation fLLMf_{\text{LLM}}. The bridge's job is to make visual features legible to the LLM, not to make them look like word embeddings.

Mathematical Intuition

A linear bridge h=Wf+bh = Wf + b can stretch and rotate, so it can amplify a small breed-specific direction relative to a large shared one; cosine similarity is not preserved by such maps, so 0.92 in CLIP space need not stay 0.92 after projection. What a linear map cannot do is create information: if two inputs are identical in feature space, any bridge sends them to the same output. A separate effect, the modality gap (Liang et al. 2022), means image and text embeddings in CLIP occupy different cones, so even well-aligned models keep the modalities apart.

Example:

A CLIP encoder produces similar features for a Labrador and a Golden Retriever (cosine similarity 0.92). The LLM needs to distinguish them in text. How does the bridge help?

2 of 3
Information Bottleneck Principle

I(V;Z)≥I(Z;T)where V=image,Z=bridge output,T=target textI(V; Z) \geq I(Z; T) \quad \text{where } V = \text{image}, Z = \text{bridge output}, T = \text{target text}

The bridge module creates a compressed representation ZZ of the visual input VV. By the data processing inequality, ZZ cannot contain more information about the target text TT than the original image VV does. The design question is: how much compression is optimal? Too little compression (all 576 tokens) wastes LLM compute on redundant information. Too much compression (32 tokens) may lose critical visual details. The optimal bottleneck preserves all task-relevant information while discarding irrelevant visual detail.

Mathematical Intuition

For a chain T→V→ZT \to V \to Z the data processing inequality gives I(Z;T)≤I(V;T)I(Z; T) \le I(V; T) and also I(Z;T)≤I(Z;V)I(Z; T) \le I(Z; V), which is the frozen formula: the bridge output cannot know more about the answer than it knows about the image. The information bottleneck objective, minimize I(Z;V)−βI(Z;T)I(Z; V) - \beta I(Z; T), formalizes the trade-off. Token count is only a proxy for I(Z;V)I(Z; V): 576 vectors are not lossless (the encoder already discarded detail at 336 px), and 32 vectors of width 768 still carry a lot of information.

Example:

BLIP-2's Q-Former compresses 257 ViT tokens to 32 query tokens (8x compression). For the task of OCR (reading text in an image), is this compression too aggressive?

3 of 3
Alignment Training Objectives

Lalign=LITC+LITM+LITG\mathcal{L}_{\text{align}} = \mathcal{L}_{\text{ITC}} + \mathcal{L}_{\text{ITM}} + \mathcal{L}_{\text{ITG}}

How do you teach a bridge what matters before the LLM is involved? BLIP-2 trains its Q-Former with three losses at once. Image-Text Contrastive (LITC\mathcal{L}_{\text{ITC}}) pulls matching image and text embeddings together and pushes mismatched ones apart. Image-Text Matching (LITM\mathcal{L}_{\text{ITM}}) is a binary classifier on fused image-text pairs, trained with hard negatives. Image-grounded Text Generation (LITG\mathcal{L}_{\text{ITG}}) makes the queries carry enough to generate the caption. Simpler bridges skip this stage: LLaVA's projector learns only from the language-model loss, first on captions and then on instructions. The pre-alignment costs a large dataset and a separate training stage.

Mathematical Intuition

The three losses use one set of Q-Former weights under different attention masks. ITC is a softmax over a batch of image-text similarities, so it shapes global geometry; ITM is a cross-entropy on matched versus hard-negative pairs, so it sharpens fine distinctions; ITG is next-token likelihood, so it forces the queries to carry generatable content. The total LITC+LITM+LITG\mathcal{L}_{\text{ITC}} + \mathcal{L}_{\text{ITM}} + \mathcal{L}_{\text{ITG}} is a multi-task objective; BLIP-2's ablations show removing ITG hurts the stage-2 generative transfer.

Example:

LLaVA trains its projector only with the language-model generation loss (first on 595K caption pairs, then on 158K instruction examples). BLIP-2 first pre-trains its Q-Former with ITC+ITM+ITG on 129M images. Which approach is more data-efficient?

Theory Exercise

Problem:

A VLM must handle both coarse tasks (image classification, scene description) and fine-grained tasks (OCR, object counting, visual question answering about small details). Design a bridge architecture that adapts its compression ratio based on the task. Describe the architecture and how it would decide how many tokens to pass to the LLM.

Hints:
  • Consider a two-path architecture: compressed and uncompressed
  • The model could learn to route based on the text query
  • Think about how LLaVA-NeXT's anyres already addresses this partially