Training word2vec embeddings

Importing the model is simple, simply use the following command. By now, you should have an intuitive feel of how the Gensim model's API is structured:

from gensim.models.word2vec import Word2Vec

Here, we are using an identical configuration for the word2vec model as we did for fastText. This helps to reduce bias in the comparison.

You are encouraged to compare the best fastText model to the best word2vec model with the following:

word2vec_ted_model = Word2Vec(sentences=sentences_ted, size=100, window=5, min_count=5, workers=-1, sg=1)

Right, let's now look at the words most similar to india, as follows:

word2vec_ted_model.wv.most_similar("india")[('cent', 0.38214215636253357), ('dichotomy', 0.37258434295654297), ...

Get Natural Language Processing with Python Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.