Welcome to the Jungle
This Matrix Factorization Jungle page ventures beyond classical decompositions into factorizations that impose structural assumptions on the unknowns—sparsity, low-rank, non-negativity, subspace membership, and more. As sparse recovery solvers matured, a rich ecosystem emerged. Sparse Coding & Dictionary Learning (Olshausen & Field) and NMF (Lee & Seung) were the first of such decompositions widely used with constraints on the matrices used for the factorization. Yet, while those factorizations were used by some practitioners, there was a sense that they "weren't rigorous enough" as little theoretical understanding came with these techniques. The discovery of compressed sensing (Candès, Romberg, Tao, Donoho) and its expansion to matrices i.e. nuclear norms can serve as convex proxies for rank, opened the floodgates to powerful new decomposition techniques.
What distinguishes these methods from traditional matrix factorizations and decompositions? A single method (say Sparse coding) can involve different loss functions and proxies to optimize. Each of these in turn admits multiple algorithm implementations—hence the Jungle reference. This elaborate complexity and the constraints applied to the results, yield phase transitions—sharp boundaries in parameter space. The phase transitions are very important because they are the eventual acid tests for algorithms or methods. These phase transitions are generally a sign that the algorithms or the factorization itself has hit a hard limit that may be due to the computational complexity of the problem being solved. This document maps that landscape, from video surveillance to recommendation systems, blending randomized linear algebra, nonconvex optimization, and probabilistic modeling.
Traditional Matrix Decompositions: There is a stellar and comprehensive treatment of classical matrix factorization techniques—LU, Cholesky, QR, SVD, Polar, Eigendecomposition, Jordan, Schur, CUR/Skeleton, Hessenberg, Tridiagonal, and Bidiagonal decompositions—in Jun Lu's monographs: "Matrix Decomposition and Applications" and "Numerical Matrix Decomposition and its Modern Applications". Most of the traditional techniques used to not put constraints on the matrix/data to be factorized. In scientific computing however, operators are sometimes approximated with decompositions and factorization to permit the design of better inverse problem solvers (see recent survey "Fast Direct Solvers" by Per-Gunnar Martinsson and Michael O'Neil).
The New Frontier: Additional information about LoRAs used with LLMs came from this survey by Zeyu Han, Chao Gao, Jinyang Liu, Jeff Zhang, Sai Qian Zhang.
"The Sparsest of Them All" — Evolution of phase transitions from Gauss to Krzakala, Mézard, Sausset, Sun, Zdeborová
Contributing
Know of a decomposition or factorization technique or an implementation or a phase transition that's missing? Open an issue and mention the paper reference (arxiv, biorxiv, DOI, techrxiv, etc....) where you found it, a brief description of the factorization or decomposition (a new one or one that has already been identified in the page), and ideally a link to code/repo. If you have identified a phase transition, please mention the article and the figure in which it is viewable (as a bound or as a graph).
References
- B.A. Olshausen & D.J. Field, "Emergence of simple-cell receptive field properties by learning a sparse code for natural images", Nature 381, 1996.
- D.D. Lee & H.S. Seung, "Learning the parts of objects by non-negative matrix factorization", Nature 401, 1999.
- J. Mairal, F. Bach, J. Ponce, G. Sapiro, "Sparse Coding and Dictionary Learning for Image Analysis", ICCV 2009 Tutorial.
- E.J. Candès, J. Romberg & T. Tao, "Robust Uncertainty Principles: Exact Signal Reconstruction from Highly Incomplete Frequency Information", IEEE Trans. Information Theory, 2006.
- D.L. Donoho, "Compressed Sensing", IEEE Trans. Information Theory, 2006.
- B. Recht, M. Fazel & P.A. Parrilo, "Guaranteed Minimum-Rank Solutions of Linear Matrix Equations via Nuclear Norm Minimization", SIAM Review, 2010.
- J. Lu, "Matrix Decomposition and Applications", arXiv:2201.00145, 2022.
- J. Lu, "Numerical Matrix Decomposition and its Modern Applications", arXiv:2107.02579, 2021.
- P.-G. Martinsson & M. O'Neil, "Fast Direct Solvers", arXiv:2511.07773, 2025.
- "Complexity Zoo" — Algorithmic Complexity Reference.
- "Complexity Zoo Petting Zoo" — Introduction to Complexity Classes.
This page was first announced on Nuit Blanche in August 2011.
Quick Reference for Advanced Matrix Factorization: Structural Assumptions & Unknowns
| FACTORIZATIONS (A = DX, UVT) | ||||||
|---|---|---|---|---|---|---|
| Problem | Form | Loss D(A;DX) | Known | Unknown | Key Constraints | Phase Trans. |
| SVD | A = DX | ||A-DX||F2 | A | D, X | DTD = I, XXT = Λ (diagonal) | — |
| pLSI | A = DX | KL(A;DX) | A | D, X | 1TD1 = 1, dij ≥ 0, 1TX = 1, xij ≥ 0 | — |
| NMF | A = DX | ||A-DX||F2 KL(A;DX) |
A | D, X | D ≥ 0, X ≥ 0 | — |
| Dictionary Learning | A = DX | ||A-DX||F2 | A | D, X | ||dj||2 = 1, X sparse | Yes |
| Sparse PCA | A = DX | ||A-DX||F2 | A | D, X | ||d||2 = 1, D sparse | Yes |
| K-Means | A = DX | ||A-DX||F2 | A | D, X | XXT = I, Xij ∈ {0,1} | Yes |
| K-Medians | A = DX | ||A-DX||1 | A | D, X | XXT = I, Xij ∈ {0,1} | Yes |
| Subspace Clustering | A = AX | ||A-AX||F2 | A | X | diag(X) = 0, sparse/low-rank | — |
| MMV / Comp. Sensing | Y = AX | ||Y-AX||F2 | Y, A | X | X joint row-sparse | Yes |
| BSS / ICA | Y = AX | ||Y-AX||F2 | Y | A, X | rows of X independent | — |
| Recommender Systems | R = UVT | ||R-UVT||F2 | RΩ | U, V | low-rank | — |
| LoRA | W' = W + BA | L(W+BA) | W | B, A | B∈Rd×r, A∈Rr×k, r ≪ d,k | — |
| Autoencoders | X = D(E(X)) | ||X-D(E(X))||F2 | X | E, D | bottleneck dim k; linear → PCA | — |
| Non-Convex Opt. | M = UVT | ||M-UVT||F2 | M | U, V | rank(UVT) ≤ r | Yes |
| Tensor Decomp. | T = ∑ a⊗b⊗c | ||T-∑a⊗b⊗c||F2 | T | factors | CP/Tucker/TT structure | — |
| Graph Matching | A = XBXT | ||A-XBXT||F2 | A | X, B | X permutation matrix | Yes |
| Generalized MF | W⊙L = W⊙UVT | ||W⊙(L-UVT)||F2 | W (mask) | U, V, L | L lowest rank | — |
| Archetypal Analysis | A = DX, D = AB | ||A-DX||F2 | A | D, X, B | X, B ≥ 0, convex hull | — |
| Matrix Comp. Sensing | A(L) = b | ||A(L)-b||22 | A, b | L | L rank-r | Yes |
| Kernel Factorizations | K = ΦΦT | ||K-ΦΦT||F2 | K (kernel) | Φ (features) | K ≥ 0, PSD | — |
| Self-Attention / Bilinear Factorization | Sc = XWQWKTXT P = softmaxrows(Sc / √dh + M) |
Task loss (no score reconstruction) | X (tokens) | WQ, WK (learned); Sc, P (computed) | Bilinear scores; tied factors ⇒ Gram / PSD; simplex rows; mask support; rank(Sc) ≤ dh is restrictive when dh < n | Yes Tied low-rank model |
| DECOMPOSITIONS (A = L + S) | ||||||
|---|---|---|---|---|---|---|
| Problem | Form | Loss D(A;L,S) | Known | Unknown | Key Constraints | Phase Trans. |
| Robust PCA | A = L + S | ||L||*+λ||S||1 | A | L, S | L low-rank, S sparse | Yes |
| Matrix Completion | PΩ(M) = PΩ(L) | ||L||* | MΩ | L | L low-rank, incoherent | Yes |
| SPCP / Noisy RPCA | A = L + S + N | ||L||*+λ||S||1 +||N||F2 |
A | L, S, N | L low-rank, S sparse, N noise | Yes |
Jun Lu's Taxonomy of Classical Matrix Decompositions
Figure 1: Matrix Decomposition World Map — relationships between classical decompositions
Figure 2: Matrix Decomposition World Map Under Conditions — taxonomy by matrix structure
From Jun Lu, "Matrix Decomposition and Applications" (arXiv:2201.00145)
Applications: Video surveillance, face recognition, Netflix recommendations
Applications: Image denoising, compression, feature learning
Spectral Clustering & K-Means
$\underbrace{A}_{\text{known}} = \underbrace{D}_{\text{unknown}} \underbrace{X}_{\text{unknown}}$ s.t. $XX^T = I$, $X_{ij} \in \{0,1\}$ Phase TransitionMatrix factorization view: Given data A, find unknown centroids D and assignment matrix X. The constraint XXT = I enforces that each data point belongs to exactly one cluster, while Xij ∈ {0,1} makes assignments binary. K-Median uses L1 loss instead of L2. Spectral methods relax the binary constraint and partition via graph Laplacian eigenvectors.
Operators: Random walk, Adjacency, Laplacian, Modularity, Non-Backtracking
K-means/K-median: Empirical probability of integrality for SDP/LP relaxations. Figure from: Awasthi, Bandeira, Charikar, Krishnaswamy, Villar, Ward — "Relax, no need to round: integrality of clustering formulations" (2015)
Subspace Clustering
$\underbrace{A}_{\text{known}} = \underbrace{A}_{\text{known}} \underbrace{X}_{\text{unknown}}$ s.t. $\text{diag}(X) = 0$, $X$ is sparse and/or low-rankMatrix factorization view: Given data matrix A, find unknown coefficient matrix X where each column xi expresses data point ai as linear combination of other points. Constraint diag(X) = 0 prevents trivial self-representation. Additional regularization: ||X||1 (SSC), ||X||* (LRR), or ||X||F (LSR).
Subspace clustering criteria satisfying EBD conditions. Figure from: Elhamifar, Vidal — "Sparse Subspace Clustering: Algorithm, Theory, and Applications" (2013)
Non-Negative Matrix Factorization (NMF)
$\min_{D,X} \|\underbrace{A}_{\text{known}} - \underbrace{D}_{\text{unknown}} \underbrace{X}_{\text{unknown}}\|_F^2$ s.t. $D \in \mathbb{R}^{m \times r}_+$, $X \in \mathbb{R}^{r \times n}_+$, $D, X \geq 0$Matrix factorization view: Given non-negative data matrix A, find unknown dictionary D and coefficients X, both constrained to be element-wise non-negative. The rank r controls the number of parts/topics. Non-negativity yields interpretable, parts-based representations.
Deep NMF (2018+): Multiple layers of factorization discover hierarchical structure. Neural NMF uses backpropagation for end-to-end training.
Matrix Completion
$\min_L \text{rank}(\underbrace{L}_{\text{unknown}})$ s.t. $P_{\underbrace{\Omega}_{\text{known}}}(L) = P_\Omega(\underbrace{M}_{\text{known}})$, $L$ is low-rank Phase TransitionMatrix factorization view: Given partial observations MΩ at index set Ω, recover unknown low-rank matrix L. Convex relaxation: min ||L||* (nuclear norm). Phase transition at m ≈ O(nr log n) samples for rank-r recovery. Made famous by Netflix Prize.
Graph-Based (2019+): GNN-based inductive methods generalize to unseen users/items and even transfer across datasets.
Robust PCA & Stable PCA
$\underbrace{A}_{\text{known}} = \underbrace{L}_{\text{unknown}} + \underbrace{S}_{\text{unknown}}$, solve $\min_{L,S} \|L\|_* + \lambda\|S\|_1$, $L$ is low-rank, $S$ is sparse Phase TransitionMatrix factorization view: Given observed matrix A, decompose into unknown low-rank component L (rank(L) ≤ r) and unknown sparse component S (||S||0 ≤ s). Nuclear norm ||L||* is convex proxy for rank; L1 norm for sparsity. Phase transition: recovery succeeds when rank(L) ≤ ρn and ||S||0 ≤ αn2.
Streaming (2015+): Nearly-linear time and single-pass algorithms now available. GRASTA tracks non-stationary subspaces online.
RPCA success rates comparison. Figure from: Parker, Schniter, Cevher — "Bilinear Generalized Approximate Message Passing" (2014)
Sparse PCA
$\max_v \underbrace{v}_{\text{unknown}}^T \underbrace{A}_{\text{known}}^T A v$ s.t. $\|v\|_2 = 1$, $\|v\|_0 \leq k$, $v$ is sparse Phase TransitionMatrix factorization view: Given data matrix A, find principal components v with at most k non-zero entries. Sparsity constraint ||v||0 ≤ k yields interpretable loadings. NP-hard; convex relaxation via SDP or L1 penalty. Computational-statistical gap: info-theoretic recovery possible below algorithmic threshold.
Dictionary Learning
$\min_{D,X} \|\underbrace{A}_{\text{known}} - \underbrace{D}_{\text{unknown}} \underbrace{X}_{\text{unknown}}\|_F^2 + \lambda\|X\|_1$ s.t. $\|d_j\|_2 = 1$, $X$ is sparse Phase TransitionMatrix factorization view: Given data matrix A, learn unknown dictionary D (columns normalized ||dj||2=1) and unknown sparse codes X (||xi||0 ≤ k). Dictionary can be overcomplete (more atoms than dimensions). Alternates between sparse coding (fix D, solve for X) and dictionary update.
Dictionary learning support recovery phase transition. Figure from: Sulam, Papyan, Romano, Elad — "Learning Simple Thresholded Features with Sparse Support Recovery" (2018)
MMV & Compressive Sensing
$\underbrace{Y}_{\text{known}} = \underbrace{A}_{\text{known}} \underbrace{X}_{\text{unknown}}$ s.t. $\|X\|_{\text{row},0} \leq k$ (joint row-sparsity) Phase TransitionMatrix factorization view: Given measurements Y and known sensing matrix A, recover unknown signal matrix X with at most k non-zero rows (joint sparsity across L measurement vectors). Donoho-Tanner phase transition: sharp boundary in (m/n, k/n) plane. Multiple measurements improve recovery over single-vector case (SMV).
Probabilistic reconstruction. From: Krzakala, Mézard, Sausset, Sun, Zdeborová (2012)
SCoSaMP. From: Blanchard, Tanner (2012)
CGIHT/NIHT. From: Blanchard, Tanner, Wei (2015)
Permutation recovery. From: Pananjady, Wainwright, Courtade (2016)
Blind Source Separation / ICA
$\underbrace{Y}_{\text{known}} = \underbrace{A}_{\text{unknown}} \underbrace{X}_{\text{unknown}}$ s.t. rows of $X$ are independentMatrix factorization view: Given mixed observations Y, recover unknown mixing matrix A and unknown source signals X. Key constraint: rows of X are statistically independent (ICA) or sparse (SCA). Non-Gaussianity of sources enables identification up to permutation and scaling.
Linear & Non-Linear Autoencoders
$\underbrace{X}_{\text{known}} \approx \underbrace{D}_{\text{unknown}}(\underbrace{E}_{\text{unknown}}(X))$, linear case $\equiv$ PCAMatrix factorization view: Given data X, learn encoder E: Rd→Rk and decoder D: Rk→Rd minimizing ||X - D(E(X))||2. Linear case: when E, D are linear maps (matrices), optimal solution recovers PCA—the encoder projects onto top-k principal components. Non-linear: E = f(VX), D = g(WZ) with nonlinearities f, g learn curved manifolds.
Key insight (Baldi & Hornik 1989): Linear autoencoders with bottleneck dimension k learn the subspace spanned by top-k principal components. Deep linear networks still recover PCA but with different learning dynamics.
Self-Attention as an Input-Dependent Factorization
$\underbrace{S_c}_{\text{computed scores}} = \underbrace{X}_{\text{known input}}\,\underbrace{W_Q}_{\text{learned}}\,\underbrace{W_K^{T}}_{\text{learned}}\,\underbrace{X^{T}}_{\text{known}} = \underbrace{Q}_{\text{computed}}\,\underbrace{K^{T}}_{\text{computed}}$ $\underbrace{P}_{\text{computed attention}} = \mathrm{softmax}_{\mathrm{rows}}\!\left(\underbrace{S_c}_{\text{computed}}/\sqrt{\underbrace{d_h}_{\text{chosen dimension}}} + \underbrace{M}_{\text{known mask}}\right)$ $\underbrace{V}_{\text{computed values}} = \underbrace{X}_{\text{known input}}\,\underbrace{W_V}_{\text{learned}},\qquad \underbrace{O}_{\text{computed output}} = \underbrace{P}_{\text{computed}}\,\underbrace{V}_{\text{computed}}$Known: input X and mask M. Learned during training: WQ, WK, WV (fixed during inference). Computed for each input: Q, K, V, Sc, P and O. Neither P nor O is supplied as known data or independently learned.
Phase Transition (tied low-rank model)Self-attention in language models. Transformer-based language models, including BERT and generative large language models (LLMs), process text as tokens (words or pieces of words), each represented by a vector. Self-attention lets each position combine information from other available positions to build a representation of the token in context. Each attention head constructs a matrix $S_c$ whose entry $(S_c)_{ij}$ scores how strongly token $i$ should attend to token $j$. Which positions are available, and what the model learns to predict, depend on its architecture and training objective.
Why this belongs in the Jungle. The model constructs this matrix through a factorization, $S_c=QK^T$. Two learned maps turn the token representations into query vectors (rows of $Q$) and key vectors (rows of $K$); each score is the dot product of a query and a key. These maps are learned as part of pretraining the full Transformer: a stack of layers containing attention heads and feed-forward networks. The model's prediction loss sends gradients through that stack, jointly shaping the attention projections and the representations they receive. Post-training can further adapt these projections and representations, for example through fine-tuning. At each layer, the current projections produce factors for the current input, and their product gives the score matrix. This is where factorization enters the learning process: its structure determines how each head can represent token relationships within the larger model. Sharing or compressing factors can also reduce memory use, while different factorizations can make longer sequences cheaper to process.
Encoder, decoder, and encoder–decoder: what context is available?
| Architecture | Attention connections | Training context |
|---|---|---|
| Encoder-only (BERT) | Bidirectional self-attention: each token can use left and right context, excluding padding. | Masked-token pretraining predicts selected original tokens from a corrupted input. Original BERT also uses next-sentence prediction. |
| Decoder-only (GPT-style) | Causal self-attention: each position can use itself and earlier positions. | Autoregressive pretraining predicts the next token. A causal mask prevents access to future tokens even when many positions are trained in parallel. |
| Encoder–decoder (original Transformer) | The encoder uses bidirectional self-attention. The decoder combines causal self-attention with cross-attention to encoder outputs. | Predict a target sequence conditioned on a source sequence, for example in translation. During training, the decoder typically receives the shifted true target sequence (teacher forcing). |
BERT's masking is not a causal attention mask. Corrupting selected input tokens creates a prediction task; it does not impose triangular attention support. Bidirectional attention also does not mean symmetric scores: BERT uses separate query and key projections, so $S_c$ need not equal $S_c^T$. See Devlin et al., BERT (2018).
Self-attention versus cross-attention. In self-attention, both factors come from the same sequence, $S_c=(XW_Q)(XW_K)^T$. In encoder–decoder cross-attention, queries come from decoder representations and keys and values from encoder outputs: $S_c=(X_{\mathrm{dec}}W_Q)(X_{\mathrm{enc}}W_K)^T$, with $V=X_{\mathrm{enc}}W_V$. If the sequence lengths are $n_{\mathrm{dec}}$ and $n_{\mathrm{enc}}$, the score and attention matrices have shape $n_{\mathrm{dec}}\times n_{\mathrm{enc}}$. Each row is normalized over encoder positions. This is still a bilinear factorization, but tying the projection matrices alone would not make it a Gram matrix of one shared set of token vectors. See Vaswani et al. (2017), Section 3.2.3.
Pretraining, post-training, and inference: where the factors enter
Pretraining learns reusable parameters. Text supplies prediction targets: the next token for an autoregressive model, selected original tokens for masked language modeling, or a target sequence for conditional generation. A loss, typically cross-entropy on those predictions, is backpropagated through the model, including attention. This updates WQ, WK, WV and output projections along with other trainable parameters. The prediction targets are known; the internal attention matrix P and head output O are not supplied as targets.
The factors are computed activations. On every training or inference forward pass, the current projections produce $Q=XW_Q$, $K=XW_K$ and $V=XW_V$, then $S_c=QK^T$, $P$ and $O=PV$. Thus $W_QW_K^T$ is a factorized learned parameterization, while $QK^T$ constructs the scores for the current input. The factors $Q,K$ are not independent parameter tables optimized separately for each sequence. Calling $X$ known means it is available to this attention operation; in deeper layers it is itself computed by preceding layers and changes as the model is trained.
Post-training adapts the pretrained model. Further training can specialize the model for a task, teach it to follow instructions, or adjust its responses using preference feedback. Depending on the method, some or all parameters are updated. The training signal still passes through the multilayer model; attention heads are not fitted in isolation. Updates to a head's projections, or to the preceding layers that produce its input X, change the factors Q, K and V and therefore its attention behavior.
LoRA is a method for parameter-efficient fine-tuning. For a selected pretrained weight matrix, it freezes $W_0$ and learns an additive update $W'=W_0+BA$, typically with a small inner dimension for $B$ and $A$. Applied to an attention projection such as $W_Q$, this changes the queries computed during each forward pass. The trainable update factors $B,A$ are parameters shared across inputs; the query/key factors $Q,K$ are activations computed for each input. LoRA can be used during post-training, but it specifies how weights are adapted, not the training objective. See LoRA.
How context enters during inference
The context is the supplied token sequence. For a decoder-only LLM, this includes the prompt and any instructions, conversation history or retrieved text that the application puts into that prompt, followed by the tokens already generated. The model does not automatically see earlier conversations or external documents: that information must be supplied in its input. Token embeddings, together with the model's positional mechanism, provide the initial representations. At each subsequent layer, X is the sequence of representations produced by the preceding layers, already incorporating information from the permitted context.
The factors make attention depend on this particular context. At a head in a given layer, the current position supplies a query $q_i=x_iW_Q$. Each available context position supplies a key $k_j=x_jW_K$ and a value $v_j=x_jW_V$. Their scores $(S_c)_{ij}=q_i k_j^T$ are scaled, masked and normalized to give weights $P_{ij}$; the head returns $o_i=\sum_{j\le i}P_{ij}v_j$ for causal self-attention. Thus the learned projections specify how to form queries, keys and values, while the actual prompt determines their contents and the resulting weights. The same fixed model can respond differently to different prompts without changing its parameters.
Generating a continuation grows the context. A decoder-only model first processes the prompt (prefill). Its final-layer representation at the last position is mapped to a distribution over the next token. After a token is selected, it is appended to the sequence and the model computes its representations to predict the following token. With KV caching, each layer reuses the keys and values of earlier positions and adds those for the new token; the new query can attend to the retained context allowed by the mask. Available context is limited by the model and serving configuration, such as a context window or sliding-window mask. This is computation over changing inputs and cached activations, not a parameter update or fine-tuning.
Other architectures receive context differently. A BERT-style encoder processes the supplied sequence with left and right context to produce representations or predictions; it does not ordinarily generate text by appending tokens in a causal loop. In an encoder–decoder model, the encoder represents the supplied source sequence. During generation, the decoder combines its growing target prefix through causal self-attention with the encoder's source representations through cross-attention. Across these architectures, ordinary inference keeps the learned parameters fixed while computing input-dependent factors and attention weights.
Why these structures matter in practice
- KV cache. During autoregressive inference, the persistent KV cache stores $K$ and $V$, not the full score matrix $S_c$. For $L$ layers and $h_{kv}$ key/value heads with equal key and value dimension $d_h$, its size per sequence is $2 L h_{kv} d_h n$ values. MQA and GQA share factors; MLA caches a joint latent representation instead.
- Long context. $S_c$ has $n^2$ entries. Linear attention and Performer replace the softmax kernel by a feature-map factorization, which removes the $n^2$ term (see Kernel Factorizations).
- What a head can express. Tied or untied factors, the head dimension, the row-sum constraint and the mask each decide which attention patterns are possible. These constraints help explain head expressivity, attention sinks and the tendency of pure attention stacks to lose token diversity, with the qualifications below.
Notation: rows are tokens, as in PyTorch and FlashAttention. $X \in \mathbb{R}^{n \times d}$, $Q = XW_Q$, $K = XW_K$, $V = XW_V$, with $W_Q, W_K, W_V \in \mathbb{R}^{d \times d_h}$. We describe the basic content-only projections first; positional modifications such as RoPE are discussed below. $S_c$ is the score (logit) matrix and $P$ the attention matrix.
What is factorized
$(S_c)_{ij} = q_i \cdot k_j$: query token $i$ (the position that reads) scores key token $j$ (the position being read). Written as a sum over the $d_h$ latent coordinates, $S_c = \sum_{a=1}^{d_h} q_{:,a}\,k_{:,a}^{T}$ is a sum of $d_h$ rank-one patterns. Each key is reused in every row and each query in every column, so the $n^2$ scores are coupled through $2 n d_h$ numbers.
The score matrix $S_c$ is constructed rather than supplied as a training target. In standard attention training, there is no score-reconstruction objective $\|S_c-QK^T\|$: that difference is zero by construction. Instead, the model learns the projection matrices through its prediction objective, as described below.
Two levels: the QK circuit and the score matrix
Substitute the definitions: $S_c = X\,W_{QK}\,X^{T}$ with $W_{QK} = W_Q W_K^{T} \in \mathbb{R}^{d \times d}$, rank $\le d_h$. $W_{QK}$ is a learned bilinear form, fixed after training. $S_c$ changes with every input. Interpretability work calls $W_{QK}$ the QK circuit and $W_{OV} = W_V W_O$ the OV circuit of a head (Elhage et al. 2021). Here $W_O\in\mathbb{R}^{d_h\times d}$ is the output projection for this head. Both products have rank at most $d_h$, so they are rank-restricted when $d_h<d$.
In practice: weight absorption. Because only the product $W_Q W_K^{T}$ matters, factors can be moved across it. MLA (DeepSeek-V2) caches a small latent $c_t$ per token and folds the key up-projection into $W_Q$, so full keys are never materialized. This simple absorption into a single fixed matrix requires that no intervening position-dependent operation obstruct the regrouping. RoPE inserts a rotation, $(S_c)_{ij} = x_i W_Q R_{j-i} W_K^{T} x_j^{T}$, where $R_{j-i}=R_i^T R_j$ for the chosen rotation convention. The effective bilinear form now depends on the position pair. DeepSeek-V2 therefore adds a separate small key that carries RoPE ("decoupled RoPE").
Tied factors: Gram matrix. Untied factors: general bilinear form
If $W_Q = W_K$, then $Q = K = Z$ and $S_c = ZZ^{T}$: a Gram matrix, symmetric and PSD, as in Kernel Factorizations. This holds even when $W_Q$ is square and full rank.
In practice: self-preference with equal-norm tied factors. By Cauchy–Schwarz, $(S_c)_{ij} \le \|z_i\|\,\|z_j\|$. If the $z_i$ have equal norms, the largest score in each row is on the diagonal. Under these assumptions, with the diagonal allowed and no extra positional bias, a previous-token head cannot give key $i-1$ a strictly larger score than key $i$. Unequal norms or additional positional terms change this conclusion. Asymmetric content scores, $(S_c)_{ij}\ne (S_c)_{ji}$, require untied query/key maps in this basic model; masks can separately make the final attention directional. Note that $P = \mathrm{softmax}(S_c)$ need not be symmetric even when $S_c$ is, because each row is normalized separately.
Phase transition. Cui, Behrens, Krzakala & Zdeborová (2024) analyse a self-attention layer with tied, low-rank query/key matrices in the high-dimensional limit. The global minimum switches sharply from a positional mechanism (attend by position) to a semantic mechanism (attend by content) as the number of training samples grows. This result concerns their specific solvable model, not a universal transition for all Transformers.
Rank: the head dimension as a bottleneck
$\mathrm{rank}(S_c)\le\min(n,d_h)$ for the dot-product score matrix before additive masks or biases. A head with $d_h=64$ and $n=4096$, for example, has a $4096\times4096$ score matrix of rank at most 64. This is a bottleneck when $d_h<n$; the factorization does not require that inequality. With $d_h = d/h$, adding heads shrinks $d_h$ and limits the patterns each head can express (Bhojanapalli et al. 2020).
In practice: the low rank is in the logits, not in the attention map. Softmax applies $\exp$ entry-wise, and $\exp$ does not preserve rank, so $P$ can be full rank. Methods that project the sequence dimension of $K$ and $V$ (Linformer) assume that $P$ itself is close to low rank. That is a different and stronger assumption.
Simplex constraint: every row sums to one
For finite, unmasked scores, $P$ has positive entries and is row-stochastic: each output $o_i$ is a convex combination of value vectors.
In practice: attention sinks. Softmax cannot assign zero total attention: its weights must sum to one. This does not forbid a zero output through zero values or cancellation. Xiao et al. observe trained models assigning substantial weight to initial tokens even when those tokens are not semantically useful. StreamingLLM (Xiao et al. 2023) shows that keeping these sink tokens in the KV cache is what makes sliding-window generation stable.
In practice: rank collapse with depth. Row-stochasticity alone does not imply rank collapse (the identity matrix is a counterexample). Dong, Cordonnier & Loukas (2021) prove doubly exponential loss of token diversity for pure attention under their stated conditions. Skip connections and MLPs counteract this tendency; the result is not a universal guarantee about full Transformer stacks.
Masking: a fixed support
Setting $M_{ij} = -\infty$ outside an allowed set gives $P_{ij} = 0$ there, with rows still summing to one on the allowed entries. Every row needs at least one allowed entry.
- Causal mask: $j \le i$, so $P$ is lower triangular. This is why the KV cache is valid: keys and values of past tokens do not change when a new token arrives.
- Sliding window: banded support. Longformer: local windows plus global tokens.
This is the sparse-support axis of the Jungle: the mask fixes where the non-zeros can be; the scores fill in the values. FlashAttention computes $PV$ block by block without materializing $S_c$, and supported structured masks allow fully masked blocks to be skipped.
Multi-head: a sum of Kronecker-structured operators, with shared factors
$O = \sum_{h=1}^{H} P_h\, X\, W_{OV}^{h}$, so $\mathrm{vec}(O) = \sum_h \left( W_{OV}^{h\,T} \otimes P_h \right) \mathrm{vec}(X)$. Here $\mathrm{vec}$ stacks columns. Each head is one input-dependent token-mixing matrix $P_h$ ($n \times n$) paired with one fixed feature map $W_{OV}^{h}$ ($d \times d$, rank $\le d_h$). The layer is nonlinear because $P_h$ depends on $X$.
In practice: KV-cache designs are factor-sharing constraints.
- MQA (Shazeer 2019): all heads share one $K$ and one $V$.
- GQA (Ainslie et al. 2023): groups of query heads share one $K$, $V$. Cache shrinks by $h / h_{kv}$.
- MLA (DeepSeek-V2, 2024): every head's keys and values are up-projections of one latent, $K_{\mathrm{content}}^h = C\,W_{UK}^{h}$, $V^h = C\,W_{UV}^{h}$, $C \in \mathbb{R}^{n \times d_c}$. This jointly factorizes the content keys and values through a shared latent dimension $d_c$, giving a rank bottleneck when $d_c$ is restrictive. Only $C$ (plus the small RoPE key) is cached. DeepSeek reports a 93.3% smaller KV cache than DeepSeek 67B.
Linear attention: factorize the kernel instead of the scores
Replace $\exp(q_i \cdot k_j)$ by $\phi(q_i)^{T}\phi(k_j)$ for a feature map $\phi: \mathbb{R}^{d_h} \to \mathbb{R}^{r}$. For unmasked attention, define $D_\phi=\operatorname{diag}(\Phi_Q\Phi_K^T\mathbf{1})$. The normalized feature-map output is $\widetilde O=D_\phi^{-1}\Phi_Q(\Phi_K^T V)$, assuming positive row sums. The usual score scaling can be absorbed into the features. Computing $\Phi_K^{T} V$ first ($r \times d_h$) costs $O(n\,r\,d_h)$ instead of $O(n^2 d_h)$, and in the causal case the prefix sums $\sum_{j\le i}\phi(k_j)v_j^T$ and $\sum_{j\le i}\phi(k_j)$ become recurrent states updated once per token (Katharopoulos et al. 2020). Performer (Choromanski et al. 2020) builds $\phi$ from positive random features that approximate the softmax kernel, extending the random-feature approach discussed in Kernel Factorizations.
Factorized weights and updates
$W_Q$ and $W_K$ can themselves be parameterized as products, and fine-tuning often adds $W' = W + BA$ (LoRA). A low-rank update does not make $W'$ low rank, and neither makes $P$ low rank.
Where the known/unknown framing of this page applies directly
During training, attention is not a recovery problem: there is no target $S_c$. After training, it often is. Converting multi-head attention to GQA, compressing $W_K$ or $W_V$ with a truncated SVD, or compressing cached keys are all problems of the form: given a trained $W_{QK}^{h}$ or a cached $K$ (known), find shared, low-rank or quantized factors (unknown) that preserve scores or outputs. These can be formulated as constrained approximation problems with reconstruction or output-matching losses. For example, GQA conversion can also require further training; an SVD alone does not guarantee preservation of end-to-end behavior.
References and implementations
LoRA & Low-Rank Adaptation (LLMs)
$W' = \underbrace{W}_{\text{frozen}} + \underbrace{B}_{\text{unknown}} \underbrace{A}_{\text{unknown}}$ s.t. $B \in \mathbb{R}^{d \times r}$, $A \in \mathbb{R}^{r \times k}$, $r \ll \min(d,k)$Matrix factorization view: Given frozen pretrained weight W, learn unknown low-rank update ΔW = BA where B∈Rd×r and A∈Rr×k are trainable. Rank r controls parameter count: O(r(d+k)) vs O(dk). Typical r = 4–64 for LLMs with d,k ~ 104.
Key insight: Pretrained weight updates during fine-tuning have low intrinsic rank. LoRA exploits this structure to achieve full fine-tuning quality with <1% trainable parameters.
Tensor Decomposition & Tensor Networks
CP: $\underbrace{\mathcal{T}}_{\text{known}} = \sum_r \underbrace{a_r \otimes b_r \otimes c_r}_{\text{unknown}}$; Tucker: $\mathcal{T} = \underbrace{G}_{\text{unk.}} \times_1 \underbrace{U}_{\text{unk.}} \times_2 \underbrace{V}_{\text{unk.}} \times_3 \underbrace{W}_{\text{unk.}}$Tensor factorization view: Given observed tensor T, decompose into unknown factors. CP: sum of R rank-1 tensors (outer products). Tucker: core tensor G and unknown factor matrices U,V,W. Tensor Train: chain of 3-way cores Gk, storage O(dnr2) vs O(dn). All factors unknown.
Tensor Networks (2011+): Tensor Train (TT) achieves O(dnr²) storage. Tensor Ring (TR, 2016) adds circular structure for permutation invariance. Tensor Wheel (2024) balances TR and fully-connected networks.
Recommender Systems & Neural MF
$\min_{U,V} \sum_{(i,j) \in \Omega} (\underbrace{R_{ij}}_{\text{known}} - \underbrace{u_i}_{\text{unk.}}^T \underbrace{v_j}_{\text{unk.}})^2 + \lambda(\|U\|^2 + \|V\|^2)$Matrix factorization view: Given sparse rating matrix R (observed at Ω), learn unknown user embeddings U∈Rm×k and item embeddings V∈Rn×k. Predict Rij ≈ uiTvj. Regularization prevents overfitting. Implicit feedback: weighted by confidence cij.
NCF Debate (2020): Properly tuned dot product often beats learned MLP similarities. Simple baselines remain competitive.
Graph Matching
$\underbrace{A}_{\text{known}} = \underbrace{X}_{\text{unknown}} \underbrace{B}_{\text{unknown}} X^T$ s.t. $X$ is a permutation matrix Phase TransitionMatrix factorization view: Given adjacency matrix A of a graph, find unknown permutation matrix X and unknown structure B such that A = XBXT. Key constraint: X is a permutation matrix (binary, doubly stochastic). Used for matching nodes across two graphs or recovering hidden structure.
Generalized Matrix Factorization
$\underbrace{W}_{\text{known}} \odot \underbrace{L}_{\text{unknown}} = W \odot \underbrace{U}_{\text{unk.}} \underbrace{V}_{\text{unk.}}^T$, minimize $\text{rank}(L)$Matrix factorization view: Given mask W indicating observed entries, find low-rank matrix L = UVT matching observations. Generalizes matrix completion (binary W) to weighted observations. The Hadamard product W⊙L selects which entries matter.
Archetypal Analysis
$\underbrace{A}_{\text{known}} = \underbrace{D}_{\text{unknown}} \underbrace{X}_{\text{unknown}}$, $D = A\underbrace{B}_{\text{unknown}}$ s.t. $X \geq 0$, $B \geq 0$Matrix factorization view: Given data A, find archetypes D that lie on the convex hull of the data (D = AB with B ≥ 0, columns sum to 1), and coefficients X representing each data point as convex combination of archetypes. Unlike NMF, archetypes are extreme points of the data itself.
Binary Matrix Factorization
$\underbrace{D}_{\text{known}} = \underbrace{T}_{\text{unknown}} \underbrace{A}_{\text{unknown}}$ s.t. $T \in \{0,1\}^{m \times r}$Matrix factorization view: Given data matrix D∈Rm×n, find unknown binary factor T∈{0,1}m×r and coefficient matrix A∈Rr×n such that D = TA. Optional constraint: AT·1r = 1n (columns sum to 1 for convex combinations). Unlike Boolean Matrix Factorization, A is real-valued.
Key insight (Slawski et al. 2013): Despite the combinatorial constraint T∈{0,1}m×r, the problem is tractable when r is small. The algorithm finds all binary vertices of aff(D) using the Littlewood-Offord lemma, achieving O(m·2r-1) complexity.
Applications: DNA methylation unmixing (T = methylation profiles per cell type, A = mixing proportions), binary classification ensembles, topic modeling with hard assignments.
Matrix Compressive Sensing (MCS)
$\underbrace{\mathcal{A}}_{\text{known}}(\underbrace{L}_{\text{unknown}}) = \underbrace{b}_{\text{known}}$ s.t. $L$ is rank-$r$ Phase TransitionMatrix factorization view: Given linear measurements b = A(L) of unknown low-rank matrix L, recover L. Extends compressive sensing from vectors to matrices. Phase transition: O(r(m+n)) measurements suffice for rank-r recovery. RIP for matrices analogous to vector case.
SPCP / Noisy Robust PCA
$\underbrace{A}_{\text{known}} = \underbrace{L}_{\text{unknown}} + \underbrace{S}_{\text{unknown}} + \underbrace{N}_{\text{unknown}}$ s.t. $L$ is low-rank, $S$ is sparse, $N$ is noise Phase TransitionMatrix factorization view: Given noisy observations A, decompose into unknown low-rank L, unknown sparse S, and unknown dense noise N. Extends Robust PCA to handle small dense perturbations. Stable Principal Component Pursuit (SPCP) solves: min ||L||* + λ||S||1 s.t. ||A - L - S||F ≤ ε.
Kernel Factorizations
$\underbrace{K}_{\text{known}} = \underbrace{\Phi}_{\text{unknown}} \Phi^T$ s.t. $K$ is PSDMatrix factorization view: Given kernel matrix K (positive semi-definite), find feature representation Φ such that Kij = φ(xi)Tφ(xj). Kernel PCA, Nyström approximation, and random features all exploit this factorization. Low-rank kernel approximations enable scalable kernel methods.
Non-Convex Optimization & Implicit Regularization
$\min_{U,V} \|\underbrace{U}_{\text{unknown}} \underbrace{V}_{\text{unknown}}^T - \underbrace{M}_{\text{known}}\|_F^2$ s.t. $U \in \mathbb{R}^{m \times r}$, $V \in \mathbb{R}^{n \times r}$ Phase TransitionMatrix factorization view: Given observed matrix M, find unknown factors U, V such that UVT approximates M. The factorization implicitly constrains rank(UVT) ≤ r. Despite non-convexity, all local minima are global when r is large enough.
Key result (Gunasekar et al. 2017): GD on matrix factorization with small init implicitly minimizes nuclear norm. Deep factorization amplifies this bias.
Randomized Algorithms & Sketching (RandNLA)
$\tilde{A} = \Pi A$ where $\Pi \in \mathbb{R}^{k \times m}$, $k \ll m$Matrix factorization view: Randomized numerical linear algebra uses random projections and sketching to compute approximate matrix factorizations efficiently. Key techniques include randomized SVD, Johnson-Lindenstrauss transforms, CountSketch, and streaming algorithms like Frequent Directions. These methods trade exact computation for massive speedups while providing provable approximation guarantees.
Other & Online SVD
Boolean factorization, alignment (RASL/TILT), streaming decompositions, and other specialized methods.
Modern Themes (2015–2024)
Contemporary research directions that cut across classical categories, reflecting the field's evolution toward neural network integration, implicit regularization, and computational-statistical trade-offs.
Computational-Statistical Gaps
Phase TransitionThe "hard phase" regime where information-theoretically recovery is possible but no polynomial-time algorithm is known. Understanding these gaps is central to modern high-dimensional statistics.
Key example: In sparse PCA, the spiked covariance model exhibits a gap: spectral methods require signal strength Θ(n1/4) but information-theoretic limit is Θ(1/√n).
Approximate Message Passing (AMP)
Phase TransitionIterative algorithms with exact asymptotic characterization via state evolution. Predict sharp phase transitions for low-rank recovery, compressed sensing, and community detection.
State Evolution: In high-dimensional limit, AMP error follows deterministic recursion. Correctly predicts success/failure boundary.
AMP phase diagram: density vs noise. Figure from: Donoho, Maleki, Montanari — "Message passing algorithms for compressed sensing" (2009)
Randomized Algorithms & Sketching (RandNLA)
Use random projections to reduce massive matrices into tractable smaller problems while preserving essential structure. Sketching enables single-pass streaming algorithms.
Frameworks & Platforms
Comprehensive software packages integrating multiple factorization methods. GPU acceleration now mainstream via RAPIDS and PyTorch backends.
Preconditioners & Fast Multipole Methods
Direct solvers/FMMFast multipole methods (FMM) can be viewed as hierarchical matrix factorizations. Exploiting low-rank structure of off-diagonal blocks enables O(N) or O(N log N) complexity for dense matrix-vector products and direct solvers. H-matrices, H²-matrices, and butterfly factorizations provide fast approximate inverses and preconditioners.
Matrix Factorization View: The multipole expansion A ≈ B̃C decomposes dense kernel matrices into structured low-rank products. Quadtree/octree decompositions yield hierarchical factorizations with sparse + low-rank blocks.
H²-matrix decomposition: A = S + UKVT (sparse + low-rank). Quadtree structure generalizes to higher dimensions.
Multipole expansion as matrix factorization: A ≈ B̃C. Figure from: Martinsson — FMM Tutorial
Essential References
Matrix Computations
Convex Optimization
Topics in Matrix Analysis
NMF & Tensor Factorizations
Matrix Manifolds
Convex Opt. in SP
Optimization for ML
LAPACK Guide
Phase Transition Atlas (2020s Framing)
Modern papers separate information-theoretic limits from algorithmic limits, and often explain gaps with spectral thresholds or state-evolution analysis.