简体   繁体   中英

Gensim getting started Error : No such file or directory: 'vectors.bin'

I am learning about Word2Vec and GloVe model in python so I am going through this getting started with GENSIM available here .

After I compiled these code step by step in 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)

I am getting this error:

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'

How do I rectify this. Where can I get the vector.bin file. Thanks for your help in advance.

The tutorial you link uses the name vectors.bin , as an example, when describing how you might load vectors created by the original Google-released word2vec.c toolkit. (That's the name used in that toolkit's documentation.)

Unless you have such a file and need to do something with it, you wouldn't need to load it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM