class

Dropout1d

extendsModule
Dropout1d(p: float = 0.5, inplace: bool = False)
source

Randomly zero entire channels during training for 3-D inputs.

Extends the dropout idea from individual elements to entire channels (feature maps) for sequence data of shape (N, C, L). A single Bernoulli draw per channel per sample determines whether that channel is zeroed across its entire length:

yn,c,:={xn,c,:1pwith probability 1p0with probability p(training)y_{n,c,:} = \begin{cases} \dfrac{x_{n,c,:}}{1 - p} & \text{with probability } 1 - p \\[6pt] \mathbf{0} & \text{with probability } p \end{cases} \quad \text{(training)}

This is more aggressive than element-wise Dropout and is appropriate when neighbouring positions along the L axis are highly correlated (as they are in the output of a 1-D convolution), so that zeroing a single element would not provide enough regularisation signal.

Parameters

pfloat= 0.5
Probability of zeroing an entire channel. Must be in [0, 1]. Default: 0.5.
inplacebool= False
If True, modify the input in place. Default: False.

Notes

  • Input: (N, C, L) — batch of 1-D feature maps.
  • Output: (N, C, L) — same shape; zeroed channels are uniformly zero along the entire L dimension.

The mask is sampled along the (N, C) axes only, then broadcast over L. The forward pass delegates to the same engine kernel as Dropout2d.

Dropout : Element-wise dropout. Dropout2d : Channel-wise dropout for 4-D (spatial) inputs. Dropout3d : Channel-wise dropout for 5-D (volumetric) inputs.

Examples

Channel-wise dropout on a batch of 1-D feature maps:
>>> import lucid, lucid.nn as nn
>>> drop1d = nn.Dropout1d(p=0.2)
>>> drop1d.train()
>>> x = lucid.ones(2, 8, 16)    # (N=2, C=8, L=16)
>>> y = drop1d(x)
>>> y.shape
(2, 8, 16)
>>> # Each of the 8 channels is either all-zero or all-scaled
Verify pass-through in eval mode:
>>> drop1d.eval()
>>> y_eval = drop1d(lucid.ones(2, 8, 16))
>>> float(y_eval.sum()) == 256.0
True

Methods (3)

dunder

__init__

None
__init__(p: float = 0.5, inplace: bool = False)
source

Initialise the Dropout1d module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Apply dropout to the input tensor.

Parameters

inputTensor
Input tensor of arbitrary shape.

Returns

Tensor

Output tensor of the same shape as input; in eval mode this is the identity.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.