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
Demo
1
Videos
3
Min read
37

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 videoInteractive demo
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

The vision encoder and language model operate in fundamentally different representational spaces. A CLIP ViT-L produces embeddings in R1024\mathbb{R}^{1024} trained with contrastive loss---similar images are close in cosine distance, dissimilar images are far. The LLM operates in R4096\mathbb{R}^{4096} trained with next-token prediction---embeddings encode syntactic and semantic properties optimized for language generation.

The alignment challenge: How do we translate a vector that means "this patch contains a golden retriever's ear" (in vision space) into a vector that the LLM understands as contributing to the generation of "golden retriever" (in language space)? The bridge must learn a mapping between these two semantic systems.

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}))

The vision encoder groups representations by visual similarity: dogs and cats look alike, so their features are close. The LLM groups by linguistic co-occurrence: "dog" and "cat" are related but distinguished by different contexts ("bark" vs "meow"). A linear projection alone cannot fully bridge this gap because the geometric structure of the two spaces is fundamentally different. The bridge must learn to disentangle visual similarity from semantic identity.

Mathematical Intuition

The vision and LLM spaces have different metric structures. In CLIP space, cosine similarity reflects visual appearance, so cos(f(dog),f(cat))≈0.9\text{cos}(f(\text{dog}), f(\text{cat})) \approx 0.9. In LLM space, embeddings are shaped by next-token prediction — "dog" is close to "bark" and "leash", not to "cat". A linear map WW between these spaces cannot preserve both distance structures simultaneously because the rank of the required transformation exceeds min⁡(dvision,dLLM)\min(d_\text{vision}, d_\text{LLM}) when the relational structures differ.

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

By the data processing inequality, I(V;T)≥I(Z;T)I(V; T) \geq I(Z; T) for any bridge output Z=f(V)Z = f(V). The optimal bridge minimizes I(Z;V)I(Z; V) (compression) while maximizing I(Z;T)I(Z; T) (task relevance). This defines a rate-distortion curve: at 32 tokens, BLIP-2 operates at high compression / moderate distortion; at 576 tokens, LLaVA operates at zero compression / zero distortion. The optimal operating point depends on the entropy of the downstream task.

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}}

Bridge modules are typically trained with a combination of objectives: Image-Text Contrastive (ITC) loss aligns global image and text representations, Image-Text Matching (ITM) trains a binary classifier on image-text pairs, and Image-grounded Text Generation (ITG) trains the bridge to produce tokens that enable the LLM to generate correct captions. BLIP-2's Q-Former is trained with all three objectives before being connected to the frozen LLM. Simpler bridges (linear/MLP) skip pre-alignment and learn directly from the generation loss.

Mathematical Intuition

ITC pushes image and text representations onto a unit hypersphere and optimizes angular separation, so its gradient acts along the sphere's surface. ITM learns a binary classifier on the joint distribution p(match∣zimg,ztxt)p(\text{match} | z_\text{img}, z_\text{txt}), producing gradients that shape the decision boundary in the fused space. ITG optimizes a conditional likelihood p(t∣z)p(t | z) with autoregressive factorization, generating gradients through the causal chain. These three gradient fields are nearly orthogonal in parameter space — ITC aligns global geometry, ITM refines local boundaries, ITG optimizes for generation utility — which is why their combination covers more of the loss landscape than any single objective.

Example:

LLaVA uses no pre-alignment (just trains the MLP bridge end-to-end with generation loss). BLIP-2 pre-trains the Q-Former with ITC+ITM+ITG. 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