liveBook · Manning

Recurrent dropout

As explained in Deep Learning with Python, Third Edition

A dropout variant for recurrent networks that applies a temporally consistent mask to recurrent computations.

Recurrent dropout combats overfitting in recurrent networks without forcing regularization to come from a smaller model. Instead of changing which units are dropped at every timestep, it applies one dropout pattern consistently across the sequence. A changing pattern would disrupt the error signal as it propagates through time. section 13.3.4

Listing 13.22 Training and evaluating a dropout-regularized LSTM
inputs = keras.Input(shape=(sequence_length, raw_data.shape[-1]))
x = layers.LSTM(32, recurrent_dropout=0.25)(inputs)
x = layers.Dropout(0.5)(x)                                       #1
outputs = layers.Dense(1)(x)
model = keras.Model(inputs, outputs)

callbacks = [
    keras.callbacks.ModelCheckpoint(
        "jena_lstm_dropout.keras", save_best_only=True
    )
]
model.compile(optimizer="adam", loss="mse", metrics=["mae"])
history = model.fit(
    train_dataset,
    epochs=50,
    validation_data=val_dataset,
    callbacks=callbacks,
)

A practical Keras configuration combines recurrent dropout inside an LSTM with ordinary dropout after the recurrent layer. The example uses recurrent_dropout=0.25, Dropout(0.5), Adam, mean squared error, mean absolute error, validation data, and checkpointing. section 13.3.4

Use recurrent dropout with these rules of thumb:

  • Set dropout for input units and recurrent_dropout for recurrent units; recurrent_dropout supplies the temporally consistent recurrent mask. section 13.3.4
  • Expect slower convergence after regularization, and compensate with longer training when necessary. section 13.3.4
  • On the Jena temperature-forecasting task, a larger LSTM with dropout avoided early overfitting and improved validation and test MAE over the no-learning baseline. section 13.3.4

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains temporal masks, recurrent activations, Keras arguments, convergence costs, and forecasting results without deriving the underlying mathematics.
Examples
Uses a dropout-regularized LSTM for Jena temperature forecasting with validation and test MAE comparisons.
What it assumes
Assumes familiarity with recurrent networks, LSTM or GRU layers, sequence data, and basic Keras model training.
What you can do after
Apply it via Keras recurrent layers by setting dropout and recurrent_dropout and evaluating overfitting on validation data.
How it connects
Connects dropout with recurrent layers, LSTM, GRU, error propagation through time, and overfitting.

Also explained in

Compare how 2 books explain recurrent dropout →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.