What Is Topic Modeling

The idea behind topic models. The vocabulary mismatch problem, topics as distributions over words and documents as mixtures of topics, how topic models differ from clustering and classification, preparing text for them, and what they are used for in retrieval and beyond.

A topic model describes a collection by a few topics, each a probability distribution over the vocabulary, and each document as a mixture of them. A document's word distribution is then $P(w \mid d) = \sum_z P(w \mid z) P(z \mid d)$, a words-by-topics table times a topics-by-documents table. The idea addresses two failures of word matching, synonymy and polysemy. On six toy documents, a sea topic (ship 0.4, boat 0.2, ocean 0.4) and a travel topic (voyage 0.6, trip 0.4) give $d_3$ (only ship) probability 0.2 for boat and make $d_1$ two-thirds sea. The model cannot tell $d_2$, which contains boat, from $d_3$, so retrieval combines topics with exact matching. Unlike k-means clustering, membership is mixed; unlike classification, topics are found, not given.

Of the six tiny documents that run through this topic, $d_3$ says only ship and $d_2$ says boat ocean. Both are about the sea, yet they share no word, so a search for boat misses $d_3$. Could a program learn, from the documents alone, that ship, boat and ocean belong together, and describe each document by what it is about?

A topic model does this: it finds groups of words that recur together across a collection, and describes each document by how much of each group it contains. News stories, for instance, contain thousands of distinct words but far fewer subjects. Stories about interest rates use bank, rate, money, central, and fed together; stories about takeovers use offer, shares, merger, tender, and bid.

First we name the two failures of word matching that topic models address. Then we define topics and mixtures on the six documents. Finally we compare topic models with clustering, and cover preparing text and uses. The article assumes the vector space model and its limits.

The problem topic models address

The retrieval models of earlier topics match words. Two failures follow from that, and both motivated latent semantic indexing (Deerwester, Dumais, Furnas, Landauer, and Harshman, 1990; Manning, Raghavan, and Schütze, 2008, §18.4):

  • Synonymy. Different words can mean the same thing. A query for car misses documents that say only automobile. A searcher's word for a concept often differs from an author's: Furnas, Landauer, Gomez, and Dumais (1987) found that two people spontaneously chose the same word for the same thing less than 20 percent of the time.
  • Polysemy. The same word can mean different things. A query for jaguar matches documents about the animal, the car, and the operating system, which share the word but nothing else.

The limits of the vector space model traced both to its treatment of every term as an independent dimension. There, an auto-insurance page went unrewarded for auto when the query said car. The remedy that topic models offer is to find dimensions that correspond to meaning. If car and automobile both belong to the same topic, documents using either word are close on that topic. If jaguar belongs partly to an animal topic and partly to a car topic, the other words in a document decide which applies.

The next section says exactly what a topic is.

Topics and mixtures

The probabilistic topic models share a simple picture (Blei, 2012):

  • A topic is a probability distribution over the vocabulary. An interest-rate topic gives high probability to bank, rate, and money and almost none to wheat. In LDA, whose prior adds pseudo-counts, every topic assigns some probability to every word (the pLSA fit below does not), but in practice each is characterized by its few dozen most probable words.
  • A document is a mixture of topics. A story might be 60 percent interest rates, 30 percent currency markets, and 10 percent other subjects. Its words are imagined as drawn from those topics in those proportions.

Fitting a topic model means working backward: given only the words, we look for topics and mixtures that would plausibly have produced them. The topics are latent: never observed directly, and inferred from the way words co-occur across many documents. Words that often appear in the same documents end up in the same topics.

A small example

The articles in this topic share one tiny collection of six documents over five words, from Manning, Raghavan, and Schütze (2008, §18.4):

Document Words
$d_1$ ship ocean voyage
$d_2$ boat ocean
$d_3$ ship
$d_4$ voyage trip
$d_5$ voyage
$d_6$ trip

Two topics describe it well. A sea topic gives ship and ocean probability 0.4 each and boat 0.2. A travel topic gives voyage 0.6 and trip 0.4. Documents $d_2$ and $d_3$ are entirely sea, $d_4$ to $d_6$ entirely travel, and $d_1$ two-thirds sea and one-third travel. These are the values that probabilistic latent semantic analysis finds when fitted to the six documents: the best of its 20 fits, reported in that article's section "The example" and checked by hand in its first worked problem.

The mixture picture says that each document's word distribution is its topics' distributions, averaged with the document's own weights. For $d_1$:

$$P(\text{ship} \mid d_1) = \tfrac{2}{3} \times 0.4 + \tfrac{1}{3} \times 0 = 0.267, \qquad P(\text{voyage} \mid d_1) = \tfrac{2}{3} \times 0 + \tfrac{1}{3} \times 0.6 = 0.2.$$

Doing this for every word and document is a matrix product: a words-by-documents table of probabilities equals a words-by-topics table times a topics-by-documents table.

The six-document example as a matrix product. Left, each document's observed word frequencies. Next, the fitted model's word probabilities, which equal the topics (a 5-by-2 table) times the mixtures (a 2-by-6 table). Notice that two topics cannot reproduce every document exactly: d2 contains "boat" and "ocean" but its fitted distribution spreads over all three sea words, and d1's fitted distribution gives "boat" probability although d1 does not contain it.
The six-document example as a matrix product. Left, each document's observed word frequencies. Next, the fitted model's word probabilities, which equal the topics (a 5-by-2 table) times the mixtures (a 2-by-6 table). Notice that two topics cannot reproduce every document exactly: d2 contains "boat" and "ocean" but its fitted distribution spreads over all three sea words, and d1's fitted distribution gives "boat" probability although d1 does not contain it.

Example (a word the document does not contain). $d_1$ does not contain boat, yet the model gives boat probability $\tfrac{2}{3} \times 0.2 + \tfrac{1}{3} \times 0 = 0.133$ in $d_1$, reaching it through the sea topic.

The model is not a copy of the data. Back to $d_3$, which contains only ship: the model gives it a 0.2 chance of boat, because sea documents use boat. That is how a topic model handles synonymy: a query for boat can match $d_3$ through the sea topic, though the word never appears in it.

Latent semantic indexing reaches a related representation by linear algebra instead of probability. Its dimensions are not distributions, and a document's coordinates on them can be negative. The purpose is the same: a few dimensions, learned from co-occurrence, that capture what documents are about better than individual words do.

How the models compare

Every model in this topic factors the term-document matrix into a small number of dimensions. They differ in what the factors may contain and in what they optimize:

Model Factors Entries Fitted by New documents
LSI (1990) term patterns × weights × document patterns any sign least squares (SVD) folded in by projection
pLSA (1999) $P(w \mid z)$ × $P(z \mid d)$ probabilities maximum likelihood (EM) folded in by re-running EM
LDA (2003) $\phi$ × $\theta$, with Dirichlet priors probabilities Bayesian inference (sampling or variational) have a probability under the model
NMF (beyond LDA) nonnegative × nonnegative nonnegative weights least squares or KL divergence fitted with the topics fixed

The dates are those of Deerwester and colleagues (1990), Hofmann (1999), and Blei, Ng, and Jordan (2003). Reading down the table is reading the history: each model kept its predecessor's factorization and changed what was wrong with it. Grouping words and documents is also what clustering does, and the next section says where the two part.

Topic models, clustering, and classification

Topic modeling is unsupervised, like clustering. No categories or labeled examples are given, and people must interpret what is found. The difference is in what a document is allowed to be. K-means assigns each document to exactly one cluster. A topic model gives each document a degree of membership in every topic, a soft or mixed-membership assignment. That suits documents, which often cover several subjects, and it lets the same word belong to several topics, which handles polysemy.

Example (a document no hard cluster fits). Suppose the six documents had to be split into two hard clusters, sea and travel. $d_1$ (ship ocean voyage) fits neither: two of its words are sea words, one a travel word, and either cluster misstates it. The topic model keeps both facts, with $d_1$ two-thirds sea and one-third travel.

The topics also differ from the categories of classification. Someone defined the Reuters categories with a purpose. A topic model finds whatever patterns of co-occurrence are strongest in the collection, and those may cut across the categories people would choose. In the Reuters experiment described in latent Dirichlet allocation, the single category of earnings reports was divided among several topics. Among them were results tables, dividend announcements, stock splits, and the language of quarterly earnings.

Since a topic is whatever the text supports, how the text is prepared matters.

Preparing text

The probabilistic models work with word counts, so documents are represented as bags of words, ignoring order. Preparation follows the text processing pipeline with a few differences in emphasis:

  • Stop words matter more. Words such as the and said appear in nearly every document. Left in, they are spread across all topics or gathered into a topic of their own. Collections usually need additional, collection-specific stop words. For Reuters, abbreviations such as mln, dlrs, and pct were removed as well.
  • Very rare and very common words are usually dropped. A word in two documents gives too little evidence of a co-occurrence pattern, and a word in half of them distinguishes nothing.
  • Stemming is often skipped. It reduces the vocabulary, but stemmed words make topics harder to read, and readability is the point of many applications.
  • Weighting depends on the model. LSI is usually applied to weighted vectors, such as TF-IDF. LDA and pLSA model raw counts, since their probabilities are defined over word occurrences.

What topic models are used for

  • Exploring a collection. The commonest use is to get an overview of a collection too large to read: which subjects it covers, in what proportions, and how they change over time. Historians, political scientists, and literary scholars have used topic models to study newspaper archives, legislative speeches, and scientific literatures.
  • Retrieval. LSI was proposed as a retrieval model, matching queries and documents in the latent space. Topic models have also been used to smooth document language models. A document's model then gives some probability to words it does not contain but its topics do, as in topic models beyond LDA.
  • Features for other tasks. A document's topic proportions are a short, dense description of it. They are useful as input to classifiers, for finding similar documents, and for recommendation.
  • Organizing and browsing. Topics can label and connect documents in an interface, as clusters can, with the difference that a document can appear under several topics.

Worked problems

The course had no assignment for this topic. These three problems are posed on the six documents and the two topics stated above, and every number in them is checked by plsa_toy.py in tools/experiments/topics/.

Problem 1 (the model's word distribution for every document). Using the sea topic (ship 0.4, boat 0.2, ocean 0.4), the travel topic (voyage 0.6, trip 0.4) and the mixtures stated above, write out $P(w \mid d)$ for all six documents, and compare $d_2$'s with its observed word frequencies.

Each column is the document's mixture applied to the two topics. For $d_1$ it is $\tfrac{2}{3}(0.4, 0.2, 0.4, 0, 0) + \tfrac{1}{3}(0, 0, 0, 0.6, 0.4)$. The documents that are entirely one topic take that topic's distribution unchanged:

$d_1$ $d_2$ $d_3$ $d_4$ $d_5$ $d_6$
ship 0.267 0.4 0.4 0 0 0
boat 0.133 0.2 0.2 0 0 0
ocean 0.267 0.4 0.4 0 0 0
voyage 0.200 0 0 0.6 0.6 0.6
trip 0.133 0 0 0.4 0.4 0.4

Every column sums to 1, as a distribution must. This table is the product of the 5-by-2 table of topics and the 2-by-6 table of mixtures, the factorization of the figure. $d_2$ (boat ocean) has observed frequencies $(0, 0.5, 0.5, 0, 0)$, and the model gives it $(0.4, 0.2, 0.4, 0, 0)$. The model moves 0.4 of its probability to ship, a word $d_2$ does not contain, because two topics cannot give $d_2$ a distribution of its own.

Problem 2 (the query boat). Rank the six documents by the probability the model gives the word boat, and compare with word matching.

From the boat row of the table, $d_2$ and $d_3$ tie at 0.2, $d_1$ follows at 0.133, and the three travel documents have 0. Word matching finds $d_2$ alone, the only document that contains boat. The model reaches $d_3$ (ship) and $d_1$, which is the gain against synonymy. It also shows a loss. The model cannot tell $d_2$, which says boat, from $d_3$, which does not, since both are entirely sea and so have the same distribution. That is why retrieval with topic models combines the topic estimate with exact matching, as topic models beyond LDA works out for this same query.

Problem 3 (what the mixture buys for $d_1$). Compute the probability of $d_1$'s three words, ship ocean voyage, under its mixture, and under each of the two hard assignments of $d_1$ to a single topic.

Under the mixture the probability is $\tfrac{4}{15} \times \tfrac{4}{15} \times \tfrac{1}{5} = 0.0142$, using $P(\text{ship} \mid d_1) = P(\text{ocean} \mid d_1) = \tfrac{2}{3} \times 0.4 = \tfrac{4}{15}$ and $P(\text{voyage} \mid d_1) = \tfrac{1}{3} \times 0.6 = \tfrac{1}{5}$. If $d_1$ were entirely sea, voyage would have probability 0, and if it were entirely travel, ship and ocean would. Either hard assignment gives the document's words probability 0 with these topics. The mixture is the only description under which $d_1$ is possible at all. Within it, each word still has one source: the sea topic is the only one that gives ship and ocean any probability, and travel the only one for voyage, so two of the three words come from the sea and one from travel, the proportions of the mixture.

What we have learned

A topic is a probability distribution over words, and a document is a mixture of topics. On the six documents, a sea topic gives $d_3$ a 0.2 chance of boat though it says only ship. A mixture can also split a document: $d_1$ is two-thirds sea and one-third travel.

The first method for finding the topics did not use probability: latent semantic indexing factors the term-document matrix with the singular value decomposition.

References

  • Blei, D. M. (2012). Probabilistic topic models. Communications of the ACM, 55(4), 77–84. record · 2 pages
  • Blei, D. M., Ng, A. Y., and Jordan, M. I. (2003). Latent Dirichlet allocation. Journal of Machine Learning Research, 3, 993–1022. record · 6 pages
  • Deerwester, S., Dumais, S. T., Furnas, G. W., Landauer, T. K., and Harshman, R. (1990). Indexing by latent semantic analysis. Journal of the American Society for Information Science, 41(6), 391–407. record · 4 pages
  • Furnas, G. W., Landauer, T. K., Gomez, L. M., and Dumais, S. T. (1987). The vocabulary problem in human-system communication. Communications of the ACM, 30(11), 964–971. record · 2 pages
  • Hofmann, T. (1999). Probabilistic latent semantic analysis. In Proceedings of the Fifteenth Conference on Uncertainty in Artificial Intelligence (UAI 1999), 289–296. record · 2 pages
  • Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, chapter 18. Cambridge University Press. record · 102 pages

Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 11 revisions