Skip to content
E
Educatum

Dropout

By Educatum AI teamLast updated: Original walkthrough ↗
Key Intuition

Dropout regularizes neural networks by randomly zeroing neuron activations with probability p during each training forward pass, preventing co-adaptation and acting as implicit model averaging across thinned subnetworks. With modern inverted dropout, surviving activations are scaled by 1 / (1 - p) during training so their expected value matches inference without requiring scaling at test time.

Reference Diagram & Materials
Dropout matrix calculation diagram

Dropout walkthrough diagram

The Core Idea Behind Dropout

When applying dropout, we randomly zero out (“drop”) a fraction pp of neuron activations in a layer on each forward pass during training. If a neuron is dropped, its output becomes 00, so it contributes neither to the forward pass nor to the backward gradient update on that iteration. This prevents neurons from over-relying on specific co-adaptations and encourages more redundant, robust representations.

Expected Value of Activations & Scaling

Let:

  • p∈[0,1)p \in [0, 1): the dropout probability (probability a neuron is dropped).
  • xx: the neuron’s original activation before dropout.
  • yy: the neuron’s output after dropout.

1. Why Unscaled Dropout Causes a Train-Test Mismatch

Without scaling, a neuron’s output during training is: yunscaled={xwith probability 1−p0with probability py_{\text{unscaled}} = \begin{cases} x & \text{with probability } 1 - p \\ 0 & \text{with probability } p \end{cases}

Its expected value during training is therefore shrunk by 1−p1 - p: E[yunscaled]=x⋅(1−p)+0⋅p=(1−p)x\mathbb{E}[y_{\text{unscaled}}] = x \cdot (1 - p) + 0 \cdot p = (1 - p)x

At inference time (eval mode), all neurons stay active (p=0p = 0) with output xx. Without compensation, activations passed to downstream layers would be 11−p\frac{1}{1 - p} times larger at test time than during training!

2. Inverted Dropout (Standard Practice)

In the original formulation (Srivastava et al., 2014), activations were left unscaled during training and multiplied by (1−p)(1 - p) at test time. Modern frameworks (PyTorch, TensorFlow, JAX) instead use inverted dropout, applying the compensation factor 11−p\frac{1}{1 - p} during training:

yinverted={x1−pwith probability 1−p0with probability py_{\text{inverted}} = \begin{cases} \dfrac{x}{1 - p} & \text{with probability } 1 - p \\ 0 & \text{with probability } p \end{cases}

Taking the expectation over the random binary mask: E[yinverted]=x1−p⋅(1−p)+0⋅p=x\mathbb{E}[y_{\text{inverted}}] = \frac{x}{1 - p} \cdot (1 - p) + 0 \cdot p = x

Because the expected activation already equals xx during training:

  • Inference requires zero extra work: all weights and activations are used directly at test time without scaling.
  • Backpropagation: the exact same binary mask and 11−p\frac{1}{1 - p} scaling factor are applied to gradients flowing back through that layer during training.

More in GenAI by Hand

Try keywords like RoPE, FlashAttention, DPO, or Blind 75.