Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. from gensim import utils
  2.  
  3. def save2gensim(fname, word2vec_dict):
  4. vectors = list(word2vec_dict.values())
  5. vector_size = vectors[0].shape[0]
  6. total_vec = len(vectors)
  7. with utils.smart_open(fname, 'wb') as fout:
  8. fout.write(utils.to_utf8("%s %s\n" % (total_vec, vector_size)))
  9. # store in sorted order: most frequent words at the top
  10. for word, vector in word2vec_dict.items():
  11. fout.write(utils.to_utf8("%s %s\n" % (word, ' '.join(repr(val) for val in vector))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement