Python Word2Vec不匹配函数抛出Numpy警告
我正在使用word2vec。当我使用doesnu match函数时,它会显示一个警告。有人能帮忙吗 venv/lib/python3.6/site packages/gensim/models/keyedvictors.py:876:FutureWarning:要堆栈的数组必须作为“序列”类型(如列表或元组)传递。从NumPy 1.16开始,不推荐对生成器等非序列可重用项的支持,这将在将来引发错误。 vectors=vstack(self.word\u vec(word,use\u norm=True)表示已用单词中的单词)。astype(REAL) 代码: vstack()应将列表作为参数 因此,更改以下代码以避开未来警告Python Word2Vec不匹配函数抛出Numpy警告,python,numpy,word2vec,Python,Numpy,Word2vec,我正在使用word2vec。当我使用doesnu match函数时,它会显示一个警告。有人能帮忙吗 venv/lib/python3.6/site packages/gensim/models/keyedvictors.py:876:FutureWarning:要堆栈的数组必须作为“序列”类型(如列表或元组)传递。从NumPy 1.16开始,不推荐对生成器等非序列可重用项的支持,这将在将来引发错误。 vectors=vstack(self.word\u vec(word,use\u norm=T
from
vectors = vstack(self.word_vec(word, use_norm=True) for word in used_words).astype(REAL)
to
vectors = vstack(list(self.word_vec(word, use_norm=True) for word in used_words)).astype(REAL)
下面是用于抑制FutureWarning的上下文管理器。希望他们能在gensim软件包中修复它,以免损坏
import warnings
with warnings.catch_warnings():
warnings.simplefilter(action='ignore', category=FutureWarning)
w2v_model.wv.doesnt_match(['the', 'and', 'or'])
# Output: 'or'
w2v_model.wv.doesnt_match(['the', 'and', 'or'])
# Output:
# C:\Installs\Python\lib\site-packages\gensim\models\keyedvectors.py:877:
# FutureWarning: arrays to stack must be passed as a "sequence" type such as list or
# tuple. Support for non-sequence iterables such as generators is deprecated as of NumPy
# 1.16 and will raise an error in the future.
# vectors = vstack(self.word_vec(word, use_norm=True) for word in used_words).astype(REAL)
# or
import warnings
with warnings.catch_warnings():
warnings.simplefilter(action='ignore', category=FutureWarning)
w2v_model.wv.doesnt_match(['the', 'and', 'or'])
# Output: 'or'
w2v_model.wv.doesnt_match(['the', 'and', 'or'])
# Output:
# C:\Installs\Python\lib\site-packages\gensim\models\keyedvectors.py:877:
# FutureWarning: arrays to stack must be passed as a "sequence" type such as list or
# tuple. Support for non-sequence iterables such as generators is deprecated as of NumPy
# 1.16 and will raise an error in the future.
# vectors = vstack(self.word_vec(word, use_norm=True) for word in used_words).astype(REAL)
# or