Dropout

Contents

Dropout#

class brainstate.nn.Dropout(prob=0.5, broadcast_dims=(), name=None)#

A layer that stochastically ignores a subset of inputs each training step.

In training, to compensate for the fraction of input values dropped (rate), all surviving values are multiplied by 1 / (1 - rate).

This layer is active only during training (mode=brainstate.mixin.Training). In other circumstances it is a no-op.

Parameters:
  • prob (float) – Probability to keep element of the tensor. Default is 0.5.

  • broadcast_dims (Sequence[int]) – Dimensions that will share the same dropout mask. Default is ().

  • name (str | None) – The name of the dynamic system.

References

Examples

>>> import brainstate
>>> layer = brainstate.nn.Dropout(prob=0.8)
>>> x = brainstate.random.randn(10, 20)
>>> with brainstate.environ.context(fit=True):
...     output = layer(x)
>>> output.shape
(10, 20)