- Introduced by
- Maarten Grootendorst
- Year
- 2022
- Type
- Neural topic-modeling pipeline
What does it do?
BERTopic is a neural topic-modeling pipeline introduced by Maarten Grootendorst in 2022.
It combines transformer-based contextual embeddings, UMAP dimensionality reduction and HDBSCAN density-based clustering, and then labels each cluster with its most distinctive terms using a class-based TF-IDF procedure.
The intuition behind the method
Classic topic models treat a document as a bag of words and rarely capture what words mean in context. BERTopic instead starts from contextual embeddings, so documents that discuss the same thing in different words end up close together. It groups those nearby documents into clusters and then reads off the words that make each cluster distinctive, and those words become the topic label. The result is a set of themes that come from the meaning of the text rather than from raw word counts alone.
History
BERTopic was introduced by Maarten Grootendorst in 2022 as a neural topic-modeling approach that pairs transformer embeddings with a class-based TF-IDF procedure. Its clustering stage uses HDBSCAN; the HDBSCAN reference on this page is the software paper by McInnes, Healy and Astels (2017).
When to use it
Choose BERTopic when you have a collection of text and want to discover its themes without defining them in advance, for exploratory or descriptive work on cross-sectional or longitudinal text. It needs a reasonably large corpus, because the density-based clustering has little signal in small collections, and very small corpora often yield unstable topics. Compute matters too, since the embedding step is expensive and a GPU is preferred. Do not use it when your categories are already defined and labelled; supervised classification is more suitable then.
Limitations and considerations
- It needs a sufficient number of documents to form stable topics; small collections, often well under a hundred documents, tend to produce unstable clusters.
- The transformer embedding step is expensive, and a GPU or comparable compute is preferred.
- Results depend on the embedding model and on the UMAP and HDBSCAN settings chosen, so different configurations can produce different topics.
- UMAP is a stochastic projection; without a fixed random seed, repeated runs on the same corpus may produce somewhat different clusters.
- HDBSCAN leaves some documents unassigned as outliers, so not every document receives a topic.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Builds on contextual embeddings, so it can group documents that share meaning even when they use different words, which bag-of-words models do not capture.
- Density-based clustering leaves atypical documents unassigned rather than forcing them into topics, which keeps the topics themselves more focused.
- Supports dynamic topic modeling, so topics can be followed over time on time-stamped corpora.
- A multilingual embedding model allows the same pipeline to work across languages.
Applications
- Discovering themes in large collections of documents or reports for exploratory analysis.
- Tracking how topics in a corpus evolve over time on time-stamped text.
- Summarising open-ended survey responses or reviews into interpretable themes.
- Organising scientific or social-media corpora into coherent topic clusters across languages.
How it works
How it works
Each document is converted into a contextual embedding by a BERT-based transformer model. Because the embedding reflects meaning in context, documents that express the same idea in different wording tend to lie near each other in the vector space. A multilingual embedding model allows the same pipeline to process corpora in several languages. The embedding model is chosen by the user and should be matched to the corpus language and domain.
The high-dimensional embeddings are projected into a lower-dimensional space with UMAP. The projection aims to preserve local neighbourhood structure, which makes the data more manageable for the clustering step, since density estimation becomes less reliable as dimensionality grows.
HDBSCAN groups the reduced embeddings into density-based clusters. Because it is density-based, it can find clusters of varying shape and leaves sparse or atypical documents unassigned as outliers instead of forcing every document into a topic.
For each cluster, a class-based TF-IDF score ranks the terms that are most distinctive of that cluster compared with the others. In this procedure all documents in a cluster are treated as a single class document, so the weight of a term reflects how distinctive it is for that cluster relative to the others, rather than for individual documents. The top-ranked terms form the topic's representation. On time-stamped corpora, the same topics can be tracked across time as dynamic topics.
Common pitfalls
- Running it on too few documents leaves the density-based clustering without enough signal to form meaningful topics.
- Choosing an embedding model that does not match the corpus language degrades topic quality; use a multilingual or language-appropriate model.
- Treating unassigned outlier documents as a failure rather than as expected behaviour of density-based clustering.
- Labelling topics from their class-based TF-IDF terms alone, without reading representative documents, which can lead to over-interpreting a topic label.
Frequently asked questions
How is BERTopic different from classic topic models like LDA?
Classic models such as LDA work from word counts and a bag-of-words view of each document. BERTopic starts from contextual transformer embeddings, reduces them with UMAP, clusters them with HDBSCAN, and labels each cluster with class-based TF-IDF terms. Because it works from contextual embeddings, it can group documents by meaning rather than by shared word counts alone.
How many documents do I need?
The sources behind this page do not give a fixed minimum. Small collections, often well under a hundred documents, tend to give unstable topics, because the density-based clustering has little signal to work with. Check whether the topics stay stable on your own data before relying on them.
Why are some of my documents not assigned to any topic?
HDBSCAN is a density-based clustering algorithm and deliberately leaves genuinely sparse or atypical documents unassigned as outliers rather than forcing them into a topic. In typical BERTopic output these documents are labelled -1. This is expected behaviour, not an error.
Can BERTopic handle non-English text?
Yes. By selecting a multilingual embedding model the same pipeline can process corpora in many languages; matching the embedding model to the corpus language is key to good topic quality.
Related methods
Sources
Grootendorst, M. (2022). BERTopic: Neural topic modeling with a class-based TF-IDF procedure. arXiv:2203.05794.
Open DOI referenceMcInnes, L., Healy, J. & Astels, S. (2017). hdbscan: Hierarchical density based clustering. Journal of Open Source Software, 2(11), 205.
Open DOI reference