'AttributeError: 'KeyedVectors' object has no attribute 'get_keras_embedding'

I want to import "Word2Vec" from "Keyed Vectors". This is my code:

from gensim.models import KeyedVectors

wv = KeyedVectors.load_word2vec_format("german.model", binary = True)

from keras.models import Sequential

model = Sequential()
model.add(wv.get_keras_embedding())

However, I get the following error message:

AttributeError: 'KeyedVectors' object has no attribute 'get_keras_embedding'

I would be really happy if someone could help me



Solution 1:[1]

The utility function get_keras_embedding() no longer exists on KeyedVectors. You can copy its functionality yourself, in an external function, using the guidance on the Gensim wiki: https://github.com/RaRe-Technologies/gensim/wiki/Using-Gensim-Embeddings-with-Keras-and-Tensorflow

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gojomo