Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create gensim word2vec model using pre trained word vectors?

I have created word vectors using a distributed word2vec algorithm. Now I have words and their corresponding vectors. How to build a gensim word2vec model using these words and vectors?

like image 787
Uma Maheswara Rao Pinninti Avatar asked Nov 29 '25 16:11

Uma Maheswara Rao Pinninti


1 Answers

I am not sure if you created word2vec model using gensim or some other tools but if understand your question correctly you want to just load the word2vec model using gensim. This is done in the following way:

import gensim
w2v_file = codecs.open(WORD2VEC_PATH, encoding='utf-8')
model = gensim.models.KeyedVectors.load_word2vec_format(w2v_file, binary=True)  # or binary=False if the model is not compressed

If, however, what you want to do is to train word2vec model from scratch (i.e. from raw text) using purely gensim here is a tutorial on how to train word2vec model using gensim.

like image 62
sophros Avatar answered Dec 02 '25 07:12

sophros