BERTopic datamap可视化不起作用,

sauutmhj  于 2个月前  发布在  其他
关注(0)|答案(6)|浏览(34)

除了这个之外的其他可视化作品。这表明BERTopic没有这个方法。

gr8qqesn

gr8qqesn1#

@Hansyvea 你能提供你的错误和示例代码吗?
你的 #1955 也没有任何细节。

7fhtutme

7fhtutme2#

PS:上周我在Colab上遇到了类似的错误。
我猜你可能指的是这个错误或者类似的
# "Data map plotting is unavailable unless datamapplot is installed."
# datamapplot not installed
对我有效的方法是:确保安装并加载datamapplot

## Install DataMapPlots: Below for Colab or if working inline within Notebook
!pip install datamapplot

## load library
    import datamapplot

你应该可以执行
topic_model.visualize_document_datamap(docs, reduced_embeddings=reduced_embeddings)
## where reduced_embedding is already derived from your umap fit_transformed.
如果BERTopic datamap不起作用,你可以尝试直接使用datamap。
就我的情况而言,我直接调用了 create_plot :
PS:我还尝试了 datamapplot.create_interactive_plot() ,成功了。

datamapplot.create_plot(
    reduced_embeddings05,
    docs_info.Name,
...
...)

## where docs_info.Name or ocs_info['Name'] comes from topic_model_.get_document_info
u7up0aaq

u7up0aaq3#

请确保您安装了BERTopic v0.16.1(或发布时更高版本),因为它首先在v0.16.1中得到支持。如果BERTopic建议它没有这个功能,那么要么是之前提到的情况,要么就是安装最新版本。

yqkkidmi

yqkkidmi4#

我也遇到了datamapplot无法正常工作的问题。以下是我的代码:

import datamapplot
print(bertopic.__version__)
0.16.1

topic_model.visualize_document_datamap(docs, embeddings=embeddings, title='', width=1200, height=1200,)

错误输出:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/work/infomedia/sim_analysis.ipynb Cell 410 line 1
----> <a href='vscode-notebook-cell://app-5046147-0.cloud.sdu.dk/work/infomedia/sim_analysis.ipynb#Z1405sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a> topic_model.visualize_document_datamap(docs, embeddings=embeddings, title='', width=1200, height=1200,)

File [~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2431](https://vscode-remote+app-002d5046147-002d0-002ecloud-002esdu-002edk.vscode-resource.vscode-cdn.net/work/infomedia/~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2431), in BERTopic.visualize_document_datamap(self, docs, topics, embeddings, reduced_embeddings, custom_labels, title, sub_title, width, height, **datamap_kwds)
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2429'>2429</a> check_is_fitted(self)
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2430'>2430</a> check_documents_type(docs)
-> <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2431'>2431</a> return plotting.visualize_document_datamap(self,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2432'>2432</a>                                            docs,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2433'>2433</a>                                            topics,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2434'>2434</a>                                            embeddings,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2435'>2435</a>                                            reduced_embeddings,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2436'>2436</a>                                            custom_labels,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2437'>2437</a>                                            title,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2438'>2438</a>                                            sub_title,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2439'>2439</a>                                            width,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2440'>2440</a>                                            height,
   <a href='~/.local/lib/python3.10/site-packages/bertopic/_bertopic.py:2441'>2441</a>                                            **datamap_kwds)

File [~/.local/lib/python3.10/site-packages/bertopic/plotting/_datamap.py:142](https://vscode-remote+app-002d5046147-002d0-002ecloud-002esdu-002edk.vscode-resource.vscode-cdn.net/work/infomedia/~/.local/lib/python3.10/site-packages/bertopic/plotting/_datamap.py:142), in visualize_document_datamap(topic_model, docs, topics, embeddings, reduced_embeddings, custom_labels, title, sub_title, width, height, **datamap_kwds)
    <a href='~/.local/lib/python3.10/site-packages/bertopic/plotting/_datamap.py:139'>139</a> # Map in topic names and plot
    <a href='~/.local/lib/python3.10/site-packages/bertopic/plotting/_datamap.py:140'>140</a> named_topic_per_doc = pd.Series(topic_per_doc).map(topic_name_mapping).values
--> <a href='~/.local/lib/python3.10/site-packages/bertopic/plotting/_datamap.py:142'>142</a> figure, axes = datamapplot.create_plot(
    <a href='~/.local/lib/python3.10/site-packages/bertopic/plotting/_datamap.py:143'>143</a>     embeddings_2d,
...
    <a href='~/.local/lib/python3.10/site-packages/bertopic/plotting/_datamap.py:149'>149</a>     **datamap_kwds,
    <a href='~/.local/lib/python3.10/site-packages/bertopic/plotting/_datamap.py:150'>150</a> )
    <a href='~/.local/lib/python3.10/site-packages/bertopic/plotting/_datamap.py:152'>152</a> return figure

NameError: name 'datamapplot' is not defined
unhi4e5o

unhi4e5o5#

假设 datamapplot 已经正确安装,您可能需要重启笔记本并再次尝试。不确定,但可能是在安装 datamapplot 之前,datamapplot 的 try/except 子句就已经完成了,但这只是我的猜测,因为我不了解确切的过程。

ruarlubt

ruarlubt6#

假设 datamapplot 已经正确安装,您可能需要重启笔记本并再次尝试。不确定,但可能是在安装 datamapplot 之前,datamapplot 的 try/except 子句就已经完成了,但这只是我的猜测,因为我不了解确切的过程。
您完全正确,已解决问题。老式的重启。谢谢!

相关问题