当我运行包含以下代码的.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')则为compress,后缀=(True,'npz')else(False,'npy')AttributeError:'Word2Vec'
  对象没有属性“ endswith”

最佳答案

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

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)

关于python - AttributeError:'Word2Vec'对象没有属性'endswith',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59333165/

10-12 23:56