Topic Modeling

Machine Learning
Introduced by
Hofmann, T. (pLSA, 1999); Blei, D. M., Ng, A. Y., & Jordan, M. I. (LDA, 2003)
Year
1999–2003
Type
Unsupervised generative probabilistic model
Family
Deep learning / NLP / CV

What does it do?

Topic modeling refers to unsupervised probabilistic methods that infer latent thematic structure in a text collection from patterns of word co-occurrence.

In the two models named here, Hofmann's Probabilistic Latent Semantic Analysis (1999) and Latent Dirichlet Allocation (Blei, Ng, and Jordan, 2003), each topic is a distribution over the vocabulary and each document is a mixture of topics. No labelled training data are required.

The intuition behind the method

Imagine reading thousands of articles and trying to group them by theme without knowing the themes in advance. Topic modeling does this mathematically: it assumes each document is a mixture of a small number of latent topics, and each topic is characterised by a distribution over words. Words like 'election', 'vote', and 'senate' cluster into a politics topic; 'gene', 'protein', and 'cell' cluster into biology. The algorithm finds both the word-topic weights and the per-document topic proportions simultaneously, guided only by co-occurrence patterns in the corpus.

History

Latent semantic analysis (LSA) uncovered hidden structure in term-document matrices through matrix decomposition, but it had no probabilistic generative formulation. Hofmann (1999) introduced Probabilistic Latent Semantic Analysis, giving topic models a generative probabilistic interpretation. Blei, Ng, and Jordan (2003) formalised Latent Dirichlet Allocation by adding a Dirichlet prior over document-topic distributions, which enables Bayesian inference and generalisation to unseen documents. Later neural and transformer-based variants, such as BERTopic, embed documents before clustering and are aimed at improving coherence on short or specialised texts.

When to use it

Choose topic modeling when you have a sizeable unlabelled text collection, no predefined categories, and an exploratory question about its themes, such as open-ended survey responses, academic abstracts, or news archives. It suits settings where the number of topics is not known in advance. If new documents must be scored after fitting, choose LDA rather than pLSA, because pLSA learns document-topic proportions only for the training documents. Avoid topic modeling when the corpus is small, because word co-occurrence statistics are unstable with little text; when documents are very short, where a short-text adaptation is needed; or when you need precise per-document category predictions rather than soft thematic proportions. For labelled classification, supervised methods such as BERT-based classifiers are usually preferable.

Limitations and considerations

  • The number of topics K must be specified or searched, which requires fitting several models and comparing coherence and qualitative quality.
  • Short texts produce sparse co-occurrence counts, so topics are often incoherent or redundant.
  • Classical LDA uses a bag-of-words assumption (exchangeability), so word order and syntax are ignored.
  • Inference is stochastic (variational or Gibbs sampling), so results vary across runs; a fixed random seed is needed for reproducibility.
  • The model returns word lists, not topic names; each topic must be labelled by an analyst.
  • pLSA has no document-level generative model, so it cannot infer topic proportions for documents outside the training set and is prone to overfitting.

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

Strengths

  • Fully unsupervised: themes are discovered from raw text without labelled training data.
  • Can be applied to large corpora with online or distributed inference variants.
  • Topics are returned as ranked word lists that domain experts can read and validate.
  • Document-topic proportions are continuous and can serve as compact features for downstream models.
  • LDA is a Bayesian generative model with a Dirichlet prior, so its inference targets posterior distributions rather than a single point estimate. The approximations used in practice (variational inference or Gibbs sampling) add their own approximation error and run-to-run variability.

Applications

  • Exploratory analysis of open-ended survey or interview responses to surface recurring themes.
  • Mapping research trends across large collections of academic abstracts or grant proposals.
  • Monitoring public discourse and opinion dynamics in news or social media corpora.
  • Generating document-topic features for downstream classification or recommendation systems.
  • Corpus navigation and search: tagging documents with topic proportions to enable faceted retrieval.
  • Longitudinal analysis of how topics in a domain evolve over time.

How it works

How it works

1

Raw text is tokenised and cleaned: stopwords and punctuation are usually removed, and very rare or very frequent terms are filtered out. Stemming, lemmatisation, and vocabulary-size limits are optional choices. Without this step, function words tend to dominate the topics, because the model has no built-in way to tell which words are uninformative.

2

Each document is converted into a vector of word counts over the vocabulary. Word order is discarded, but the co-occurrence statistics across documents remain, and these are what the model uses to find themes.

3

For pLSA, the model estimates word-topic distributions p(w|z=k) and document-topic proportions p(z=k|d) jointly. The formula above states that the probability of a word in a document is the sum over topics of its probability under each topic, weighted by that topic's share of the document. For LDA, a Dirichlet prior is placed on the document-topic proportions, and the exact posterior is intractable, so variational inference or Gibbs sampling is used to approximate it.

Formula
p(w|d) = \sum_{k=1}^{K} p(w|z=k)\,p(z=k|d)
4

After fitting, each topic is summarised by its highest-weighted words. Each document receives a topic-proportion vector showing how much of its content is attributed to each topic. These vectors can serve as features for downstream classification or regression.

5

Interpreting the output requires human judgement. Coherence measures such as NPMI or C_v help compare candidate values of K, but the top-weighted words of each topic should still be read to check that the topics are meaningful and not redundant.

Common pitfalls

  • Skipping stopword removal and vocabulary filtering, so function words fill the top-word lists and substantive themes are buried.
  • Choosing K without comparing coherence scores (NPMI, C_v) across candidate values and reading the resulting topics.
  • Treating the model's topics as validated categories without checking the top-word lists with a domain expert.
  • Applying standard topic models to very short texts such as single sentences or social media posts, where co-occurrence is too sparse without a short-text adaptation.
  • Reporting a single run only; check whether topics are stable across random seeds, since an apparent theme may be an artefact of initialisation.

Frequently asked questions

How do I choose the number of topics K?

Compute a coherence score (such as C_v or NPMI) for a range of candidate K values and look for the point where coherence stops improving meaningfully. Then read the top words of the candidate models to check that the topics are meaningful and non-redundant; the coherence curve alone rarely settles the choice.

How much data do I need for topic modeling to work well?

Classical LDA needs enough documents and vocabulary for the word co-occurrence statistics to be stable. With a small corpus, topics are often incoherent. In that case, qualitative thematic analysis or an embedding-based approach such as BERTopic may be more suitable.

Can I use topic modeling output as features in a classifier?

Yes. The document-topic proportion vector is a compact, dense representation that can be passed directly to logistic regression, a random forest, or a neural classifier. This is a common pipeline in semi-supervised workflows where labelled data are scarce.

What is the difference between LDA and NMF for topic modeling?

LDA is a probabilistic generative model estimated by Bayesian inference; NMF (Non-negative Matrix Factorisation) is a matrix decomposition. Both produce word-topic and document-topic matrices. The NMF solution depends on its initialisation, and LDA inference is stochastic, so both can vary across runs. On clean corpora they often yield similar topics; the choice usually depends on whether a probabilistic model is needed and on computational constraints.

Does topic modeling work on non-English text?

Yes, at the algorithm level, since it only requires tokenised text. Language-specific preprocessing, such as stopword lists and stemming or lemmatisation, is needed. For multilingual corpora, multilingual embeddings such as mBERT combined with a method like BERTopic can be considered.

Related methods

Sources

  1. Blei, D. M., Ng, A. Y., & Jordan, M. I. (2003). Latent Dirichlet Allocation. Journal of Machine Learning Research, 3, 993–1022.

    Open publication reference
  2. Hofmann, T. (1999). Probabilistic Latent Semantic Analysis. Proceedings of the Fifteenth Conference on Uncertainty in Artificial Intelligence (UAI), 289–296.

    Open publication reference