簡體   English   中英

AttributeError: 模塊“gensim.utils”沒有屬性“smart_open”

[英]AttributeError: module 'gensim.utils' has no attribute 'smart_open'

我正在使用 Doc2vec 構建詞匯表,但出現錯誤“AttributeError: module 'gensim.utils' has no attribute 'smart_open'”。 我該如何解決這個問題?

這是針對 Databricks 平台上的筆記本,在 Python 3 中運行。過去,我曾嘗試在本地 Jupyter Notebook 上運行代碼,但發生了同樣的錯誤。

我還搜索了https://radimrehurek.com/gensim/models/doc2vec.html,但找不到與 smart_open 相關的任何內容。

model = Doc2Vec(window=5, min_count=1, size=50, sample=1e-5, negative=5, workers=1)

model.build_vocab(sentences.to_array())

我分別運行了以上幾行。 第一行工作正常。 第二個說:AttributeError: module 'gensim.utils' has no attribute 'smart_open'

我相信這是因為您安裝了新的gensim版本,然后您會收到此錯誤。 您可以:

(1) 按照以下建議更新調用: /python3.7/site-packages/smart_open/smart_open_lib.py:398: UserWarning: 此函數已棄用,請改用 smart_open.open。 有關詳細信息,請參閱遷移說明: https : //github.com/RaRe-Technologies/smart_open/blob/master/README.rst#migrating-to-the-new-open-function

或:(2) pip install gensim==3.4.0

希望這可以幫助。

我嘗試了上述答案中給出的第一種方法,不幸的是它不適用於我的情況。 通過查看文件“utils.py”,我發現關於 smart_open 的聲明是“from smart_open import open”。 因此,我嘗試改用“utils.open()”,這正好解決了我的問題^-^

順便說一句,我的gensim版本是3.8.3。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM