Created
September 30, 2017 02:10
-
-
Save ceshine/00c69e52860e0ba19aaa51a0634b6198 to your computer and use it in GitHub Desktop.
Key Code Blocks of Keras LSTM Dropout Implementation
This file contains hidden or 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
# https://github.com/tensorflow/tensorflow/blob/v1.3.0/tensorflow/contrib/keras/python/keras/layers/recurrent.py#L1174 | |
class LSTM(Recurrent): | |
#... | |
def get_constants(self, inputs, training=None): | |
#... | |
ones = K.ones_like(K.reshape(inputs[:, 0, 0], (-1, 1))) | |
ones = K.tile(ones, (1, self.units)) | |
def dropped_inputs(): # pylint: disable=function-redefined | |
return K.dropout(ones, self.recurrent_dropout) | |
rec_dp_mask = [ | |
K.in_train_phase(dropped_inputs, ones, training=training) | |
for _ in range(4) | |
] | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment