How do we use pre-trained embeddings?

We just downloaded these.

The file formats used by word2vec and GloVe are slightly different from each other. We'd like a consistent API to look up any word embedding, and we can do this by converting the embedding format. Note that there are minor differences in how word embedding is stored.

This format conversion can be done using Gensim's API called glove2word2vec. We will use this to convert our GloVe embedding information to the word2vec format.

So, let's get the imports out of the way and begin by setting up filenames, as follows:

from gensim.scripts.glove2word2vec import glove2word2vec
glove_input_file = 'data/glove.6B.300d.txt'
word2vec_output_file = 'data/glove.6B.300d.word2vec.txt'

We don't ...

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.