【问题标题】:AttributeError: The vocab attribute was removed from KeyedVector in Gensim 4.0.0AttributeError:词汇属性已从 Gensim 4.0.0 中的 KeyedVector 中删除
【发布时间】:2022-04-23 13:13:22
【问题描述】:

AttributeError Traceback(最近一次调用最后一次) ~/Desktop/implimentaion/train.py 在 31 使用_w2v = 真 32 ---> 33 train_df, embeddings = make_w2v_embeddings(train_df, embedding_dim=embedding_dim, empty_w2v=not use_w2v) 34 35 # 拆分训练验证

~/Desktop/implimentaion/util.py in make_w2v_embeddings(df, embedding_dim, empty_w2v) 90 91 # 如果 word2vec 模型中缺少一个单词。 ---> 92 如果单词不在 word2vec.vocab 中: 93 如果单词不在 vocabs_not_w2v 中: 94 词汇_not_w2v_cnt += 1

~/opt/anaconda3/lib/python3.8/site-packages/gensim/models/keyedvectors.py in vocab(self) 第643章 第644章 --> 645 引发属性错误( 646 “词汇属性已从 Gensim 4.0.0 中的 KeyedVector 中删除。\n” 647 “使用 KeyedVector 的 .key_to_index 字典、.index_to_key 列表和方法”

AttributeError:词汇属性已从 Gensim 4.0.0 中的 KeyedVector 中删除。 改用 KeyedVector 的 .key_to_index 字典、.index_to_key 列表和方法 .get_vecattr(key, attr) 和 .set_vecattr(key, attr, new_val)。 见https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4

【问题讨论】:

标签: python anaconda word2vec


【解决方案1】:

正如错误所暗示的,“请参阅https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4"

该页面解释了如何调整旧代码以使用 gensim-4.0.0 和更高版本的 Gensim。

(您需要更改您的~/Desktop/implimentaion/util.py 文件以不再使用.vocab 属性来测试一个单词是否在模型中。错误消息中显示的特定情况的修复可能就像更改一样简单if word not in word2vec.vocabif word not in word2vec。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    相关资源
    最近更新 更多