Sub topic 17
Choosing between LDA and BERTopic
This chapter assumes you have trained an LDA model with gensim and fitted a BERTopic model, as in the earlier chapters. You should know what a document-topic mixture is, what UMAP, HDBSCAN and c-TF-IDF do, and how topic coherence is computed. Here the aim is a decision you can defend for a specific corpus.
The two definitions of a topic
The methods answer different questions, so compare them before comparing outputs.
- In LDA, a topic is a probability distribution over the vocabulary. Each document is a mixture of topics, so one document can be 60% "economy" and 40% "health".
- In BERTopic, a topic is a cluster of documents that are close in embedding space. The topic's words come afterwards, from c-TF-IDF. By default each document gets one topic, or the outlier label -1.
LDA describes how words are generated. BERTopic describes where documents sit in meaning space. Most of the practical differences below follow from this.
Side-by-side comparison
| Dimension | LDA | BERTopic |
|---|---|---|
| Input | Bag-of-words counts | Raw text, embedded by a sentence model |
| Document assignment | Mixture over all topics | One topic per document by default |
| Outliers | None. Every document gets a mixture | Topic -1 holds documents that fit no cluster |
| Number of topics | Fixed in advance (`num_topics`) | Found by HDBSCAN, then reducible afterwards |
| Word order and context | Ignored | Captured by the embedding model |
| Short texts | Weak, because there are few co-occurring words | Usually better |
| Hardware | CPU is enough | Embedding is slow on CPU for large corpora |
| Repeatability | Fix `random_state` | Fix the UMAP `random_state`, which gives repeatable runs but slower UMAP |
| Preprocessing | Matters a lot: stop words, lemmas, rare-word filtering | Light. Pass near-raw text |
| Interpretability of the model | Explicit probabilistic story | Pipeline of separate parts |
Decision criteria
Document length and structure
LDA needs enough words per document to estimate a mixture. Tweets, headlines and search queries give it very little to work with, and the topics often come out blurry or dominated by frequent words. BERTopic handles these better because the embedding captures meaning even when few words overlap.
The reverse problem hits BERTopic on long documents. Embedding models truncate their input. all-MiniLM-L6-v2, for example, only reads the first 256 word pieces. A 5,000-word report is represented by its opening paragraph. Split long documents into paragraphs or sections before fitting BERTopic. LDA has no such limit.
Do documents mix themes?
If a news article really covers both elections and football, an LDA mixture represents that directly. BERTopic assigns one topic, so you lose the second theme. BERTopic can estimate a topic distribution per document with calculate_probabilities=True or approximate_distribution, but this is an add-on, not the core model. For corpora where mixtures are the thing you want to measure, such as the share of each theme in each document, LDA is the more natural fit.
Do you need every document labelled?
LDA always gives a mixture, even for a document that matches nothing, and the mixture can be nearly flat. BERTopic admits that some documents fit nowhere, by putting them in topic -1. On noisy data this can be 30% to 50% of the corpus. That is honest, but it creates work: you either accept the outliers or reduce them with reduce_outliers, as shown in the outlier chapter.
Compute and time
LDA on a few hundred thousand documents trains on a laptop CPU in minutes. BERTopic's cost is dominated by embedding. You can cache the embeddings and reuse them while you try different UMAP and HDBSCAN settings, which makes tuning cheap after the first run:
from bertopic import BERTopic
from sentence_transformers import SentenceTransformer
docs = [
"The striker scored twice in the second half.",
"Parliament voted on the new budget on Tuesday.",
] * 50 # replace with your corpus
embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
embeddings = embedding_model.encode(docs, show_progress_bar=False)
topic_model = BERTopic(embedding_model=embedding_model, min_topic_size=10)
topics, probs = topic_model.fit_transform(docs, embeddings=embeddings)
print(len(set(topics)), "distinct labels, including -1 if present")Language and domain
A multilingual embedding model lets BERTopic cluster documents across languages. LDA works on tokens, so mixed-language data needs separate models or heavy preprocessing. For a domain with specialised vocabulary, such as legal or biomedical text, an embedding model trained on general text may place documents poorly, and LDA may be the safer choice. A domain-specific embedding model is the other option.
Control and explainability
LDA gives you explicit levers. num_topics sets the granularity, and alpha and eta control how sparse the document and topic distributions are. You can explain the model with a single generative story. BERTopic offers more steps to tune (UMAP, HDBSCAN, the vectoriser, optional representation models), and each can change the result. Its topic count responds mainly to min_topic_size and min_cluster_size, and indirectly to UMAP settings.
A decision flow
Treat the flow as a starting point. The last box matters most: run both on a sample and compare.
Comparing them fairly
Coherence scores are the obvious comparison, but they need care.
- Compute coherence on the same tokenised texts and the same dictionary for both models. A
c_vscore from one preprocessing pipeline is not comparable with a score from another. - Exclude topic -1 from the BERTopic topic words before scoring, because it is a collection of leftovers and not a topic.
- Compare models with a similar number of topics. A model with 5 topics and one with 80 have very different coherence profiles.
- Always read the top words and sample documents for each topic. A coherence score can reward topics that are tidy but useless, such as one made of boilerplate phrases.
Common errors
- Choosing BERTopic because it is newer. On clean, long documents with a modest vocabulary, LDA is often as good and much cheaper.
- Feeding BERTopic aggressively preprocessed text. Removing stop words and lemmatising before embedding discards the sentence structure the embedding model uses. Put stop-word removal in the
CountVectorizerinstead, as in the pipeline chapter, where it only affects the topic words. - Ignoring topic -1. Reporting "the top topic" without noting that -1 is the largest group misleads readers.
- Comparing runs without fixing seeds. UMAP and LDA both involve randomness. Without
random_state, differences between runs can be mistaken for differences between methods. - Reading LDA topics as clusters of documents. A document's top topic is just its largest mixture weight, which may be only 35%.
Using both
The methods can complement each other. A common pattern is to use BERTopic to explore an unfamiliar corpus, because it needs little preprocessing and finds a topic count for you. Once you know the shape of the data, you can fit LDA with a chosen num_topics when you need document mixtures, stable reporting, or cheap retraining on new batches. For topics over time, BERTopic has topics_over_time built in. With LDA you can average each period's document mixtures to get the same kind of trend, but the topics themselves stay fixed.
Exercise
You have 2 million customer reviews of one to three sentences each, in English and Spanish, and a laptop with no GPU. Your manager wants each review tagged with one theme. Which method do you try first, and what two changes would you make to the setup?
Show answer
Try BERTopic first. The reviews are short, which weakens LDA, and a multilingual embedding model such as paraphrase-multilingual-MiniLM-L12-v2 handles both languages in one model. The two changes are to compute and cache embeddings on a sample first, or on rented GPU time, because embedding 2 million texts on a CPU is slow, and to handle outliers with reduceoutliers, because the manager wants every review tagged. Fit on a sample to tune mintopic_size, then apply the model to the full corpus.
Exercise
A colleague says their BERTopic model scores a higher c_v than your LDA model, so BERTopic is better for your corpus of 3,000-word reports. Give two reasons the comparison may be unfair or the conclusion wrong.
Show answer
First, the two scores may come from different preprocessing, dictionaries, topic counts, or from BERTopic words that include topic -1, so they are not comparable. Second, reports of 3,000 words are truncated by the embedding model unless split, so BERTopic may only be modelling the opening of each report. Reports also tend to mix themes, which LDA's mixtures represent and BERTopic's single label does not. Coherence also says nothing about whether topics are useful, so the topic words and sample documents still need to be read.