Skip to content

Commit 3658e32

Browse files
authored
Make UMAP's init default to random on visualize_topics for reproducible visualization (#2412)
1 parent 1bef884 commit 3658e32

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

bertopic/plotting/_topics.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ def visualize_topics(
9595
if HAS_UMAP:
9696
if c_tfidf_used:
9797
embeddings = MinMaxScaler().fit_transform(embeddings)
98-
embeddings = UMAP(n_neighbors=2, n_components=2, metric="hellinger", random_state=42).fit_transform(
99-
embeddings
100-
)
98+
embeddings = UMAP(
99+
n_neighbors=2, n_components=2, metric="hellinger", init="random", random_state=42
100+
).fit_transform(embeddings)
101101
else:
102-
embeddings = UMAP(n_neighbors=2, n_components=2, metric="cosine", random_state=42).fit_transform(embeddings)
102+
embeddings = UMAP(
103+
n_neighbors=2, n_components=2, metric="cosine", init="random", random_state=42
104+
).fit_transform(embeddings)
103105
else:
104106
raise ModuleNotFoundError(
105107
"UMAP is required to reduce the embeddings.. Please install it using `pip install umap-learn`."

0 commit comments

Comments
 (0)