gensim word2vec:查找词汇中的单词数 [英] gensim word2vec: Find number of words in vocabulary

查看:63
本文介绍了gensim word2vec:查找词汇中的单词数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用python gensim 训练word2vec模型后,如何找到模型词汇表中的单词?

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

推荐答案

词汇表在Word2Vec模型的 wv 属性的 vocab 字段中,作为字典,带有密钥是每个令牌(单词).因此,这只是获取字典长度的常用Python:

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)

(在0.13之前的旧gensim版本中, vocab 直接出现在模型上.因此,您可以使用 w2v_model.vocab 代替 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.)

这篇关于gensim word2vec:查找词汇中的单词数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆