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$

3 Answers 3

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$ Answer is outdated. list(model.wv.key_to_index.keys()) $\endgroup$ Commented May 10 at 21:38
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$
0
$\begingroup$

With gensim's API flux, right now it seems to work like so:

model.wv.key_to_index.keys()

$\endgroup$
1
  • $\begingroup$ Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. $\endgroup$
    – Community Bot
    Commented May 13 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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