AttributeError:模块“gensim.utils”没有属性“smart_open”

ido*_*ehe 2 python gensim doc2vec databricks

我正在使用 Doc2vec 构建词汇表,但出现错误“AttributeError:模块‘gensim.utils’没有属性‘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())
Run Code Online (Sandbox Code Playgroud)

我分别运行了以上几行。第一行工作正常。第二个说: AttributeError: module 'gensim.utils' has no attribute 'smart_open'

son*_*nvx 5

我相信这是因为你安装了新的 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#migration-to-the-new-open-function

或:(2)pip install gensim==3.4.0

希望这可以帮助。