[Python] AttributeError: The vocab attribute was removed from KeyedVector in Gensim 4.0.0

Discussão em 'Python' iniciado por Stack, Julho 5, 2025.

  1. Stack

    Stack Membro Participativo

    AttributeError Traceback (most recent call last)
    ~/Desktop/implementaion/train.py in <module>
    31 use_w2v = True
    32
    ---> 33 train_df, embeddings = make_w2v_embeddings(train_df, embedding_dim=embedding_dim, empty_w2v=not use_w2v)
    34
    35 # Split to train validation

    ~/Desktop/implementaion/util.py in make_w2v_embeddings(df, embedding_dim, empty_w2v)
    90
    91 # If a word is missing from word2vec model.
    ---> 92 if word not in word2vec.vocab:
    93 if word not in vocabs_not_w2v:
    94 vocabs_not_w2v_cnt += 1

    ~/opt/anaconda3/lib/python3.8/site-packages/gensim/models/keyedvectors.py in vocab(self)
    643 @property
    644 def vocab(self):
    --> 645 raise AttributeError(
    646 "The vocab attribute was removed from KeyedVector in Gensim 4.0.0.\n"
    647 "Use KeyedVector's .key_to_index dict, .index_to_key list, and methods "

    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.
    See https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4

    Continue reading...

Compartilhe esta Página