How to get word embeddings back from Keras?

Say you create your own custom word embeddings in the process of some arbitrary task, say text classification. How do you get a dictionary like structure of {word: vector} back from Keras?

embeddings_layer.get_weights() gives you the raw embeddings...but it's unclear which word corresponds to what vector element.

1 answer

  • answered 2021-02-23 05:47 Andrey

    This dictionary is not a part of keras model. It should be kept separately as a normal python dictionary. It should be in your code - you use it to convert text to integer indices (to feed them to Embedding layer).