January 2018
Beginner to intermediate
284 pages
8h 35m
English
In this section, we will briefly explain how to use pre-trained vectors. Before reading this section, download Word2Vec pre-trained vectors from https://drive.google.com/file/d/0B7XkCwpI5KDYNlNUTTlSS21pQmM/edit, and load the model:
from gensim.models import KeyedVectors# Load pre-trained modelmodel = KeyedVectors.load_word2vec_format( './GoogleNews-vectors-negative300.bin', binary=True)
Then, we find the top 5 words that are similar to woman and king, but dissimilar to man:
model.wv.most_similar( positive=['woman', 'king'], negative=['man'], topn=5)
We see the following:
[(u'queen', 0.7118192911148071), (u'monarch', 0.6189674139022827), (u'princess', 0.5902431607246399), (u'crown_prince', 0.5499460697174072), ...
Read now
Unlock full access