首页 > 解决方案 > TypeError: __init__() 在 Node2Vec 中得到了一个意外的关键字参数 'size'

问题描述

我正在嵌入一个带有 Node2Vec 库的图,但我得到这个错误: TypeError: init () got an unexpected keyword argument 'size' to the following code block -

model = node2vec.fit(window=10, min_count=1, batch_words=4)

知道为什么会这样吗?

标签: python-3.xgraphgensimword2vec

解决方案


我遇到了完全相同的问题,找不到解决方案。从评论中我尝试重新启动运行时但没有任何改变。

我的代码是:

node2vec = Node2Vec(G) 
model = node2vec.fit()

和我得到的错误: TypeError: __init__() got an unexpected keyword argument 'size' 它直接指向.fit()我用networkX图尝试过的线,并且用stellargraph(使用EdgeSplitter)它们两者都有相同的错误。我也尝试过设置维度:

node2vec = Node2Vec(G, dimensions=24) 

但它也没有奏效。我不知道我还能尝试什么...

编辑:以防万一,完整的错误消息是:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-38-3ccb4a8a103e> in <module>
      4 
      5 node2vec = Node2Vec(G, dimensions=24)
----> 6 model = node2vec.fit()
      7 edges_embs = HadamardEmbedder(keyed_vectors=model.wv)
      8 train_embeddings = [edges_embs[str(x[0]),str(x[1])] for x in samples_train]

D:\environnements\stel2\lib\site-packages\node2vec\node2vec.py in fit(self, **skip_gram_params)
    172         :type skip_gram_params: dict
    173         :return: A gensim word2vec model
--> 174         """
    175 
    176         if 'workers' not in skip_gram_params:

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

解决方案

解决方案来了:您必须将 gensim 从(在我的情况下)降级4.1.23.8.3. 我正在使用 node2vec0.4.3 这个问题应该从 4.2 开始修复,但由于某种原因我仍然有它。 https://githubmemory.com/repo/eliorc/node2vec/issues/60 我从adamdingliang的建议中得到了解决方案


推荐阅读