2017-07-24 116 views
3

根据gensim.models.Word2VecAPI reference,“compute_loss”是一个有效的关键字。但是,我收到一个错误,说这是一个unexpected keyword为什么gensim的Word2Vec不能识别'compute_loss'关键字?

UPDATE

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

但是,使用conda卸载gensim后,pip install gensim没有改变任何东西,因为它仍然不起作用。

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

/END我也跟着下载的tutorial notebook on Word2Vec

在输入[25]中,“Training Loss Computation”标题后的第一个单元格中,我在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' 

我必须通过畅达安装gensim 2.2.0,并有从gensim库(与教程笔记本电脑)的新新克隆。我在Windows 10上使用64位Python 3.5.3。(Anaconda)

我试图寻找其他人遇到同样的遭遇,但我没有成功。

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

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

回答

2

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

问题中引用的笔记本是在开发分支。 主人分支有一个notebook,这是符合最新的分配。

compute_loss参数被添加在this commit,6月19日.PYPI的last upload仅在两天后的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中有解释。

相关问题