Vision-Language Projection › Linear Projection

Michael BrenndoerferFebruary 10, 20265 min read
Language AI HandbookAll chapters
Part 50 of 67Multimodal Models
Chapter 384Vision-Language Projection › Linear Projection
Reading section 3 of 12 · Linear Projection · 5 minSection 3 of 12 · 5 min

Book contents

Section 3 of 12 · 5 min read

Vision-Language Projection › Linear ProjectionOne section · Sections in this chapter3 / 12 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The simplest and most widely used approach is linear projection, a single learnable matrix that affine-turns each vision embedding into the LLM's embedding space. This approach embodies the principle of Occam's razor: before introducing complexity, test whether a simple linear transformation suffices to align the two semantic spaces.

Mathematical Formulation

Given a vision encoder output V∈Rn×dv\mathbf{V} \in \mathbb{R}^{n \times d_v} where nn is the number of visual tokens (patches) and dvd_v is the vision embedding dimension, the linear projection applies a weight matrix W∈Rdv×dl\mathbf{W} \in \mathbb{R}^{d_v \times d_l} and optionally a bias b∈Rdl\mathbf{b} \in \mathbb{R}^{d_l}:

Hlinear=VWH=Hlinear+1nb⊤\begin{aligned} \mathbf{H}_{\text{linear}} &= \mathbf{V} \mathbf{W} \\ \mathbf{H} &= \mathbf{H}_{\text{linear}} + \mathbf{1}_n \mathbf{b}^\top \end{aligned}

where:

  • V∈Rn×dv\mathbf{V} \in \mathbb{R}^{n \times d_v}: the vision encoder output containing nn visual tokens (patches) of dvd_v dimensions each
  • W∈Rdv×dl\mathbf{W} \in \mathbb{R}^{d_v \times d_l}: the learnable weight matrix mapping from vision dimension dvd_v to language model dimension dld_l
  • b∈Rdl\mathbf{b} \in \mathbb{R}^{d_l}: the optional bias vector (often omitted in modern implementations)
  • 1n\mathbf{1}_n: a column vector of ones with length nn, letting broadcasting of the bias to all nn tokens
  • Hlinear∈Rn×dl\mathbf{H}_{\text{linear}} \in \mathbb{R}^{n \times d_l}: the intermediate result after matrix multiplication, before bias addition
  • H∈Rn×dl\mathbf{H} \in \mathbb{R}^{n \times d_l}: the final projected visual tokens in the LLM's embedding space, ready for consumption by the language model

The matrix multiplication VW\mathbf{V}\mathbf{W} performs the core geometric transformation. Each row of V\mathbf{V} is a single patch embedding, and right-multiplying by W\mathbf{W} maps that embedding into the LLM's embedding space. Geometrically, this rotates and scales while re-orienting the vision embedding space so that its directions align with meaningful directions in the LLM's space.

To understand the geometric action more concretely, recall from linear algebra that matrix multiplication is a linear map. A linear map can rotate vectors, stretch them along certain axes, compress them along others, and reflect them. It cannot, however, perform non-linear operations like folding the space or creating new clusters that do not exist in the original. This means linear projection can reorient the vision space to match the LLM's coordinate system, but it cannot fundamentally restructure the topology of the vision representations. If two visual concepts are indistinguishably close in vision space, a linear projection cannot separate them in LLM space. This is an inherent limitation we will revisit when discussing MLP projections.

In modern implementations, bias terms are often omitted following the convention established in transformer architectures, where Layer Normalization typically follows linear transformations, reducing the need for explicit bias. The projection applies independently to each visual token, meaning the sequence length nn remains unchanged; only the dimensionality transforms. This is an important property: the spatial correspondence between image regions and token positions is preserved exactly, which proves important for localized visual understanding tasks.

Why Linear Projection Works

Linear projection relies on a key insight: if the vision encoder has learned semantically meaningful representations, a linear transformation may suffice to rotate and scale these representations into the LLM's embedding space. This assumes that the vision and language representations, while expressed in different coordinate systems, exist on approximately aligned semantic manifolds within their respective high-dimensional spaces.

To understand why this assumption often holds, consider how both vision encoders and language models learn their representations. Vision encoders trained via contrastive learning (like CLIP) or supervised classification learn to map visually similar images to nearby points in embedding space. Language models learn to map semantically similar words or contexts to nearby embeddings. When both models are trained on internet-scale data containing natural correlations between images and their descriptions, their respective embedding spaces often capture similar semantic relationships, albeit in different coordinate systems. A linear transformation can then serve as a coordinate rotation, aligning the axes of the vision space with those of the language space without changing the underlying semantic geometry.

The approach is computationally efficient, adding only dv×dld_v \times d_l parameters, a negligible increase when the LLM itself contains billions of parameters. For a ViT-L/14 projected to LLaMA-2-7B, this is 1024×4096=4,194,3041024 \times 4096 = 4{,}194{,}304 parameters, roughly 0.06% the size of the LLM itself. The tiny parameter count makes overfitting unlikely even with modest training datasets and simplifies optimization considerably.

Linear projection also preserves spatial information faithfully since each patch embedding projects independently, maintaining the correspondence between image regions and token positions. This preservation of spatial structure proves important for tasks requiring localized understanding, such as referring expression comprehension (identifying which object in an image a phrase refers to) or visual question answering about specific image regions. When the language model's attention mechanism later processes these visual tokens, it can rely on their positional correspondence to build spatial reasoning chains.

Initialization and Optimization Considerations

Although linear projection has few parameters, how those parameters are initialized and trained matters considerably. Poor initialization can cause the projected visual features to lie in distant corners of the LLM's embedding space, where the language model has no useful pre-trained knowledge about vectors in that vicinity.

A common practice is to initialize the projection matrix with values drawn from a normal distribution scaled by 1/dv1 / \sqrt{d_v}, similar to the initialization scheme used for transformer weight matrices. This keeps the initial output variance from growing or shrinking uncontrollably, helping the LLM receive visual tokens with magnitude comparable to its learned text token embeddings during early training.

Some implementations additionally use a learning rate for the projection layer that is several times larger than the learning rate for any unfrozen encoder parameters. Since the projection is learning from scratch while frozen encoders are simply being evaluated, the projection benefits from faster parameter updates. The asymmetric learning rate schedules help the projection converge while preventing instability in the frozen components.