pyml.neural_network.layer.transformation.dropout.Dropout#

class Dropout(rate)[source]#

Bases: _Transformation

Dropout Layer for Neural Networks.

This layer applies dropout regularization during training to prevent overfitting by randomly setting a fraction of the input units to zero during each forward pass.

Parameters:

rate (float) – The dropout rate, indicating the fraction of input units to drop. The remaining units will be scaled by 1 / (1 - rate).

Variables:
  • generator (numpy.random.Generator) – Random number generator used for mask generation.

  • inputs (numpy.ndarray) – The input values received during the forward pass.

  • binary_mask (numpy.ndarray) – Binary mask with probabilities of keeping units.

  • output (numpy.ndarray) – The output values after applying dropout during the forward pass.

Methods

__init__

backward

Perform the backward pass by applying the binary mask to gradients.

forward

Perform the forward pass with dropout during training and without dropout during inference.

set_adjacent_layers

Set adjacent layers which are needed for the model to iterate through the layers.

backward(dvalues)[source]#

Perform the backward pass by applying the binary mask to gradients.

Return type:

None

Parameters:

dvalues (np.ndarray) – Derived gradient from the previous layer (reversed order).

forward(inputs, training)[source]#

Perform the forward pass with dropout during training and without dropout during inference.

Return type:

None

Parameters:
  • inputs (np.ndarray) – Input values from previous layer.

  • training (bool) – If true, apply dropout to layer be replacing some inputs with zero. Otherwise inputs will be passed through as outputs

Note

During training, the layer generates a binary mask with probabilities of keeping units, which is then applied to the inputs to create the output. During inference (when training is False), the layer simply copies the inputs to the output.

set_adjacent_layers(previous_layer, next_layer)#

Set adjacent layers which are needed for the model to iterate through the layers.

Parameters:
  • previous_layer (_Layer) – Layer that is previous to this layer.

  • next_layer (_Layer) – Layer that is subsequent to this layer.