加载word2vec模型时出错

时间:2017-12-26 12:20:36

标签: word2vec gensim

我正在使用以下函数加载我的word2vec模型。

def __init__(self, filename):
        print filename
        try:
            self.model = gensim.models.Word2Vec.load(filename)
        except cPickle.UnpicklingError:
            load = gensim.models.Word2Vec.load_word2vec_format
            self.model = load(filename, binary=True)

但是,当我尝试这样做时,我收到以下错误。

Traceback (most recent call last):
  File "./explore", line 70, in <module>
    api_controller.model = Model(sys.argv[1])
  File "/home/volka/Documents/projects/word2vec-explorer/explorer.py", line 77, in __init__
    self.model = gensim.models.Word2Vec.load(filename)
  File "/usr/local/lib/python2.7/dist-packages/gensim/models/word2vec.py", line 1458, in load
    model = super(Word2Vec, cls).load(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/gensim/utils.py", line 256, in load
    obj = unpickle(fname)
  File "/usr/local/lib/python2.7/dist-packages/gensim/utils.py", line 920, in unpickle
    return _pickle.loads(f.read())
AttributeError: 'module' object has no attribute 'call_on_class_only'

我在两个版本中使用的genism版本是0.12.3。

请让我知道我错在哪里?

这就是我尝试删除call_on_class_only的方法。

model = word2vec.Word2Vec(text, sg=0, negative=5, hs=0)
model.save("test_project")

#load, delete and save
model_1 = word2vec.Word2Vec.load("test_project")
del model_1.call_on_class_only
model.save(model_name_2)

它给了我以下错误:AttributeError: call_on_class_only

请帮帮我。

0 个答案:

没有答案