我使用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'])
错误消息实际上告诉我们使用对象本身,即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