Dropout, as Hinton and colleagues introduced it in 2012, omits each hidden unit with probability 0.5 and each input with probability 0.2 on every presentation of every training case. At test time it keeps every unit and instead scales the outgoing weights of the dropped layers, so that each unit sends what it sends on average during training. Implement both passes of a ReLU network with a softmax output.
Implement dropout_forward(X, layers, train, rng=None, p_in=0.2, p_hidden=0.5).
Inputs
X: array of shape (N, D), one training case per row.layers: list of (W, b) pairs. Layer computes with W of shape (d_in, d_out). Every layer except the last is followed by . The last layer is followed by a row-wise softmax.train: True for a training pass, False for the test pass.rng: a np.random.Generator, used only when train=True.p_in, p_hidden: the probabilities of omitting an input and a hidden unit.Training pass (train=True): a unit is kept when its uniform draw is at least the drop probability.
keep = rng.random(X.shape) >= p_in, and the network sees .keep = rng.random(h.shape) >= p_hidden, and the next layer sees .Test pass (train=False), the mean network: no masks. The first layer uses weights and every later layer uses , because its inputs are hidden units that were dropped during training. Biases are not scaled.
Output: the softmax probabilities, an array of shape (N, K).
X or the arrays in layers.