Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Gensim“最相似”中的弃用警告?_Python_Python 3.x_Gensim_Word2vec - Fatal编程技术网

Python Gensim“最相似”中的弃用警告?

Python Gensim“最相似”中的弃用警告?,python,python-3.x,gensim,word2vec,Python,Python 3.x,Gensim,Word2vec,在Python3.7中实现Word2Vec时,我遇到了一个与折旧相关的意外情况。我的问题是,word2vec gensim python中关于“最相似”的贬值警告到底是什么 目前,我得到以下问题 弃用警告:调用弃用的最相似的方法(方法将在4.0.0中删除,改用self.wv.most\u-similable()。 模型。最相似的(“哈姆雷特”) FutureWarning:不推荐将issubdtype的第二个参数从int转换为np.SignedIntegrater。将来,它将被视为np.int3

在Python3.7中实现Word2Vec时,我遇到了一个与折旧相关的意外情况。我的问题是,word2vec gensim python中关于“最相似”的贬值警告到底是什么

目前,我得到以下问题

弃用警告:调用弃用的
最相似的方法(方法将在4.0.0中删除,改用self.wv.most\u-similable()。
模型。最相似的(“哈姆雷特”)
FutureWarning:不推荐将issubdtype的第二个参数从
int
转换为
np.SignedIntegrater
。将来,它将被视为
np.int32==np.dtype(int.type)
。 如果np.issubdtype(vec.dtype,np.int):

请帮助遏制这个问题?感谢您的帮助

我试过的代码如下

import re
from gensim.models import Word2Vec
from nltk.corpus import gutenberg

sentences = list(gutenberg.sents('shakespeare-hamlet.txt'))   
print('Type of corpus: ', type(sentences))
print('Length of corpus: ', len(sentences))

for i in range(len(sentences)):
    sentences[i] = [word.lower() for word in sentences[i] if re.match('^[a-zA-Z]+', word)]
print(sentences[0])    # title, author, and year
print(sentences[1])
print(sentences[10])
model = Word2Vec(sentences=sentences, size = 100, sg = 1, window = 3, min_count = 1, iter = 10, workers = 4)
model.init_sims(replace = True)
model.save('word2vec_model')
model = Word2Vec.load('word2vec_model')
model.most_similar('hamlet')

弃用警告是一种警告,用于指示对Python未来版本中可能存在或可能不存在的内容的使用,这些内容通常会被其他内容取代。(说出它们是什么)

错误似乎起源于Word2Vec内部,而不是您的代码。删除这些错误需要进入该库并更改其代码

试着按照它告诉你的去做

将您的
model.most_-simulate('hamlet')
更改为
model.wv.most_-simulate('hamlet')


我不熟悉这个软件包,所以请调整它的使用方式

因此,Gensim在这里告诉您,最终您将无法在Word2Vec模型上直接使用最类似的方法。相反,您需要在
model.wv
对象上调用它,这是训练模型时存储的关键向量

这是一个警告,它将变得过时和不起作用

通常情况下,对于一些版本,有些东西是不推荐的,因为在删除它们之前,使用它们的人有足够的时间移动到新方法

他们把最相似的
搬到了

因此,
大多数simliar()
应该看起来像:

model.wv.most_similar('hamlet')

希望这有帮助

编辑:使用
wv.most_-simple()


更新到4.0.0版本后,函数model.most_similable()将被删除。因此,您可以将函数修改为model.wv.most_similor()。函数model.similarity()也是如此。您必须将其更改为model.wv.similarity()

谢谢你的回复。怎么做?我编辑了它。我复制粘贴错了。它应该像
model.wv一样工作。最相似的('hamlet')
现在,它抛出以下错误,“utureWarning:issubdtype的第二个参数从
int
转换为
np.signedinteger
已弃用。将来,它将被视为
np.int32==np.dtype(int.type
。如果np.issubdtype(vec.dtype,np.int):”根据这个签名,看起来你不能简单地传递它
'hamlet'
试试传递,
positive='hamlet'
谢谢你的建议。但是,我也尝试了model.wv.most_类似,但它显示了以下消息,“将issubdtype的第二个参数从
int
转换为
np.signedinteger
已被弃用”。这听起来像是
numpy
Gensim
使用的其他依赖项发出的警告。他们需要改变这一点。我要升级numpy吗?不,因为它是
Gensim
中的代码,或者使用不推荐的转换方法的某些依赖项。谢谢Madhan。我试过这个模型。wv。最相似的(“哈姆雷特”)。但是,它显示了以下错误,“utureWarning:issubdtype的第二个参数从
int
转换为
np.signedinteger
已被弃用。将来,它将被视为
np.int32==np.dtype(int.type
。如果np.issubdtype(vec.dtype,np.int):”是的。它来自gensim使用的
numpy
依赖项。Genism正在更新版本ref:中修复它。您可以尝试将numpy降级到1.13:[ref](),谢谢您的及时回复。这很重要。如何将numpy降级到1.13?不用担心:)
pip卸载numpy
。然后
pip安装numpy==1.13
pip3对吗?这是因为我使用的是3.7版python。
import re
from gensim.models import Word2Vec
from nltk.corpus import gutenberg

sentences = list(gutenberg.sents('shakespeare-hamlet.txt'))   
print('Type of corpus: ', type(sentences))
print('Length of corpus: ', len(sentences))

for i in range(len(sentences)):
    sentences[i] = [word.lower() for word in sentences[i] if re.match('^[a-zA-Z]+', word)]
print(sentences[0])    # title, author, and year
print(sentences[1])
print(sentences[10])
model = Word2Vec(sentences=sentences, size = 100, sg = 1, window = 3, min_count = 1, iter = 10, workers = 4)
model.init_sims(replace = True)
model.save('word2vec_model')
model = Word2Vec.load('word2vec_model')
similarities = model.wv.most_similar('hamlet')
for word , score in similarities:
    print(word , score)