簡體   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