Gensim入门错误:没有这样的文件或目录:'vectors.bin'

时间:2017-01-17 05:18:54

标签: python error-handling gensim word2vec

我正在学习python中的 Word2Vec GloVe 模型,所以我要开始使用 GENSIM 可用here

在Idle3中逐步编译这些代码之后:

from gensim.models import word2vec
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
sentences = word2vec.Text8Corpus('text8')
sentences = word2vec.Text8Corpus('~/Desktop/text8')
model = word2vec.Word2Vec(sentences, size=200)
model.most_similar(positive=['woman', 'king'], negative=['man'], topn=1)
model.most_similar(positive=['woman', 'king'], negative=['man'], topn=2)
model.most_similar(['man'])
model.save('text8.model')
model.save_word2vec_format('text.model.bin', binary=True)
model1 = word2vec.Word2Vec.load_word2vec_format('text.model.bin', binary=True)
model1.most_similar(['girl', 'father'], ['boy'], topn=3)
more_examples = ["he is she", "big bigger bad", "going went being"]
for example in more_examples:
    a, b, x = example.split()
    predicted = model.most_similar([x, b], [a])[0][0]
    print ("'%s' is to '%s' as '%s' is to '%s'" % (a, b, x, predicted))
model_org = word2vec.Word2Vec.load_word2vec_format('vectors.bin', binary=True)

我收到此错误:

2017-01-17 10:34:26,054 : INFO : loading projection weights from vectors.bin
Traceback (most recent call last):
  File "<pyshell#16>", line 1, in <module>
    model_org = word2vec.Word2Vec.load_word2vec_format('vectors.bin', binary=True)
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/word2vec.py", line 1172, in load_word2vec_format
    with utils.smart_open(fname) as fin:
  File "/usr/local/lib/python3.5/dist-packages/smart_open-1.3.5-py3.5.egg/smart_open/smart_open_lib.py", line 127, in smart_open
    return file_smart_open(parsed_uri.uri_path, mode)
  File "/usr/local/lib/python3.5/dist-packages/smart_open-1.3.5-py3.5.egg/smart_open/smart_open_lib.py", line 558, in file_smart_open
    return open(fname, mode)
FileNotFoundError: [Errno 2] No such file or directory: 'vectors.bin'

我该如何纠正这个问题。我在哪里可以获得vector.bin文件。 感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在描述如何加载由原始Google发布的word2vec.c工具包创建的向量时,tutorial you link使用名称vectors.bin作为示例。 (这是该工具包文档中使用的名称。)

除非你有这样的文件并且需要对它做一些事情,否则你不需要加载它。