Singular Value Decomposition › Randomized SVD for Scale

Michael BrenndoerferUpdated March 21, 20264 min read
Language AI HandbookAll chapters
Part 3 of 67Distributional Semantics
Chapter 18Singular Value Decomposition › Randomized SVD for Scale
Reading section 7 of 14 · Randomized SVD for Scale · 4 minSection 7 of 14 · 4 min

Book contents

Section 7 of 14 · 4 min read

Singular Value Decomposition › Randomized SVD for ScaleOne section · Sections in this chapter7 / 14 ↓
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

Even with sparse algorithms, exact SVD becomes slow for matrices with millions of rows or columns. Modern production NLP systems may want to compute embeddings for vocabularies of 500,000 to 1 million words. Randomized SVD, introduced by Halko, Martinsson, and Tropp in their influential 2011 paper "Finding structure with randomness," provides a principled approximation that dramatically reduces computation while maintaining high accuracy.

Randomized SVD

Randomized SVD approximates the top-kk singular vectors of a matrix by first projecting it onto a random low-dimensional subspace, then applying standard SVD to the smaller projected matrix. The result is nearly as accurate as exact SVD but much faster to compute, especially when kk is small relative to the matrix dimensions.

The algorithm works in two stages that together are much cheaper than direct SVD.

Stage 1: Range finding. The goal of this stage is to find a small orthonormal matrix Q\mathbf{Q} whose columns approximately span the range (column space) of M\mathbf{M}, restricted to the kk dominant directions. Generate a random matrix G\mathbf{G} of shape n×(k+p)n \times (k + p), where pp is a small oversampling parameter, typically 5 to 10. The oversampling provides insurance that the random projection does not miss any important directions. Form the sample matrix:

Y=MG\mathbf{Y} = \mathbf{M} \mathbf{G}

Compute an orthonormal basis Q\mathbf{Q} for the column space of Y\mathbf{Y} using QR decomposition. The key insight is that multiplying M\mathbf{M} by a random matrix produces a "sketch" of the column space of M\mathbf{M}. If M\mathbf{M} has kk dominant singular directions with much larger singular values than the rest, then Y\mathbf{Y} will be approximately a linear combination of those kk directions plus small random perturbations. QR decomposition extracts an orthonormal basis for this sketch.

Stage 2: SVD of the projected matrix. Form the smaller matrix:

B=QTM\mathbf{B} = \mathbf{Q}^T \mathbf{M}

B\mathbf{B} has dimensions (k+p)×n(k + p) \times n. Rather than being enormous, B\mathbf{B} is small in its first dimension: only k+pk + p rows. Compute the exact SVD of B\mathbf{B}:

B=U^ΣVT\mathbf{B} = \hat{\mathbf{U}} \mathbf{\Sigma} \mathbf{V}^T

Recover the approximate left singular vectors as U=QU^\mathbf{U} = \mathbf{Q} \hat{\mathbf{U}}.

The computational saving is substantial. The expensive operations in the randomized algorithm are the matrix-vector products in forming Y\mathbf{Y} and B\mathbf{B}, each costing O(nnz)O(\text{nnz}) for a sparse matrix. The full SVD of B\mathbf{B} costs O((k+p)2n)O((k+p)^2 n), which is small when k≪mk \ll m. Compared to exact SVD at O(k⋅nnz)O(k \cdot \text{nnz}), the asymptotic cost is similar, but the constant factors are much smaller because the algorithm avoids the iterative Lanczos refinement. For very large matrices, the difference is an order of magnitude in wall time.

The theoretical guarantee is that the error of randomized SVD is, with high probability, only slightly larger than the error of the best rank-kk approximation. Specifically:

E∥M−QQTM∥F≤(1+kp−1)1/2σk+1\mathbb{E}\|\mathbf{M} - \mathbf{Q}\mathbf{Q}^T\mathbf{M}\|_F \leq \left(1 + \frac{k}{p-1}\right)^{1/2} \sigma_{k+1}

where the expectation is over the random choice of G\mathbf{G} and σk+1\sigma_{k+1} is the (k+1)(k+1)-th singular value. When pp is even modestly large (say, p=10p = 10) and the singular values decay rapidly (as they do in NLP matrices), the bound is tight and the approximation is excellent.

An optional but often used power iteration step can further improve accuracy: instead of computing Y=MG\mathbf{Y} = \mathbf{M} \mathbf{G}, compute Y=(MMT)qMG\mathbf{Y} = (\mathbf{M} \mathbf{M}^T)^q \mathbf{M} \mathbf{G} for small qq (typically 1 or 2). Each power iteration squares the singular values, making the dominant ones even more prominent relative to the small ones and producing a better sketch of the dominant subspace. The cost is 2q2q additional matrix-vector products.

Scikit-learn's TruncatedSVD uses randomized SVD internally for large matrices, making it the practical tool of choice for LSA at scale. The algorithm='randomized' option (the default) invokes this randomized approach.