Skip to content

Instantly share code, notes, and snippets.

Last active April 4, 2017 08:09
What would you like to do?
CBOW word embedding in Keras
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
# 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