Created
March 13, 2018 18:34
-
-
Save dipanjanS/dbff31351127c893a4579c9be11e113d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.layers import Merge | |
from keras.layers.core import Dense, Reshape | |
from keras.layers.embeddings import Embedding | |
from keras.models import Sequential | |
# build skip-gram architecture | |
word_model = Sequential() | |
word_model.add(Embedding(vocab_size, embed_size, | |
embeddings_initializer="glorot_uniform", | |
input_length=1)) | |
word_model.add(Reshape((embed_size, ))) | |
context_model = Sequential() | |
context_model.add(Embedding(vocab_size, embed_size, | |
embeddings_initializer="glorot_uniform", | |
input_length=1)) | |
context_model.add(Reshape((embed_size,))) | |
model = Sequential() | |
model.add(Merge([word_model, context_model], mode="dot")) | |
model.add(Dense(1, kernel_initializer="glorot_uniform", activation="sigmoid")) | |
model.compile(loss="mean_squared_error", optimizer="rmsprop") | |
# view model summary | |
print(model.summary()) | |
# visualize model structure | |
from IPython.display import SVG | |
from keras.utils.vis_utils import model_to_dot | |
SVG(model_to_dot(model, show_shapes=True, show_layer_names=False, | |
rankdir='TB').create(prog='dot', format='svg')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you