AttributeError:'Word2Vec'对象没有属性'endswith'

时间:2019-12-14 07:28:08

标签: python machine-learning nlp artificial-intelligence word-embedding

当我运行包含以下代码的.py文件时

if not os.path.exists('model_out'):
    model1 = gensim.models.Word2Vec(l, min_count = 1, size = 100, window = 5)
    model1.save('model_out')
model1.load('model_out')
model11 = gensim.models.keyedvectors.KeyedVectors.load(model1)
max_size = len(model.wv.vocab)-1

产生以下错误

  

回溯(最近一次通话):文件“ assignment.py”,第35行,在          model11 = gensim.models.keyedvectors.KeyedVectors.load(model1)文件   “ /Users/harshpanwar/Desktop/Enthire_assignment/myenv/lib/python3.6/site-packages/gensim/models/keyedvectors.py”,   1540行,在负载中       模型=超级(WordEmbeddingsKeyedVectors,cls).load(fname_or_handle,** kwargs)文件   “ /Users/harshpanwar/Desktop/Enthire_assignment/myenv/lib/python3.6/site-packages/gensim/models/keyedvectors.py”,   线228,在负载中       返回super(BaseKeyedVectors,cls).load(fname_or_handle,** kwargs)文件“ /Users/harshpanwar/Desktop/Enthire_assignment/myenv/lib/python3.6/site-packages/gensim/utils.py”,   负载中的第424行       压缩,子名称= SaveLoad._adapt_by_suffix(fname)文件“ /Users/harshpanwar/Desktop/Enthire_assignment/myenv/lib/python3.6/site-packages/gensim/utils.py”,   _adapt_by_suffix中的第513行       如果fname.endswith('。gz')或fname.endswith('。bz2')否则为False,则后缀=(True,'npz')否则(False,'npy')AttributeError:'Word2Vec'   对象没有属性“ endswith”

1 个答案:

答案 0 :(得分:2)

我认为某些功能可能已被弃用。试试

from gensim import models
w = models.KeyedVectors.load_word2vec_format('model', binary=True)

from gensim import models
w = models.Word2Vec.load_word2vec_format('model', binary=True)