The Keras embedding layer allows us to learn a vector space representation of an input word, like we did in word2vec, as we train our model. Using the functional API, the Keras embedding layer is always the second layer in the network, coming after the input layer.
The embedding layer needs the following three arguments:
- input_dim: The size of the vocabulary of the corpus.
- output_dim: The size of the vector space we want to learn. This would correspond to the number of neurons in word2vec hidden layer.
- input_length: The number of words in the text we're going to use in each observation. In the examples that follow, we will use a fixed size based on the longest text we need to send and we will pad smaller documents with 0s.
An embedding layer will output a 2D matrix for each input document that contains one vector for each word in the sequence specified...