CBOW word embedding in Keras
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
modelWRD = Sequential() | |
# 1st layer is a dummy-permutation=identity to specify input shape | |
modelWRD.add( Permute((1,), input_shape=(n_words,)) ) | |
modelWRD.add( EMBEDDING ) | |
modelWRD.add( Lambda( | |
lambda x : K.sum(x,axis=1), # sum over words | |
output_shape=(embedding_dimension,)) | |
) | |
# Dense is a linear map followed by an activation | |
modelWRD.add( Dense(vocab_size, activation='softmax') ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment