Skip to content

Instantly share code, notes, and snippets.

@nokados
Created May 25, 2018 09:59
Show Gist options
  • Save nokados/b499ad1525eedb3a770756d24b66da0a to your computer and use it in GitHub Desktop.
Save nokados/b499ad1525eedb3a770756d24b66da0a to your computer and use it in GitHub Desktop.
Embedding Layer for Keras with weights from gensim Word2Vec (or FastText, why not?)
def word2vec_embedding_layer(embeddings_path='data/weights.npz', max_review_length=150):
weights = load_weights(embeddings_path)
layer = Embedding(input_dim=weights.shape[0],
output_dim=weights.shape[1],
input_length=max_review_length,
weights=[weights])
return layer
# How to make 'data/weights.npz'? What is load_weights()?
# See https://gist.github.com/nokados/d5cfec00bc194822f89dff556ff62b29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment