Linformer is an efficient Transformer architecture that reduces the self-attention complexity from $O(N^2)$ to $O(N)$ by projecting the key and value matrices from sequence length $N$ to a fixed lower dimension $k$, based on the observation that the attention matrix is approximately low-rank. By learning projection matrices $E, F \in ℝ^{k\times N}, Linformer$ computes attention as $\operatorname{softmax}(Q(\mathrm{EK})^T/\sqrt{d})\cdot (\mathrm{FV})$, operating on $k\times d$ matrices instead of $N\times d$.
Why Linformer Matters in AI/ML:
Linformer demonstrated that full attention is often redundant because attention matrices are empirically low-rank, and projecting to a fixed dimension achieves near-identical performance while enabling linear-time processing of long sequences.
• Low-rank projection — Keys and values are projected: K̃ $= E\cdot K \in ℝ^{k\times d}$ and Ṽ $= F\cdot V \in ℝ^{k\times d}$, where $E, F \in ℝ^{k\times N}$ are learned projection matrices; attention becomes softmax(QK̃^T/√d)·Ṽ, computing an $N\times k$ attention matrix instead of $N\times N$
• Fixed projected dimension — The projection dimension $k$ is fixed regardless of sequence length $N$ (typically $k=128-256$); this means computational cost grows linearly with $N$ rather than quadratically, enabling theoretically unlimited sequence lengths
• Empirical low-rank evidence — Analysis shows that attention matrices have rapidly decaying singular values: the $top-128$ singular values capture 90%+ of the attention matrix's energy across most layers and heads, validating the low-rank assumption
• Parameter sharing — Projection matrices $E, F$ can be shared across heads and layers to reduce parameter count: head-wise sharing (same projections per layer) or layer-wise sharing (same projections across all layers) with minimal quality impact
• Inference considerations — During autoregressive generation, Linformer's projections require access to all previous tokens' keys/values simultaneously, making it less suitable for causal (left-to-right) generation compared to bidirectional encoding tasks
| Configuration | Projected Dim $k$ | Quality (vs Full) | Speedup | Memory Savings |
|---|---|---|---|---|
| $k = 64$ | Small | 95-97% | $8-16\times $ | $8-16\times $ |
| $k = 128$ | Standard | 97-99% | $4-8\times $ | $4-8\times $ |
| $k = 256$ | Large | 99%+ | $2-4\times $ | $2-4\times $ |
| Shared heads | $k$ per layer | $\sim 98\%$ | $4-8\times $ | Better |
| Shared layers | Same $k$ everywhere | $\sim 96\%$ | $4-8\times $ | Best |
Linformer is the foundational work demonstrating that Transformer attention is practically low-rank and can be efficiently approximated through learned linear projections, reducing quadratic complexity to linear while preserving model quality and establishing the low-rank paradigm that influenced all subsequent efficient attention research.