| ggml_layer_dropout | R Documentation |
Applies dropout regularization. During training, multiplies all activations
by (1 - rate) (deterministic expected-value scaling).
During inference (training = FALSE), the layer is an identity (no change).
ggml_layer_dropout(
model,
rate,
stochastic = FALSE,
name = NULL,
trainable = FALSE
)
model |
A |
rate |
Dropout rate in |
stochastic |
Logical. If |
name |
Optional layer name. |
trainable |
Ignored for dropout (no weights); kept for API consistency. |
The model with the dropout layer appended, or a new tensor node.
Keras implements inverted dropout: during training it applies a random
Bernoulli mask and scales surviving activations up by
1 / (1 - rate), so the expected value of each unit is preserved and
no scaling is needed at inference.
This implementation uses deterministic scaling (multiply by
(1 - rate) at training, identity at inference) — equivalent in
expected value but without stochastic noise. Consequences:
No random mask → the regularization signal is weaker (no co-adaptation breaking).
Activations at training are scaled down, not up — the magnitude seen by subsequent layers differs from Keras behaviour.
Results are fully deterministic and reproducible without setting a seed.
With stochastic = TRUE the Bernoulli mask is regenerated once
per epoch (not per batch), because ggml_opt_fit processes all
batches inside a single C call. This is weaker than per-batch dropout
but stronger than the deterministic variant.
model <- ggml_model_sequential() |>
ggml_layer_dense(128, activation = "relu", input_shape = 784L) |>
ggml_layer_dropout(0.5, stochastic = TRUE) |>
ggml_layer_dense(10, activation = "softmax")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.