MaartenGr/BERTopic

visualize_topics() 's problem

Closed this issue · 2 comments

when i use visualize_topics1 = topic_model.visualize_topics()
it comes to
File "D:\PyChram\BertTopic_Project\Dji\Dji_patent.py", line 52, in
visualize_topics1 = topic_model.visualize_topics()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\envs\bertopic\Lib\site-packages\bertopic_bertopic.py", line 2240, in visualize_topics
return plotting.visualize_topics(self,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\envs\bertopic\Lib\site-packages\bertopic\plotting_topics.py", line 79, in visualize_topics
embeddings = UMAP(n_neighbors=2, n_components=2, metric='cosine', random_state=42).fit_transform(embeddings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\envs\bertopic\Lib\site-packages\umap\umap_.py", line 2887, in fit_transform
self.fit(X, y, force_all_finite)
File "D:\anaconda3\envs\bertopic\Lib\site-packages\umap\umap_.py", line 2780, in fit
self.embedding_, aux_data = self.fit_embed_data(
^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\envs\bertopic\Lib\site-packages\umap\umap
.py", line 2826, in fit_embed_data
return simplicial_set_embedding(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\anaconda3\envs\bertopic\Lib\site-packages\umap\umap
.py", line 1086, in simplicial_set_embedding
graph.data[graph.data < (graph.data.max() / float(n_epochs_max))] = 0.0
^^^^^^^^^^^^^^^^
File "D:\anaconda3\envs\bertopic\Lib\site-packages\numpy\core_methods.py", line 41, in _amax
return umr_maximum(a, axis, None, out, keepdims, initial, where)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation maximum which has no identity

A small tip, whenever you share an error log, make sure to always your full code and provide enough context. For instance, it's not clear to me which version of BERTopic you are using or if the problem stems from initializing BERTopic for example.

Thus, can you share a bit more information? Also, and this is a bit of a stretch, it might be that you have generated too few topics but I cannot be sure without knowing more about your model.

A small tip, whenever you share an error log, make sure to always your full code and provide enough context. For instance, it's not clear to me which version of BERTopic you are using or if the problem stems from initializing BERTopic for example.

Thus, can you share a bit more information? Also, and this is a bit of a stretch, it might be that you have generated too few topics but I cannot be sure without knowing more about your model.

thanks , I find it was because generated too few topics. I use another data generate 62 topics, it can be visualized.