Skip to content

Commit f361f2c

Browse files
committed
Adding BERTopic notebook and examples to Readme.
1 parent 62af7fa commit f361f2c

9 files changed

+507
-19
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.idea/*
22
.gitattributes
33
*.pyc
4+
.DS_Store
5+
dist/*

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,28 @@ Topically's first feature is to name clusters of texts based on their content. F
3737
# Usage Example: Topically + BERTopic
3838
Use Topically to name clusters in the course of topic modeling with tools like BERTopic. Get the cluster assignments from BERTopic, and name the clusters with topically.
3939

40-
`TODO: Add code example`
40+
```python
41+
42+
from bertopic import BERTopic
43+
from topically import Topically
44+
45+
# Load and initialize BERTopic
46+
topic_model = BERTopic(nr_topics=10)
47+
48+
# df is a dataframe. df['title'] is the column of text we're modeling
49+
df['topic'], probabilities = topic_model.fit_transform(df['title'], embeds)
50+
51+
# Load topically
52+
app = Topically('cohere_api_key')
53+
54+
# name clusters
55+
df['cluster_names'] = app.name_clusters((df['title'], df['topic']))
56+
57+
df[['title', 'topic', 'cluster_names']]
58+
```
59+
60+
61+
<img src="./assets/topically-name_topics-example.png" />
4162

4263
# Installation
4364

317 KB
Loading

0 commit comments

Comments
 (0)