Building the word2vec model using gensim

Now that we have understood how the word2vec model works, let's see how to build the word2vec model using the gensim library. Gensim is one of the popular scientific software packages widely used for building vector space models. It can be installed via pip. So, we can just type the following command in the terminal to install the gensim library:

pip install -U gensim

Now that we have installed gensim, we will see how to build the word2vec model using that. You can download the dataset used in this section along with complete code with step by step explanation from GitHub at http://bit.ly/2Xjndj4.

First, we will import the necessary libraries:

import warnings
warnings.filterwarnings(action='ignore')

#data processing
import pandas as pd
import re
from nltk.corpus import stopwords
stopWords = stopwords.words('english')

#modelling
from gensim.models import Word2Vec
from gensim.models import Phrases
from gensim.models.phrases import Phraser
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset