Sub topic 9
Where LDA struggles
This chapter assumes you have trained an LDA model with gensim, as in the previous chapter. You should know the generative story, the roles of alpha and eta, and what a bag-of-words corpus is. The goal is to recognise the situations where LDA output looks fine but is misleading, and to know what to try first.
The bag-of-words assumption
LDA sees each document as a count of words. Word order and sentence structure are discarded. This causes three concrete problems.
- Phrases are split. "New York" becomes "new" and "york", which can land in different topics. Detect phrases before building the dictionary, for example with gensim's
Phrases. - Context is lost. "The bank approved the loan" and "the river bank flooded" both contribute a count for "bank" to whichever topic is likely. LDA has no mechanism to use the neighbouring words to separate the two senses.
- Synonyms are unrelated. "Car" and "automobile" are different columns in the count matrix. LDA can only link them if they co-occur in the same documents often enough. Sentence embeddings, which BERTopic uses, place such words close together without needing co-occurrence.
You must choose the number of topics
LDA needs num_topics before training. The data does not tell you the right value, because there often is no single right value.
- Too few topics merge themes. A "sports and politics" topic is a typical symptom.
- Too many topics split one theme into near duplicates, or produce topics made of generic words.
- Coherence scores help (see the previous chapter), but they are noisy and often have a plateau rather than a clear peak. Pick the smallest value near the plateau and then read the topics.
Non-parametric variants such as HDP exist, but they bring their own tuning problems. In practice, you run LDA several times with different num_topics values and inspect the results.
Instability across runs
LDA inference starts from a random state and optimises a non-convex objective, so it finds a local optimum. Two runs with different seeds can give different topics. Small changes in the data, the vocabulary filter, or the number of passes also change the result.
Check this before you trust any single model. The script below trains two models with different seeds and reports, for each topic in the first model, how closely its best match in the second model overlaps in top words (Jaccard similarity: shared words divided by all distinct words).
from gensim import corpora
from gensim.models import LdaModel
docs = [
["goal", "match", "player", "team", "season"],
["election", "vote", "party", "government", "policy"],
["team", "coach", "league", "season", "win"],
["minister", "government", "vote", "law", "policy"],
]
dictionary = corpora.Dictionary(docs)
corpus = [dictionary.doc2bow(doc) for doc in docs]
def top_words(model, n=5):
return [
{dictionary[w] for w, _ in model.get_topic_terms(t, topn=n)}
for t in range(model.num_topics)
]
def jaccard(a, b):
return len(a & b) / len(a | b)
models = [
LdaModel(
corpus=corpus,
id2word=dictionary,
num_topics=2,
passes=10,
random_state=seed,
)
for seed in (1, 2)
]
topics_a, topics_b = (top_words(m) for m in models)
for i, words_a in enumerate(topics_a):
best = max(jaccard(words_a, words_b) for words_b in topics_b)
print(f"topic {i}: best match in other run = {best:.2f}")Scores near 1.0 mean the topic reappears. Low scores mean the topic depends on the seed. Topics that do not reappear across several seeds should not be reported as findings. Raising passes and iterations reduces some of the instability but does not remove it.
Short and uneven documents
LDA estimates each document's topic mixture from that document's own words. A tweet with six tokens gives very little evidence, so its mixture is dominated by the prior alpha. Typical results are:
- Topics that mostly reflect a few frequent words.
- Mixtures that look flat or arbitrary.
- Very long documents overpowering the topic-word distributions during training.
Common remedies are to merge short texts into pseudo-documents (for example, all posts by one user or in one thread), to filter out very short documents, or to use an embedding-based method.
Sensitivity to preprocessing
Topic quality depends heavily on what you feed in. The same corpus gives different topics with different choices.
| Choice | Effect if done badly |
|---|---|
| Stop-word list | Frequent function words form "junk" topics |
| Minimum document frequency | Rare typos and names add noise to the vocabulary |
| Maximum document frequency | Corpus-wide words (for example "said" in news) appear in every topic |
| Lemmatisation | Word variants split counts across columns |
| Phrase detection | Multi-word terms are split and mixed across topics |
In gensim, dictionary.filter_extremes(no_below=5, no_above=0.5) is a common starting point. Always apply the filter before building the bag-of-words corpus.
Topics are not always interpretable
LDA optimises likelihood, not human readability. A topic is a distribution over all vocabulary words, and nothing forces its top words to form a theme. Common failure cases:
- Junk topics: generic words ("people", "think", "like") that appear everywhere.
- Mixed topics: two unrelated themes sharing one topic because there were too few topics.
- Background topics: boilerplate such as email footers or copyright notices.
Labels like "Topic 3" mean nothing until you read the top words and a few top documents. Do both, because top words can look coherent while the highest-probability documents show something else.
Every document gets topics
LDA has no outlier concept. Each document is a mixture over the topics, even if it is spam, in another language, or off-topic. Such documents are forced into topics and distort the topic-word distributions. BERTopic handles this with its outlier topic -1. With LDA, you filter beforehand: drop documents in the wrong language, remove duplicates, and consider a threshold on the dominant topic probability to flag documents that fit nothing well.
Static and flat structure
- LDA treats the corpus as one batch. If themes shift over time, a single model blurs them. Dynamic variants exist, but they are more complex to run.
- Topics are flat. LDA does not tell you that "football" and "cricket" belong under "sport". You can approximate a hierarchy by comparing topic similarity afterwards.
- Probabilities of topics are a mixture. A document with 0.5 on one topic and 0.5 on another is not the same as a document that is half about each theme, and the numbers depend on
alpha.
Putting it together
The diagram shows the main symptoms and where to look first.
When to look elsewhere
These problems do not make LDA useless. It is fast, cheap, works on a CPU, gives soft mixtures per document, and is easy to explain. It is a weaker choice when your texts are short, when meaning depends on context, or when you cannot pick a topic count. The later chapters on BERTopic and on choosing between the two methods return to this trade-off.
Exercise
You train LDA with 10 topics on 50,000 tweets. Topic 4 has the top words "like", "just", "get", "good", "really", and the topics change a lot when you change the random seed. Name two likely causes and one change for each.
Show answer
Likely causes are (1) generic words that were not filtered, and (2) very short documents that give little evidence for each document's topic mixture. For (1), extend the stop-word list and use filterextremes with a lower noabove so very common words are removed. For (2), pool tweets into longer pseudo-documents (for example by user or hashtag), or filter very short tweets. Raising passes and comparing several seeds also helps you decide which topics are stable.
Exercise
Why can LDA not treat "car" and "automobile" as related unless they co-occur, and which method in this tutorial avoids that limit?
Show answer
LDA works on word counts, where each word is a separate column with no built-in notion of meaning. Similarity only emerges through shared documents. BERTopic uses sentence embeddings, which place texts with similar meaning close together even when they share no words.