How to get dictionary vocabulary from gensim word2vec?

I am using the gensim word2vec package in python. I know how to get a dictionary from a trained model. But how to get a word for each word in a dictionary?

+6
source share
1 answer

Each word in the dictionary contains an associated dictionary object containing an index and a counter.

vocab_obj = w2v.vocab["word"] vocab_obj.count 

Result for google news w2v model: 2998437

So, in order to get a counter for each word, you will iterate over all the words and dictionary objects in the dictionary.

 for word, vocab_obj in w2v.vocab.items(): #Do something with vocab_obj.count 
+14
source

All Articles