This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.feature_extraction.text import CountVectorizer | |
cv = CountVectorizer(ngram_range=(1, 3), stop_words="english") | |
model.update_topics(docs, topics, vectorizer=cv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Update topic representation by increasing n-gram range and removing english stopwords | |
model.update_topics(docs, topics, n_gram_range=(1, 3), stop_words="english") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bertopic import BERTopic | |
model = BERTopic() | |
topics, probs = model.fit_transform(docs) | |
# Further reduce topics | |
new_topics, new_probs = model.reduce_topics(docs, topics, probs, nr_topics=30) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bertopic import BERTopic | |
model = BERTopic(nr_topics="auto") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bertopic import BERTopic | |
model = BERTopic(nr_topics=20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.visualize_distribution(probabilities[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bertopic import BERTopic | |
from sklearn.datasets import fetch_20newsgroups | |
docs = fetch_20newsgroups(subset='all', remove=('headers', 'footers', 'quotes'))['data'] | |
model = BERTopic() | |
topics, probs = model.fit_transform(docs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loaded_model = BERTopic.load("my_model") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bertopic import BERTopic | |
model = BERTopic() | |
model.save("my_model") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bertopic import BERTopic | |
model = BERTopic(embedding_model="xlm-r-bert-base-nli-stsb-mean-tokens") |