Function dfdx::tensor_ops::dropout

source ·
pub fn dropout<S: Shape, E: Dtype, D: DropoutKernel<E>, T: Tape<E, D>>(
    t: Tensor<S, E, D, T>,
    prob: impl Into<f64>
) -> Tensor<S, E, D, T>
Expand description

Zeros elements with probability p and scales all elements by 1 / (1 - p).

Described in paper: Improving neural networks by preventing co-adaptation of feature detectors

Example:

let t = dev.tensor([1.0f32, 2.0, 3.0, 4.0]);
let r = t.dropout(0.5);
assert_eq!(r.array(), [2.0, 0.0, 6.0, 0.0]);

Implementation details:

To reduce memory usage, this function first samples a u64 seed from rng, and then instantiates two identical rand::rngs::StdRng with that seed. These rngs are used in both the forward pass and backward pass to generate identical random numbers, so the masking is the same for both.