gensim word2vec: Find number of words in vocabulary

前端 未结 2 386
鱼传尺愫
鱼传尺愫 2021-01-31 07:46

After training a word2vec model using python gensim, how do you find the number of words in the model\'s vocabulary?

2条回答
  •  北海茫月
    2021-01-31 08:49

    The vocabulary is in the vocab field of the Word2Vec model's wv property, as a dictionary, with the keys being each token (word). So it's just the usual Python for getting a dictionary's length:

    len(w2v_model.wv.vocab)
    

    (In older gensim versions before 0.13, vocab appeared directly on the model. So you would use w2v_model.vocab instead of w2v_model.wv.vocab.)

提交回复
热议问题