3
$\begingroup$

Is there a way I can access just the vocabulary list of pre-trained vectors for word2vec and GloVe? I do not need the entire n-dimensional embeddings.

$\endgroup$

2 Answers 2

6
$\begingroup$

In short: Yes, you can.

You need to first load the vectors using the Gensim module in Python.

# Load Google news vectors
word2vec_path = "path_to_the_vectors/GoogleNews-vectors-negative300.bin"
word2vec = gensim.models.KeyedVectors.load_word2vec_format(word2vec_path, binary=True)

# contains the list of all unique words in pre-trained word2vec vectors
w2v_vocabulary = word2vec.vocab
$\endgroup$
1
$\begingroup$

What you want can be done by pre-processing the word embedding file in the following way :

with open('glove.txt') as f:
    text = f.readlines()

word_list = [line.strip().split()[0] for line in text]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.