Skip to content

Commit

Permalink
Set trainable flag in get_embedding_layer. Fix 1557 (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsef123 authored and menshikh-iv committed Sep 1, 2017
1 parent 9caf055 commit 3d2227d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gensim/models/keyedvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,5 +832,8 @@ def get_embedding_layer(self, train_embeddings=False):
if not KERAS_INSTALLED:
raise ImportError("Please install Keras to use this function")
weights = self.syn0
layer = Embedding(input_dim=weights.shape[0], output_dim=weights.shape[1], weights=[weights]) # No extra mem usage here as `Embedding` layer doesn't create any new matrix for weights

# set `trainable` as `False` to use the pretrained word embedding
# No extra mem usage here as `Embedding` layer doesn't create any new matrix for weights
layer = Embedding(input_dim=weights.shape[0], output_dim=weights.shape[1], weights=[weights], trainable=train_embeddings)
return layer

0 comments on commit 3d2227d

Please sign in to comment.