Recurrent dropout regularizes sequence models by applying one fixed dropout pattern across every timestep. A changing pattern would disrupt the error signal flowing through time, while a time-constant mask lets the network learn across the sequence. section 13.3.4
Dropout-regularized LSTM
For temperature forecasting, configure recurrent dropout inside the LSTM and ordinary dropout after it: layer_lstm(32, recurrent_dropout = 0.25) |> layer_dropout(0.5) |> layer_dense(1). The regularized model can use more units and train longer to reduce overfitting. section 13.3.4
Listing 13.23 Training and evaluating a dropout-regularized LSTM
inputs <- keras_input(shape = c(sequence_length, ncol_input_data))
outputs <- inputs |>
layer_lstm(32, recurrent_dropout = 0.25) |>
layer_dropout(0.5) |> #1
layer_dense(1)
model <- keras_model(inputs, outputs)
callbacks = list(
callback_model_checkpoint("jena_lstm_dropout.keras", save_best_only = TRUE)
)
compile(model, optimizer = "adam", loss = "mse", metrics = "mae")history <- model |> fit(
train_dataset,
epochs = 50,
validation_data = val_dataset,
callbacks = callbacks
)
Inspect the complete R/Keras training and evaluation example, including checkpointing, compilation, metrics, and validation. section 13.3.4
Keras recurrent layers expose separate rates: dropout applies to input units, whereas recurrent_dropout applies to recurrent units and their internal activations. This reduces reliance on shrinking the network for regularization. section 13.3.4 section 13.5

