繁体   English   中英

词汇表中的单词数 gensim word2vec

[英]Number of words in vocabulary gensim word2vec

如何为 gensim Word2Vec 打印模型词汇表中的单词数?

import gensim
model = gensim.models.KeyedVectors.load_word2vec_format("GoogleNews-vectors-negative300.bin", binary=True)

我努力了

len(model.wv.vocab)

但我得到这个错误

Traceback (most recent call last):
  File ".\word2vec.py", line 4, in <module>
    len(model.wv.vocab)
AttributeError: 'KeyedVectors' object has no attribute 'wv'

和这个

len(model.vocab)

它给出了这个错误

Traceback (most recent call last):
  File ".\word2vec.py", line 4, in <module>
    len(model.vocab)
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\gensim\models\keyedvectors.py", line 645, in vocab
    raise AttributeError(
AttributeError: The vocab attribute was removed from KeyedVector in Gensim 4.0.0.
Use KeyedVector's .key_to_index dict, .index_to_key list, and methods .get_vecattr(key, attr) and .set_vecattr(key, attr, new_val) instead.

这里找到更新版本

len(model.vectors)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM