Gensim v3.6.0 Word2Vec DeprecationWarning:调用不推荐使用的`wv`(属性将在4.0.0中删除,改为使用self)

问题描述 投票:0回答:1

我使用Gensim 3.6.0加载了预先训练的Word2Vec,并且在调用model.wv时显示以下错误。

/anaconda/envs/python36/lib/python3.6/site-packages/ipykernel_launcher.py:1: DeprecationWarning: Call to deprecated `wv` (Attribute will be removed in 4.0.0, use self instead).
  """Entry point for launching an IPython kernel.

这是我的代码示例

import gensim
model = gensim.models.KeyedVectors.load_word2vec_format('/path/to/file/my-vec-300d-v2', binary=False)
print(model.wv['hello'].shape)
print(model.wv['hello']) 
python-3.x gensim word2vec
1个回答
0
投票

错误消息实际上告诉我们使用对象本身,即model而不是model.wv

print(model['hello'].shape) # instead of model.wv['hello'].shape which is deprecated
print(model['hello']) # instead of model.wv['hello'] which is deprecated
© www.soinside.com 2019 - 2024. All rights reserved.