- Introduced by
- Lee & Seung
- Year
- 1999
- Type
- Matrix-factorization topic model
What does it do?
NMF topic modeling applies Non-negative Matrix Factorization to a document-term matrix to extract non-negative document-topic and topic-term weights from a corpus.
The factorization is a parts-based decomposition studied by Lee and Seung (1999) in a paper on learning the parts of objects. Unlike probabilistic topic models such as LDA, it is a matrix factorization without a generative model.
The intuition behind the method
A corpus can be written as a large table in which each row is a document and each column is a term. NMF approximates this table as the product of two smaller tables with no negative entries: one giving how strongly each document relates to each topic, and one giving how strongly each term relates to each topic. Because no entry can be negative, components are only added together and do not cancel one another, so each topic is read through the terms with the largest weights in it. Whether those top terms form a coherent theme depends on the corpus and on the choice of k, and has to be checked by reading them.
History
NMF as a parts-based, additive representation was studied by Lee and Seung (1999), whose paper is titled Learning the Parts of Objects by Non-negative Matrix Factorization. Its use as a topic model for text is a later adaptation, and the origin of that adaptation is not verified here.
When to use it
Choose NMF topic modeling when you want to describe or explore a text corpus, can represent the documents as a document-term matrix (TF-IDF weighting is a common choice), and can fix the number of topics k before fitting. Small corpora are a poor fit, because topics estimated from few documents tend to be unstable from one fit to the next. Do not use it when you need a probabilistic or generative model of the text, when you need uncertainty estimates over topics, or when k cannot reasonably be chosen in advance. In those cases a probabilistic model such as LDA is the alternative to consider.
Limitations and considerations
- The number of topics k must be chosen in advance and is not learned from the data.
- Small corpora are a poor fit: with few documents the topics tend to be unstable, and no fixed document count guarantees stability.
- Because it is a matrix factorization rather than a probabilistic model, it provides no generative account of the documents and no principled uncertainty over topics.
- The fit is non-convex, so the factors depend on initialization and the optimizer, and results should be checked across restarts.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- The additive, parts-based factorization keeps every component non-negative, so each topic can be read directly as a set of high-weight terms.
- It works directly on document-term matrices, including TF-IDF-weighted ones.
- The method is conceptually simple: one matrix factorization with a clear split into a document-topic matrix and a topic-term matrix.
Applications
- Discovering and naming the main themes in a collection of documents.
- Summarising large corpora by their dominant topics for exploratory analysis.
- Tagging documents with topic weights for downstream description and search.
- Comparing topic structure across subsets of a corpus.
How it works
How it works
The corpus is turned into a document-term matrix in which each document is a row of weighted term scores. TF-IDF is a common weighting for text: it reduces the weight of terms that occur in almost every document and increases the weight of terms that distinguish one document from another. Other non-negative weightings, such as raw counts, can also be used, and the choice of weighting affects the topics that result.
The document-term matrix V, with documents as rows and terms as columns, is approximated as the product WH, where W has documents as rows and k columns, and H has k rows and terms as columns. The chosen number of topics k sets the inner dimension of this product. The factors are fitted by minimising the reconstruction error, commonly the squared Frobenius norm ||V - WH||^2_F, under the constraint that every entry of W and H is non-negative. This is usually done iteratively, for example with multiplicative updates or alternating least squares. Because the approximation is only approximate, the factors do not reproduce V exactly. The problem is non-convex, so different random initializations can yield different factors, and several restarts should be compared.
Each topic is read from its highest-weighted terms. Since all weights are non-negative and combine additively, these top terms can be inspected and given a label. Whether the resulting themes are clear depends on the data and on k, so the labels should be checked against the documents.
Each document is described by its row in W, which gives the non-negative weight of every topic in that document. These weights can be used to summarise the corpus, to tag documents with their dominant topics, or as input to later description and exploration. If a distribution-like reading is needed, rows or columns can be rescaled to sum to one. This normalization is a post-processing step and is not part of the factorization.
Common pitfalls
- Choosing k poorly: too few topics merge distinct themes, and too many split themes into noisy fragments.
- Choosing the term weighting without thought: the weighting changes which terms carry weight in the factorization, and this can change the topics. TF-IDF is a common choice because it down-weights terms that occur in almost every document.
- Fitting on few documents or using a single run: topics from a small corpus or from one random initialization may change between fits, so the result should be checked by refitting with several restarts.
- Treating the factors as exact rather than approximate: NMF reconstructs the original matrix only approximately.
Frequently asked questions
How is NMF topic modeling different from LDA?
Both can produce document-topic values. NMF is a matrix factorization that keeps all components non-negative and additive, with no generative model, and its result depends on initialization. LDA is a probabilistic generative model. The choice depends on whether a non-negative factorization or a probabilistic account of the text is needed.
How do I choose the number of topics k?
k must be set before fitting, since NMF does not learn it from the data. A practical procedure is to fit several candidate values of k, each with several random restarts, then compare the reconstruction error and how stable the topics are across restarts, and inspect the top terms of each topic for coherence. Reconstruction error alone tends to fall as k grows, so it cannot select k by itself. These checks support the choice of k but do not establish a single correct value.
Why is TF-IDF commonly used instead of raw counts?
TF-IDF is a common weighting that reduces the weight of terms occurring in almost every document and increases the weight of terms that distinguish documents, so common words contribute less to the factorization. Raw counts can also be used, and the weighting choice affects the topics, so it is worth comparing alternatives on your data.
How many documents do I need?
There is no fixed document count that guarantees stable topics. Small corpora tend to produce topics that change from one fit to the next, so refit on your own data with several random starts and check whether the topics remain similar.
Related methods
Sources
Lee, D.D. & Seung, H.S. (1999). Learning the Parts of Objects by Non-negative Matrix Factorization. Nature, 401, 788-791.
Open DOI referenceArora, S., Ge, R., Halpern, Y., Mimno, D., Moitra, A., Sontag, D., Wu, Y. & Zhu, M. (2013). A Practical Algorithm for Topic Modeling with Provable Guarantees. Proceedings of the 30th International Conference on Machine Learning (ICML), 280-288.
Open publication reference