34 min total

Deep Learning

Regularization & dropout

Regularization & dropout

Once the network can learn, the next questions are how to keep it from overfitting and how to make training behave reliably.

Training, development, and test sets

Machine learning is a highly iterative process

Data sizePreferred split (Train/dev/test)
Millions99.5/0.4/0.1
Small50/20/30

Make sure that the Train & dev/test data distributions are the same

For meaningful evaluations

Use dev set to evaluate and iterate models performance

Test set is only used to provide unbiased estimate of final model performance

Regularization

Used to prevent overfitting in machine learning models

L2 Norm is also called Euclidean norm/Frobenius norm

L2 regularization is also called 'weight decay'

L1 regularization adds absolute values of weight parameters, leading to many sparse(zero) weight vectors

Weight decay multiplies weights by value slightly less than one during each GD iteration

L2/Frobenius Norm:

Regularization & dropout — diagram

New Backprop eq:

Regularization & dropout — diagram
Regularization & dropout — diagram
Regularization & dropout — diagram
Regularization & dropout — diagram

Dropout regularization

Regularization & dropout — diagram

During training, dropout temporarily deactivates randomly selected units, so each pass uses a different subset of the network.

Dropout in neural networks mimics ensemble learning by training different subsets of nodes in each iteration. During testing, without dropout, it's like averaging outputs from all these subnetworks. This approach mirrors ensemble methods, where multiple models' outputs are combined for improved robustness. Essentially, dropout acts as an efficient way to train numerous networks sharing the same weights, providing ensemble-like benefits within a single network structure.

Inverted dropout

Illustrating with layer3 and Keep_prob = 0.8

python
keep_prob = 0.8
D3 = np.random.rand(*A3.shape) < keep_prob
A3 = A3 * D3 / keep_prob

Net activations during inference would be larger if we don’t use inverted dropout technique.

Regularization & dropout — diagram

In normal dropout algorithm, during inference activations are multiplied by p to ensure that activations are not too high

Inverted dropout divides retained activations by keep_prob during training to preserve their expected scale. No dropout scaling is needed during inference.

Dropout has similar effect to L2 regularization

We can apply dropout to input layers aswell as set individual keep_probs for different layers to ensure that layers with high params are dropout more

Other regularization methods

  1. Data augmentation
  2. Early stopping
Regularization & dropout — diagram

When dev set error begins to increase, stop the algorithm then

Regularization lambda hyperparameter ko change krk mein bar bar train krna prta, whereas idhr ek hi baari mein pta lg jaata