Using the modular property of BERTopic
Because BERTopic is modular, you can employ alternative techniques for a model. This section will show you the code structure and then explain what other techniques you can implement. First, you will import the following classes:
from umap import UMAPfrom hdbscan import HDBSCAN from sentence_transformers import SentenceTransformer from sklearn.feature_extraction.text import CountVectorizer from bertopic import BERTopic from bertopic.representation import KeyBERTInspired from bertopic.vectorizers import ClassTfidfTransformer
Your BERTopic model, topic_model
, is a collection of modules as follows. This view is clear because it tells us the components of BERTopic:
topic_model = BERTopic( # word embedding embedding_model=embedding_model, # dimension reduction umap_model=umap_model, ...