Dropout
Dropout sets a random subset of hidden units to zero at every training step. Each unit of a hidden layer is kept with probability , the keep probability, and zeroed otherwise, independently of the other units and of earlier steps:
A zeroed unit removes all of its incoming and outgoing weights for that step, so each step trains a slightly different subnetwork. Typical values are for dense hidden layers and higher values near the input. In the backward pass the gradient is multiplied by the same mask, so zeroed units receive no gradient on that step.At test time every unit is active, so each unit receives more input than it did on average during training. Three versions handle this:
- The weight scaling inference rule multiplies the activations, or equivalently the outgoing weights, by at test time.
- Inverted dropout, which PyTorch uses, divides the kept activations by during training and changes nothing at test time.
- Monte Carlo dropout keeps dropout on at test time, runs the network several times, and averages the predictions.
In the first two a unit’s expected training output equals its test output.
Dropout makes the network rely less on any single unit and encourages redundant representations. It also tends to remove sharp kinks in the learned function that lie between training points and do not affect the loss. It acts like data augmentation applied inside the network. For linear regression with dropout on the input features, the expected training loss equals ridge regression with a feature-dependent penalty:
Here is a random mask with entries , is the elementwise product, and is the -th column of . Dropout works well in dense layers and poorly in convolutional layers. Convolutional networks use two variants instead:
- Spatial dropout drops whole channels.
- Cutout masks a square of the input image.
Keep Probability or Drop Probability
The lecture and the discussions write for the probability of keeping a unit. PyTorch’s
nn.Dropout(p)and the textbook state the probability of dropping it, which is here. With PyTorch’s convention the inverted-dropout scale is . Check the convention before plugging into any formula.
Intuition
A network can fit its training data with units that only work together. One unit makes the function rise steeply, a second brings it back down, and a third cancels the second. The three create a kink between training points that costs nothing on the training loss and generalizes badly. Removing one of them at random breaks the arrangement and changes the output far from the data, as the figure shows. The next gradient step then pushes the remaining units to make up for the loss. Repeated over many steps, every unit learns to be useful on its own. Large detours that the data never asked for are gradually removed.
\usepackage{tikz}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[x=1cm,y=1cm]
\foreach \k/\px/\lab in {0/0/{all units},1/5.2/{one step of dropout}} {
\foreach \i in {1,2,3} \node[circle,draw,minimum size=0.55cm,inner sep=0pt] (x\k\i) at (\px,3-\i) {$x_{\i}$};
\foreach \i in {1,...,4} \node[circle,draw,minimum size=0.55cm,inner sep=0pt] (a\k\i) at (\px+1.4,3.5-\i) {};
\foreach \i in {1,...,4} \node[circle,draw,minimum size=0.55cm,inner sep=0pt] (b\k\i) at (\px+2.8,3.5-\i) {};
\node[circle,draw,minimum size=0.55cm,inner sep=0pt] (y\k) at (\px+4.0,1) {$y$};
\node at (\px+2.0,-1.5) {\lab};
}
\foreach \i in {1,2,3} \foreach \j in {1,...,4} \draw[mid] (x0\i) -- (a0\j);
\foreach \i in {1,...,4} \foreach \j in {1,...,4} \draw[mid] (a0\i) -- (b0\j);
\foreach \i in {1,...,4} \draw[mid] (b0\i) -- (y0);
\foreach \i in {1,2,3} \foreach \j in {1,3,4} \draw[mid] (x1\i) -- (a1\j);
\foreach \i in {1,3,4} \foreach \j in {1,2,4} \draw[mid] (a1\i) -- (b1\j);
\foreach \i in {1,2,4} \draw[mid] (b1\i) -- (y1);
\node[circle,draw=hot,fill=hot,minimum size=0.55cm,inner sep=0pt] at (6.6,1.5) {};
\node[circle,draw=hot,fill=hot,minimum size=0.55cm,inner sep=0pt] at (8.0,0.5) {};
\node[hot] at (7.3,3.2) {dropped units};
\end{tikzpicture}
\end{document}The randomness also makes dropout a cheap ensemble. A layer with units has possible masks, each a different subnetwork, and all of them share one set of weights. Training samples a new subnetwork at every step. Testing with all units active and scaled activations approximates the average prediction of the whole family without training or storing more than one network.
Properties
(Matching the Expected Activation) The scaling by makes each unit’s input at test time equal its expected input during training.
A unit that receives during training has expected input . At test time, with every , its input would be , larger by the factor . Multiplying by at test time, or dividing by during training, removes the mismatch. For a linear network the match is exact in expectation. Through nonlinearities it is only approximate, because the average of over masks is not of the average input. Monte Carlo dropout avoids this approximation by averaging actual dropout predictions. The spread of those predictions also gives a rough measure of the model’s uncertainty.
(Ridge Regression in Disguise) For linear regression, dropout on the inputs equals generalized ridge regression after rescaling the weights by .
Substituting into the identity in the callout gives
The map is invertible, so it maps the minimizer of the dropout objective to the minimizer of this Tikhonov problem. The factor is the same test-time scaling as in the weight scaling rule. The penalty on grows with , so features with large values are shrunk more. The strength falls to as , equals at , and grows like as .
(Equal Column Norms) After the ridge reparameterization, every feature column has the same norm, which resembles the rescaling done by batch normalization.
Rewriting the problem as standard ridge regression with penalty requires and the data matrix . Its -th column is . All columns therefore have the norm . Dropout behaves like ridge regression on features rescaled to a common size. Batch normalization also rescales features, but it centers them as well and uses batch statistics with a learned scale and shift. Equal norms without centering do not give equal variances, so the two operations resemble each other without being equivalent.
(Weak in Convolutional Layers) Dropping single pixels of a feature map barely changes what the next layer sees, because neighboring pixels carry the same information.
Natural images are smooth, so a feature map’s neighboring positions are strongly correlated. When one position is zeroed, its neighbors still pass nearly the same information forward, and the regularizing effect is small. Spatial dropout instead zeroes entire channels, the same channels at every position of an example. Cutout masks a square patch of the input image. Both remove information that the rest of the input cannot easily supply. Classic CNNs such as AlexNet applied ordinary dropout only to their dense layers.
Derivation
We want to remove the expectation from the dropout objective for linear regression. Write , so that the -th prediction is . Since , the mean prediction is . For any random vector , , so
The mask entries are independent with variance , so the variance of each sum is the sum of the variances:
This is the identity in the callout. The mean term asks the scaled-down predictions to fit the data, and the variance term penalizes weights on features with large norms.
Examples
(Easy) Training and Test Activations
A layer has activations and keep probability . One training step samples the mask .
What does the next layer receive on this step with plain dropout and with inverted dropout, and what should it receive at test time in each case? , and inverted dropout passes . Over all masks, plain dropout passes on average, so at test time the activations must be scaled to . Inverted dropout passes on average, so at test time it passes unchanged. A next-layer unit that sums its inputs would see on average during plain-dropout training. At test time it would see if the scaling were forgotten.
Plain dropout passes
(Medium) The Penalty Dropout Imposes
A linear regression has two features with column norms and , and it is trained with dropout on its inputs.
Write the equivalent ridge penalty for and for . Here . For the factor is , so and the penalty is . For the factor is , so and the penalty is . Dropping more units quadruples the penalty here. In both cases the weight on the large-norm feature is penalized times as heavily as the other, which is the ratio of the squared column norms.
(Hard) How Noisy Is Dropout?
A unit sums inputs, each equal to , with inverted dropout at keep probability : .
Find the mean and standard deviation of for with and with . The mean is in both cases. The variance is . For this is , a standard deviation of , or of the mean. For it is , a standard deviation of . The relative noise falls like , so a wide layer feels dropout less on each unit's total input than a narrow one. Lower keep probabilities inject more noise and therefore regularize more strongly.
See Also
- 4.4. Neural Network Regularization, for the other regularizers.
- 4.4.2. Data Augmentation, which dropout imitates inside the network.
- 3.2.1. Ridge Regression, for ridge regression.
- 4.5.1. Batch Normalization, another source of training noise.
- 5.2.4. CNNs, for AlexNet’s use of dropout in its dense layers.