NMF Topic Model

Machine Learning
Introduced by
Lee, D. D. & Seung, H. S.
Year
1999
Type
Matrix factorization / unsupervised topic model
Family
Deep learning / NLP / CV

What does it do?

Non-negative Matrix Factorization (NMF) is an unsupervised matrix decomposition method that can be used to find latent topics in a text corpus.

It factors a document-term matrix into two non-negative matrices, one holding topic-word weights and the other holding document-topic weights. Because the factors cannot be negative, the model tends to build topics additively from parts, which often gives topics that are readable without further processing.

The intuition behind the method

Imagine the corpus as a large spreadsheet where rows are documents and columns are words. NMF asks whether this spreadsheet can be rebuilt from a small number of word patterns, which become the topics. Because all values must be non-negative, one pattern cannot be cancelled out by subtracting another, so the model has to combine patterns additively. Each document is then described as a mixture of these patterns. In practice, the topics are often easy to label from their top words, although this depends on the corpus and the settings.

History

Non-negative Matrix Factorization was introduced by Daniel D. Lee and H. Sebastian Seung in a 1999 Nature paper, which showed that NMF applied to image data learns localized, parts-based components. The companion paper on algorithms, in the Advances in Neural Information Processing Systems proceedings, presents the multiplicative update rules that are now standard. The method was later applied to text, where its input, a non-negative and sparse document-term matrix, is a natural fit for the factorisation.

When to use it

Use NMF when you want topics that are easy to read and label from a text corpus, and when the question is exploratory rather than a probabilistic model of how documents were generated. It is usually applied to TF-IDF matrices built from documents of moderate length, such as abstracts, news articles or survey responses. Raw term counts are also accepted, but they tend to let frequent words dominate many topics, so TF-IDF is the usual choice. It suits moderate-sized corpora where interpretability matters more than inference. Avoid NMF when documents are very short, since their rows in V are too sparse to factor meaningfully. Also avoid it when you need document-topic probabilities for downstream probabilistic inference or held-out likelihood evaluation, and consider LDA or neural topic models instead when the corpus is very large and sparse.

Limitations and considerations

  • The number of topics k must be set by the user; the method has no built-in way to infer it from the data.
  • NMF is not a generative probabilistic model, so the document-topic values are not probabilities and cannot be used directly in probabilistic pipelines.
  • When the initialisation is random, different runs can give different topics; a deterministic initialisation such as NNDSVD removes this source of variation.
  • Very short documents produce sparse rows in V that are hard to factor meaningfully.
  • The standard formulation does not model topic correlation or document-level covariates, which structural topic models can represent.
  • The factorisation is not unique, and the multiplicative updates converge only to a local minimum. Different starting points or different k can give different topics, so check stability across seeds and report the seed.
  • Multiplicative updates can converge slowly on large vocabularies, and runtime grows with corpus size and k. The choice of loss (Frobenius or KL divergence) changes the factors, so it should be reported with the results.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • The non-negativity constraint gives additive, parts-based factors, which is the property that motivated the method in its original image-data application.
  • With a fixed initialisation such as NNDSVD, repeated runs on the same matrix and settings are reproducible, although the result can still be a local minimum rather than a unique optimum.
  • TF-IDF input down-weights common words, which reduces, but does not remove, the need for stop-word filtering.
  • It is available in standard machine learning libraries such as scikit-learn, and it has few hyperparameters beyond k, the initialisation and the loss.

Applications

  • Topic discovery and thematic analysis of document collections such as scientific abstracts, news articles and open-ended survey responses.
  • Document clustering and labelling of large text repositories, using the document-topic weights as cluster memberships.
  • Using document-topic vectors as features in recommendation or retrieval systems.
  • Dimensionality reduction of sparse document-term matrices before a downstream classifier.
  • Serving as a baseline against which probabilistic or neural topic models are compared.
  • Beyond text, the same factorisation is used for parts-based decomposition of image, gene expression and audio data.

How it works

How it works

1

The corpus is converted into a document-term matrix V with one row per document and one column per vocabulary term. Each cell usually holds a TF or TF-IDF score, which is a non-negative count or its weighted equivalent. Before this step, the text is normally preprocessed (lowercasing, stop-word removal, optional stemming), and the vocabulary is pruned by minimum and maximum document frequency to remove noisy terms.

2

V is approximated as the product of two non-negative matrices: W (n by k, document-topic weights) and H (k by m, topic-word weights), where k is the chosen number of topics. Both matrices are initialised, either with a non-negative SVD-based seed (NNDSVD) or with random non-negative values, and are then refined iteratively to reduce a reconstruction loss. The loss is commonly the Frobenius norm of V minus WH, and the KL divergence is a common alternative.

Formula
V \approx W H,\; W \in \mathbb{R}_{\geq 0}^{n \times k},\; H \in \mathbb{R}_{\geq 0}^{k \times m}
3

The Lee-Seung multiplicative update rules, in the Frobenius-loss form shown in the mechanics, update H and W in turn. Each update multiplies the current entries by a non-negative ratio, so non-negativity is preserved at every step. An entry that reaches zero stays at zero in later updates, which is one reason the solution becomes sparse. Iteration stops when the reconstruction loss no longer changes meaningfully or when a maximum number of iterations is reached.

Formula
H \leftarrow H \odot \frac{W^{T}V}{W^{T}WH}, \quad W \leftarrow W \odot \frac{VH^{T}}{WHH^{T}}
4

After each iteration the algorithm compares the change in reconstruction loss with a tolerance. When the change is small enough, convergence is declared. Implementations also impose an iteration limit so that training ends on large vocabularies even if the loss keeps decreasing slowly. The exact tolerance and limit are implementation settings and should be reported with the results.

5

Once the factorisation has converged, each row of H is a topic, and its highest-weighted columns are the words that define it. Each row of W gives a document's soft membership across the topics. Topics are usually labelled from their top words, commonly five to ten. Topic coherence measures such as NPMI can be computed to compare candidate values of k.

Common pitfalls

  • Choosing k without comparing coherence scores across a range of candidate values.
  • Using raw counts instead of TF-IDF, which lets high-frequency words dominate many topics.
  • Skipping vocabulary pruning by minimum and maximum document frequency, which leaves rare or ubiquitous terms that add noise to the factors.
  • Reading the row-normalised document-topic weights as true probabilities; they are only a convenient scaling of non-negative weights.
  • Ignoring how preprocessing choices such as stemming versus lemmatisation and the stop-word list change the vocabulary, and therefore the topics.

Frequently asked questions

How do I choose the number of topics k?

Run NMF for a range of candidate k values and compute a topic coherence measure such as NPMI or C_V for each. Plot coherence against k and look for a peak or an elbow. Topics should also be checked by reading their top words, since a high coherence score does not guarantee that the topics are useful for your question.

Is NMF better than LDA?

Neither is better in every case. NMF often gives topics that are easy to read and label, but it is not a generative probabilistic model. LDA provides document-topic distributions that are proper probabilities and supports held-out likelihood evaluation. The choice depends on whether interpretability or probabilistic inference is the priority.

Does NMF require stop-word removal?

TF-IDF input reduces the influence of common words automatically, but explicit stop-word removal and minimum document-frequency pruning usually still help by removing tokens that add noise without contributing to coherent topics.

How reproducible are NMF results?

With NNDSVD initialisation, the starting point is deterministic, so repeated runs with the same matrix and settings give the same result. This does not mean the solution is unique or globally optimal, because the factorisation can settle in a local minimum. With random initialisation, set and report a random seed, and check stability across seeds, since different runs can yield different topic orderings or word weights.

Can NMF handle multilingual corpora?

Only if the document-term matrix is built so that each language's vocabulary is handled appropriately, or if the corpus is translated to a common language first. Multilingual topic models, such as polylingual LDA or multilingual BERT-based approaches, are designed for cross-lingual settings and may be more suitable there.

Related methods

Sources

  1. Lee, D. D., & Seung, H. S. (1999). Learning the parts of objects by non-negative matrix factorization. Nature, 401(6755), 788–791.

    Open DOI reference
  2. Lee, D. D., & Seung, H. S. (2001). Algorithms for non-negative matrix factorization. In Advances in Neural Information Processing Systems (NIPS), 13, 556–562.

    Open publication reference
  3. 2015_Book_DataMining, p. 191