Latent semantic indexing
Latent Semantic Indexing (LSI) = apply truncated Singular Value Decomposition (SVD) to the term–document matrix to find a low-dimensional 'concept' space that reduces synonymy/noise and lets queries match documents by latent concepts.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
LSI is used by engineers inside search systems (IR systems, search engines) to reduce dimensionality of text data and match queries to documents by latent concepts rather than only exact words. It is an automatic way to address synonymy and some polysemy, and is used when you want concept-level ranking or to compress the index (see also TF‑IDF, Vector space model and cosine ranking, and Dimensionality reduction methods in other topics).
Key ideas
A = U Σ V^T.
Here U's columns are left singular vectors, V's columns are right singular vectors, and the diagonal of Σ lists singular values in non‑increasing order σ1 ≥ σ2 ≥ ... ≥ 0.
Assumption: A is real. If A is sparse, compute truncated SVD by specialized algorithms (Lanczos, randomized SVD).
Truncated SVD / Rank‑k approximation (LSI core): keep only the top k singular values and corresponding singular vectors. Write U_k (m × k), Σ_k (k × k), V_k (n × k). Then the rank‑k approximation is
A_k = U_k Σ_k V_k^T. This is the representation used by LSI: it defines a k‑dimensional "concept" space.Eckart–Young theorem (exact statement): Among all matrices B of rank ≤ k, A_k = U_k Σ_k V_k^T is the unique minimiser of the Frobenius norm error ||A − B||_F. In symbols:
A_k = argmin_{rank(B) ≤ k} ||A − B||_F. Assumptions: singular values are distinct enough for uniqueness; proof uses orthogonality and properties of SVD (universities expect derivation sketch).Document and query coordinates in concept space (consistent conventions; pick one and be consistent):
- Each document j is represented by the k‑vector d_j = column j of (Σ_k V_k^T) (shape k × 1). Equivalently, rows of (V_k Σ_k) give document coordinates.
- A query q (m × 1) is projected into concept space by q_k = U_k^T q (k × 1). (This choice makes both q_k and d_j k‑vectors and directly comparable by cosine.) Alternative common convention: represent documents by columns of V_k^T and map queries as q_k = Σ_k U_k^T q; this yields q_k · V_k^T(:,j) = q^T A_k(:,j). Equivalently, to fold in a new document a_new into this space use v_new = Σ_k^{-1} U_k^T a_new. Check which your exam or toolkit expects.
Similarity and ranking: compute cosine similarity between q_k and d_j: cos(q_k, d_j) = (q_k · d_j) / (||q_k|| · ||d_j||). Normalize vectors before ranking.
Why LSI helps: by keeping top k singular vectors LSI keeps dominant co‑occurrence patterns (concepts) and discards noise/rare associations. This can let a query match documents containing related terms (synonymy) because both project to similar concept coordinates.
Limitations: LSI is linear (cannot model complex non‑linear semantics), it can lose fine distinctions (over‑smoothing), it is sensitive to choice of k, and SVD is computationally heavy for large matrices. Also LSI can be affected by stopwords, weighting scheme (TF, TF–IDF), and scaling.
Practical choices: common k values are in hundreds for large corpora; use truncated SVD libraries (ARPACK, randomized SVD) and sparse weighting. Always normalize after projection when using cosine.
Diagram to draw for an exam answer (describe exactly):
- Draw a rectangular matrix labeled A (m × n) with rows "terms" and columns "documents". Arrow pointing to three blocks: U (m × k), Σ (k × k), V^T (k × n) and label them left singular vectors, singular values (diagonal), right singular vectors.
- Draw a second small diagram: show query q (m × 1) mapped via U_k^T to q_k (k × 1), and docs as columns of Σ_k V_k^T (k × n); then show cosine between q_k and each document vector.
Formulas
A = U Σ V^T — A: m × n term–document matrix; U: m × m orthogonal (left singular vectors); Σ: m × n diagonal with singular values σi ≥ 0; V: n × n orthogonal (right singular vectors). Applies to any real matrix A.
A_k = U_k Σ_k V_k^T — truncated SVD keeping top k singular values; U_k: m × k, Σ_k: k × k, V_k: n × k. Best rank‑k approximation in Frobenius norm (Eckart–Young).
d_j = (Σ_k V_k^T)_{:,j} — document j coordinates in k‑dim concept space; units: dimensionless vector of weights.
q_k = U_k^T q — project query q (m × 1) into the same k‑dim concept space; units: dimensionless.
similarity = cos(q_k, d_j) = (q_k · d_j) / (||q_k|| · ||d_j||) — cosine similarity between projected query and document.
Time complexity (dense SVD): O(min(m n^2, m^2 n)) — m = terms, n = documents. Truncated SVD via Lanczos/randomized algorithms is usually much faster for k << min(m,n).
Worked examples
Model exam answer (derivation of best low‑rank approximation): Question: Show why A_k = U_k Σ_k V_k^T is the best rank‑k approximation of A in Frobenius norm. Answer (model): Start from SVD A = U Σ V^T and write Σ = diag(σ1,σ2,...). Let A_k = sum_{i=1..k} σ_i u_i v_i^T (this expands U_k Σ_k V_k^T). For any matrix B of rank ≤ k, B can be expressed in the subspace spanned by the top k singular vectors only up to error. Using orthonormality of u_i and v_i, compute ||A − B||F^2 = sum{i>k} σ_i^2 + additional non‑negative terms. Minimization forces the additional terms to zero and leaves minimal residual sum_{i>k} σ_i^2. Thus A_k minimises the Frobenius norm. (This is the Eckart–Young theorem.) Include the step that shows orthogonality splits the norm into orthogonal components and only the discarded singular values contribute to minimum error.
Numerical LSI example (small, exam‑style): Given term–document matrix A (terms × docs):
A = [[1, 0], [0, 1], [1, 1]](3 terms, 2 documents; columns are documents) Precomputed SVD (show steps briefly): compute A^T A = [[2,1],[1,2]] which has eigenvalues λ1 = 3, λ2 = 1 so singular values σ1 = sqrt(3) ≈ 1.73205, σ2 = 1. Right singular vectors (normalized) v1 = (1/√2)[1,1]^T, v2 = (1/√2)[1,−1]^T. Left singular vectors u_i = (1/σ_i) A v_i give u1 ≈ [0.40825, 0.40825, 0.81650]^T, u2 ≈ [0.70711, −0.70711, 0]^T. Choose k = 1 (truncate to top concept). Then Σ_1 = [1.73205]. Document coordinates (k × n) are columns of Σ_1 V_1^T:- d1 = 1.73205 × (1/√2) ≈ 1.22474
- d2 = 1.73205 × (1/√2) ≈ 1.22474 Query q = [1, 0, 0]^T (term1 only). Project: q_k = U_1^T q = u1^T q ≈ 0.40825. Cosine similarities in 1‑D are identical (both docs have same sign and magnitude): cos = 1.0. Interpretation: after strong dimensionality reduction (k=1), documents that both share term3 are collapsed together and the query cannot distinguish doc1 from doc2. This shows LSI can lose fine distinctions if k is too small.
(All numerical multiplications were checked: A^T A entries, eigenvalues, σ, u and v normalization. If you rederive with exact radicals use √3 and √2.)
Short programming style example (pseudo‑workflow to compute LSI in Python using a library):
- Build sparse term–document matrix A (m × n) with TF–IDF.
- Use sklearn.decomposition.TruncatedSVD(n_components=k) on a docs × terms TF–IDF matrix X. scikit‑learn returns components_ = V_k^T and singular_values_ = σ_i; the reduced document embeddings are X_k = X @ V_k = U_k Σ_k, obtainable via fit_transform/transform.
- Compute doc coordinates with X_k = svd.transform(X) (do not use components_.T * singular_values_ for doc embeddings; that yields term/topic loadings, not per‑document vectors).
- Project a query vectorised like a row of X using svd.transform([q]) to get its k‑dim embedding; then use cosine similarity against the transformed document vectors.
Common mistakes
- Using q_k = U_k^T q but comparing to V_k^T(:,j) without scaling—must use the same coordinate convention.
- Not normalising vectors before cosine similarity.
- Choosing k too small (over‑compression) or too large (keeps noise); don’t assume bigger k always better.
- Confusing singular values σi with eigenvalues λi of A^T A; σi = sqrt(λi).
- Forgetting computational cost: naive SVD on very large sparse A is impractical without truncated/randomised algorithms.
For your exam
Kinds of questions:
- Definitions: define LSI, SVD, left/right singular vectors, rank‑k approximation, Eckart–Young theorem.
- Short notes: explain how LSI handles synonymy, limitations, and complexity.
- Derivations: derive A_k form from SVD, outline proof of Eckart–Young theorem.
- Numericals: small A given, compute A^T A, singular values (or given σ and v, compute U), form A_k, project a query and compute cosine similarities. Show matrix dimensions carefully.
- Diagrams: draw term–document → SVD block decomposition and query/document projection arrows.
What full‑marks answers include:
- Correct SVD statement with matrix dimensions and orthogonality claims.
- Explicit expression for A_k and statement of Eckart–Young theorem.
- Correct projection formulas with consistent coordinate convention, and correct normalisation for cosine.
- For numericals, list intermediate matrices (A^T A), eigenvalues/singular values, normalized singular vectors, U_k, Σ_k, V_k^T, and final similarity numbers with units/dimension remarks (dimensionless).
Quick check
- What is the basic matrix factorisation LSI uses?
- Write the rank‑k LSI approximation formula.
- How do you project a query q into the k‑dim concept space (one correct convention)?
Answers: 1. SVD (A = U Σ V^T). 2. A_k = U_k Σ_k V_k^T. 3. q_k = U_k^T q (and then compare to document vectors which are columns of Σ_k V_k^T), or the equivalent convention q_k = Σ_k U_k^T q if documents are represented by columns of V_k^T.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?