MaartenGr / BERTopic

Leveraging BERT and c-TF-IDF to create easily interpretable topics.
https://maartengr.github.io/BERTopic/
MIT License
6.19k stars 765 forks source link

datamapplot is not defined #2170

Closed LauwXiang closed 1 month ago

LauwXiang commented 1 month ago

Have you searched existing issues? 🔎

Desribe the bug

When I try to use fig = topic_model.visualize_document_datamap(texts, embeddings=embeddings) fig.savefig("file.png") I encounter the following error.

`NameError Traceback (most recent call last) Cell In[28], line 2 1 # import datamapplot ----> 2 fig = topic_model.visualize_document_datamap(texts, embeddings=embeddings) 3 fig.savefig("file.png")

File d:\software\miniconda3\envs\transformers\lib\site-packages\bertopic_bertopic.py:2620, in BERTopic.visualize_document_datamap(self, docs, topics, embeddings, reduced_embeddings, custom_labels, title, sub_title, width, height, datamap_kwds) 2618 check_is_fitted(self) 2619 check_documents_type(docs) -> 2620 return plotting.visualize_document_datamap( 2621 self, 2622 docs, 2623 topics, 2624 embeddings, 2625 reduced_embeddings, 2626 custom_labels, 2627 title, 2628 sub_title, 2629 width, 2630 height, 2631 datamap_kwds, 2632 )

File d:\software\miniconda3\envs\transformers\lib\site-packages\bertopic\plotting_datamap.py:148, in visualize_document_datamap(topic_model, docs, topics, embeddings, reduced_embeddings, custom_labels, title, sub_title, width, height, datamap_kwds) ... 155 datamap_kwds, 156 ) 158 return figure

NameError: name 'datamapplot' is not defined`

Even after I installed datamapplot, I still get the above error. Moreover, after restarting the computer and trying to run it again, the following error appears as well. I can only resolve the following issue by uninstalling both bertopic and datamapplot, and then reinstalling bertopic.


> 
> `---------------------------------------------------------------------------
> FileNotFoundError                         Traceback (most recent call last)
> Cell In[1], [line 2](vscode-notebook-cell:?execution_count=1&line=2)
>       [1](vscode-notebook-cell:?execution_count=1&line=1) import pandas as pd
> ----> [2](vscode-notebook-cell:?execution_count=1&line=2) from bertopic import BERTopic
>       [3](vscode-notebook-cell:?execution_count=1&line=3) from sentence_transformers import SentenceTransformer
>       [4](vscode-notebook-cell:?execution_count=1&line=4) from umap import UMAP
> 
> File d:\software\miniconda3\envs\transformers\lib\site-packages\bertopic\__init__.py:3
>       [1](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/__init__.py:1) from importlib.metadata import version
> ----> [3](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/__init__.py:3) from bertopic._bertopic import BERTopic
>       [5](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/__init__.py:5) __version__ = version("bertopic")
>       [7](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/__init__.py:7) __all__ = [
>       [8](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/__init__.py:8)     "BERTopic",
>       [9](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/__init__.py:9) ]
> 
> File d:\software\miniconda3\envs\transformers\lib\site-packages\bertopic\_bertopic.py:49
>      [46](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/_bertopic.py:46) from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
>      [48](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/_bertopic.py:48) # BERTopic
> ---> [49](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/_bertopic.py:49) from bertopic import plotting
>      [50](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/_bertopic.py:50) from bertopic.cluster import BaseCluster
>      [51](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/_bertopic.py:51) from bertopic.backend import BaseEmbedder
> 
> File d:\software\miniconda3\envs\transformers\lib\site-packages\bertopic\plotting\__init__.py:7
>       [5](file:///D:/software/miniconda3/envs/transformers/lib/site-packages/bertopic/plotting/__init__.py:5) from ._term_rank import visualize_term_rank
> ...
>    [1118](file:///D:/software/miniconda3/envs/transformers/lib/pathlib.py:1118) def _opener(self, name, flags, mode=0o666):
>    [1119](file:///D:/software/miniconda3/envs/transformers/lib/pathlib.py:1119)     # A stub for the opener argument to built-in open()
> -> [1120](file:///D:/software/miniconda3/envs/transformers/lib/pathlib.py:1120)     return self._accessor.open(self, flags, mode)
> 
> FileNotFoundError: [Errno 2] No such file or directory: 'd:\\software\\miniconda3\\envs\\transformers\\lib\\site-packages\\datamapplot\\deckgl_template.html'`

Reproduction

No response

BERTopic Version

0.16.3

MaartenGr commented 1 month ago

I can only resolve the following issue by uninstalling both bertopic and datamapplot, and then reinstalling bertopic.

Just to be sure I understand this specific statement correctly. It works when you start from a fresh environment and installing BERTopic and DataMapPlot there?

LauwXiang commented 1 month ago

Hello, the issue has been resolved by downgrading DataMapPlot from version 0.4.0 to 0.3.0. Thank you for your reply.