【问题标题】:I want to import Dictionary but it has problem [closed]我想导入字典,但它有问题[关闭]
【发布时间】:2020-07-24 19:28:18
【问题描述】:

我正在尝试在 python 文件中导入字典。我的代码如下:

from gensim.corpora
import Dictionary
dictionary = corpora.Dictionary([token_list])
dictionary.token2id 

这不能正常工作,我收到以下错误:

NameError Traceback (most recent call last)
<ipython-input-75-3a3520a7e6ae> in <module>
----> 1 dictionary = corpora.Dictionary([token_list])
     2 dictionary.token2id

NameError: name 'corpora' is not defined

我已经安装了这个库。我怎么解决这个问题? 提前致谢。

【问题讨论】:

    标签: python python-3.x dictionary python-3.6 python-3.5


    【解决方案1】:

    您尚未定义或导入名为 corpora 的 anzthing。你所做的是从gensim.corpora 导入Dictionary。通过使用

    from gensim.corpora import Dictionary
    

    你可以像这样使用Dictionary

    from gensim.corpora import Dictionary
    dictionary = Dictionary([token_list])
    dictionary.token2id 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-06
      • 2015-07-21
      • 1970-01-01
      • 2015-11-29
      相关资源
      最近更新 更多