The flow of the embedding model with Keras remains the same as TensorFlow.
- Create the network architecture in the Keras functional or sequential model
- Feed the true and false pairs of the target and context words to the network
- Look up the word vector for target and context words
- Perform a dot product of the word vectors to get the similarity score
- Pass the similarity score through a sigmoid layer to get the output as the true or false pair
Now let's implement these steps using the Keras functional API:
- Import the required libraries:
from keras.models import Model
from keras.layers.embeddings import Embedding
from keras.preprocessing import sequence
from keras.preprocessing.sequence import skipgrams
from keras.layers import Input, Dense, Reshape, Dot, merge
import keras
Reset graphs so that any after effects left from previous runs in Jupyter Notebook...