【问题标题】:Why doesn't gensim's Word2Vec recognize 'compute_loss' keyword?为什么 gensim 的 Word2Vec 不能识别“compute_loss”关键字?
【发布时间】:2017-07-31 17:04:15
【问题描述】:

根据 gensim.models.Word2Vec API reference,“compute_loss”是一个有效的关键字。但是,我收到一条错误消息,指出它是 unexpected keyword

更新

GitHub 上的 Word2Vec 类 does have 'compute_loss' 关键字,但我的本地库没有。 我看到 gensim 文档和库彼此偏离。 我发现conda repository中的win-64/gensim-2.2.0-np113py35_0.tar.bz2-文件不是最新的。

但是在使用 conda 卸载 gensim 后,pip install gensim 并没有改变任何东西,因为它仍然无法工作。

显然,GitHub 上的源代码和分布式库不同,但本教程似乎假设代码与 GitHub 上的代码相同。

/更新结束

我关注并下载了tutorial notebook on Word2Vec

在输入 [25] 中,“训练损失计算”标题后的第一个单元格中,Word2Vec 类的初始化程序出现错误。

输入:

# instantiating and training the Word2Vec model
model_with_loss = gensim.models.Word2Vec(sentences, min_count=1, 
compute_loss=True, hs=0, sg=1, seed=42)

# getting the training loss value
training_loss = model_with_loss.get_latest_training_loss()
print(training_loss)

输出:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-c2933abf4b08> in <module>()
      1 # instantiating and training the Word2Vec model
----> 2 model_with_loss = gensim.models.Word2Vec(sentences, min_count=1, compute_loss=True, hs=0, sg=1, seed=42)
      3 
      4 # getting the training loss value
      5 training_loss = model_with_loss.get_latest_training_loss()

TypeError: __init__() got an unexpected keyword argument 'compute_loss'

我通过 conda 安装了 gensim 2.2.0,并从 gensim 存储库中获得了一个新的克隆(使用教程笔记本)。我在 Windows 10 上使用 64 位 Python 3.5.3。(Anaconda)

我曾尝试寻找其他有相同遭遇的人,但没有成功。

您知道这是什么原因,以及如何解决这个问题吗?显然,GitHub 上的源代码和分布式库不同,但本教程似乎假设代码与 GitHub 上的代码相同。

我之前也在官方邮件列表中posted the question

【问题讨论】:

    标签: python gensim word2vec


    【解决方案1】:

    更新: compute_loss 于 7 月 25 日在 2.3.0 版中添加。 /更新

    问题中引用的笔记本位于 develop 分支上。 ma​​ster 分支有一个notebook,与最新发行版一致。

    compute_loss 参数在 this commit 中添加,6 月 19 日。last upload 到 PYPI 是 6 月 21 日,仅两天后。 (截至今日)。 compute_loss 不包含在分发中。 (v2.2.0 中的最后一次提交是this。)

    我认为解决方案是等待下一个版本的gensim,同时从存储库下载代码。

    但是,这可能会给 gensim FAST 版本的工作带来挑战,至少在 Windows 上是这样。见Using Gensim shows "Slow version of gensim.models.doc2vec being used"

    如何从 GitHub 安装 gensim 在他们的install documentation 中有说明。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-15
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-22
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多