pub struct Dropout {
pub p: f32,
}
Expand description
Does nothing as a Module, and calls dropout() as ModuleMut with probability 1.0 / N
.
To prevent programmer error, Module and ModuleMut are only implemented for specific tapes:
- Module requires that the input tensor has a NoneTape. i.e. that gradients are not being tracked.
- ModuleMut requires that the tensor has a OwnedTape. i.e. that the gradients are being tracked
That means the following will fail to compile:
ⓘ
let dropout: Dropout = Default::default();
dropout.forward(dev.zeros::<Rank1<5>>().leaky_trace());
ⓘ
let mut dropout: Dropout = Default::default();
dropout.forward_mut(dev.zeros::<Rank1<5>>());
Generics:
N
: p is set as1.0 / N
Examples:
let mut dropout = Dropout { p: 0.5 };
let grads = dropout.alloc_grads();
let x: Tensor<Rank2<2, 5>, f32, _> = dev.ones();
let r = dropout.forward_mut(x.trace(grads));
assert_eq!(r.array(), [[2.0, 2.0, 2.0, 0.0, 0.0], [2.0, 2.0, 0.0, 0.0, 2.0]]);
Fields§
§p: f32