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.
3 Answers
$\begingroup$
$\endgroup$
1
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
-
$\begingroup$ Answer is outdated.
list(model.wv.key_to_index.keys())
$\endgroup$ Commented May 10 at 21:38
$\begingroup$
$\endgroup$
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]
$\begingroup$
$\endgroup$
1
With gensim's API flux, right now it seems to work like so:
model.wv.key_to_index.keys()
-
$\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 BotCommented May 13 at 4:30