Python Word2Vec uses the trained model to generate word vectors

 

#The text file must be in utf-8 without bom format 
from gensim.models.deprecated.word2vec import Word2Vec

model = Word2Vec.load(
     ' ./model/Word60.model ' )   # 3 files together: Word60.model Word60.model.syn0.npy Word60.model.syn1neg.npy 
print ( " read model successful " )

word_list = [ ' had ' ,
             ' non-existent word ' ,
             ' of ' ,
             ' me ' ,
             ' you ' ,
             ' he ' ,
             ' one ' ,
             ' 1 ' ,
             ' done ' ,
             ' eat ' ,
             ' apple ' ,
             'banana ',
             ' Vocabulary ' ,
             ' Physics ' ,
             ' Earth ' ,
             ' Black Death ' ,
             ' Plague ' ,
             '' , ]

for word in word_list:
    if word in model.index2word:
        vec = model[word]
         print (word,vec)
     else :
         print (word + ' \t\t\t - not in vocabulary ' + ' \n\n ' )

The model file is as follows:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324657316&siteId=291194637