Search code examples
variablestensorflowkerasbackendtraining-data

Is it possible to create a trainable variable in keras like in tensorflow?


Good morning everyone; I'm trying to implement this model where the neural network's inputs are based on a trainable vocabulary matrix (each row in the matrix represents a word entry in the vocabulary). I'm using keras (tensorflow backend), I was wondering if it's possible to define a trainable variable (without adding a custom layer), such that this variable will be trained as well as the neural network? like a tensorflow variable. Could you please give a short example of how I can do it? Thanks in advance.


Solution

  • The neural network's inputs are based on a trainable vocabulary matrix (each row in the matrix represents a word entry in the vocabulary)

    This is the definition of a Word Embedding

    There is already an embedding layer in Keras, you don't have to reimplement it.

    You can find an easy example of how to use it here.