Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Key Code Blocks of Keras LSTM Dropout Implementation
class LSTM(Recurrent):
def get_constants(self, inputs, training=None):
input_shape = K.int_shape(inputs)
input_dim = input_shape[-1]
ones = K.ones_like(K.reshape(inputs[:, 0, 0], (-1, 1)))
ones = K.tile(ones, (1, int(input_dim)))
def dropped_inputs():
return K.dropout(ones, self.dropout)
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