liveBook · Manning

Truncated singular value decomposition

As explained in Natural Language Processing in Action, Second Edition

TruncatedSVD is a scikit-learn estimator that computes a truncated singular value decomposition, typically using randomized methods for sparse input.

Truncated singular value decomposition reduces a large matrix to its most useful dimensions. For text analysis, it projects sparse TF–IDF or bag-of-words document vectors into a smaller document-topic space, preserving broad patterns while discarding less important dimensions. section 4.3.2

Choose p dimensions rather than retaining the full decomposition. This is especially practical for sparse natural-language matrices, where most entries are zero and randomized methods can compute an approximate decomposition efficiently. section 4.3.2 section 4.4.2

Project TF–IDF documents into topics

from sklearn.decomposition import TruncatedSVD svd = TruncatedSVD(n_components=16, n_iter=100) svd_topic_vectors = svd.fit_transform(tfidf_docs) The resulting matrix represents documents with 16 topic coordinates instead of thousands of term-frequency coordinates. The returned fit-transform result is U · S, while svd.components_ contains V, whose word weights help inspect the topics. section 4.4.1

Inspect component weights alongside the vocabulary to identify which words contribute to each topic. Interpretation still depends on data preparation: noisy vocabulary terms can make topics difficult to understand. section 4.4.1

Unlike PCA, TruncatedSVD does not center the input before decomposition. Centering can turn a sparse matrix dense, increasing runtime and memory, so TruncatedSVD is generally better suited to sparse TF–IDF data. section 4.4.2

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains retained dimensions, matrix factors, implementation outputs, topic inspection, and the PCA distinction.
Examples
Uses scikit-learn code to transform comment TF–IDF vectors into 16 topic coordinates and inspect word weights.
What it assumes
Assumes TF–IDF or bag-of-words vectors and basic matrix decomposition terminology while clarifying sparse-input behavior.
What you can do after
Apply it via scikit-learn to project sparse document matrices and inspect their topic coordinates and component weights.
How it connects
Connects singular value decomposition, latent semantic analysis, TF–IDF, bag-of-words, document-topic matrices, and PCA.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.