Registry / ai-ml / bertopic

bertopic

JSON →
library0.17.4pypypiunverified

BERTopic is a topic modeling technique that leverages state-of-the-art transformer models (like BERT) and a class-based TF-IDF procedure to create dense clusters, resulting in easily interpretable topics while retaining important words in their descriptions. It is currently at version 0.17.4 and actively maintained with regular updates and feature enhancements.

pip install bertopic
INSTALL
IMPORT
SIG · BERTOPIC
B
bertopic
ai-mlpythonv0.17.4
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.960 runs
build_error
glibc
py 3.103.960 runs
timeout
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BERTopic
from bertopic import BERTopic

This quickstart example demonstrates how to initialize BERTopic, fit it to a dataset (the 20 newsgroups dataset is commonly used), and retrieve information about the discovered topics. The `fit_transform` method processes the documents, returning topic assignments and probabilities.

from bertopic import BERTopic from sklearn.datasets import fetch_20newsgroups # Fetch documents (e.g., 20 newsgroups dataset) docs = fetch_20newsgroups(subset='all', remove=('headers', 'footers', 'quotes'))['data'] # Initialize and train BERTopic model topic_model = BERTopic() topics, probs = topic_model.fit_transform(docs) # Get information about the frequent topics topic_info = topic_model.get_topic_info() print(topic_info.head())
Debug
Known issues
breakingBERTopic models are not guaranteed to be compatible across different versions. When saving and loading models, ensure that the BERTopic version, Python version, and dependency versions (e.g., UMAP, HDBSCAN) are identical to prevent errors or unexpected behavior.
fix
Pin the versions of `bertopic` and its core dependencies (`umap-learn`, `hdbscan`, `sentence-transformers`) in your `requirements.txt` or `pyproject.toml` to match the environment where the model was trained.
affects: <0.17.0
gotchaThe default UMAP algorithm used for dimensionality reduction has a stochastic nature, meaning repeated runs with the same data can yield slightly different topic results.
fix
For reproducible results, initialize UMAP with a `random_state` and pass it to BERTopic: `from umap import UMAP; umap_model = UMAP(random_state=42); topic_model = BERTopic(umap_model=umap_model)`.
affects: All versions
gotchaFor optimal performance, especially with large documents or when iterating over parameters, it is recommended to pre-calculate embeddings and pass them to BERTopic.
fix
Calculate embeddings once using `sentence-transformers` (or your preferred embedding model) and then pass them as the `embeddings` argument to `topic_model.fit_transform(docs, embeddings=precomputed_embeddings)`.
affects: All versions
gotchaBy default, BERTopic initializes with an English-optimized embedding model ('all-MiniLM-L6-v2'). For multilingual datasets, you must explicitly specify the language.
fix
For multilingual documents, initialize BERTopic with `topic_model = BERTopic(language="multilingual")`. This will load a multilingual model ('paraphrase-multilingual-MiniLM-L12-v2').
affects: All versions
deprecatedSupport for Python 3.8 was officially dropped with recent BERTopic versions, notably around 0.17.x releases.
fix
Upgrade your Python environment to Python 3.9 or higher. Python 3.10 and 3.11 are explicitly supported, with 3.13 support added in recent patches.
affects: >=0.17.0
Upgrade
Version history
0.17.4latest on PyPI · released Dec 3, 2025
Audit
Dependencies
sentence-transformersrequiredDefault for embedding documents.
umap-learnrequiredDefault for dimensionality reduction.
hdbscanrequiredDefault for clustering.
scikit-learnoptionalUsed for alternative dimensionality reduction (e.g., PCA) if umap-learn is not installed in lightweight mode.
Agent activity
46 hits · last 30 days
node
40
Amazon
1
OpenAI (training)
1
Resources