Qu

dropout_layer

Builtin index · Statistics & ML

result = dropout_layer(rate)

Input: rate · Output: result

What it is

Builds one unfitted dropout-layer spec for use inside a sequential stack: rate a number in [0, 1), the fraction of activations to zero during training.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = dropout_layer(rate)
rate numbernot documented yet
result Record
Returns a layer-spec Record with no weights (dropout has none) — sequential_forward turns it into a dropout(...) call during training and a no-op passthrough during .predict.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

dl1 = dense_layer(2, 8, activation = "relu")
dl2 = dropout_layer(0.3)
dl3 = dense_layer(8, 1, activation = "none")
net = sequential((dl1, dl2, dl3), seed = 3)
print("layer count: {length(net.layers)}")

Xxor = [0.0, 0.0; 0.0, 1.0; 1.0, 0.0; 1.0, 1.0]
Yxor = [0.0; 1.0; 1.0; 2.0]
net = net.fit(Xxor, Yxor, epochs = 60, optimizer = adam(lr = 0.05), loss = "mse")
n = length(net.loss_history)
print("sequential + dropout_layer: loss {round(net.loss_history[0], 4)} -> {round(net.loss_history[n - 1], 4)}")

mc = mlp_classifier(2, [8], 2, seed = 3)
Yc = [0, 1, 1, 0]
mc = mc.fit(Xxor, Yc, epochs = 60, loss = "cross_entropy")
nc = length(mc.loss_history)
print("mlp_classifier: loss {round(mc.loss_history[0], 4)} -> {round(mc.loss_history[nc - 1], 4)}")
preds = mc.predict(Xxor)
print("mlp_classifier raw logits shape: {rows(preds)} x {cols(preds)}")
output
layer count: 3
sequential + dropout_layer: loss 3.0224 -> 0.5
mlp_classifier: loss 0.7146 -> 0.6938
mlp_classifier raw logits shape: 4 x 2

from statistics-ml

How it works

dropout_layer([rate=0.5]) — a stretch wrapper (the task's must-have is dense_layer): no weights of its own, just a spec sequential_forward turns into a dropout(...) call during training and a no-op passthrough during predict.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.