为什么 gensim 的 Word2Vec 不能识别 'compute_loss' 关键字?

Why doesn't gensim's Word2Vec recognize 'compute_loss' keyword?

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

更新:

Word2Vec class GitHub 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] 中,"Training Loss Computation" 标题后的第一个单元格中,我在 Word2Vec class' 初始值设定项中遇到错误。

输入:

# 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

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

问题中引用的笔记本在 develop 分支上。 master 分支有一个 notebook 与最新发行版一致。

this commit, June 19. The last upload to PYPI was June 21, only two days later. (As of today). The compute_loss is not included in the distribution. (Last commit in v2.2.0 is this中添加了compute_loss参数。)

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

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

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