Regularization

Regularization is a set of techniques that lower the complexity of a neural network model during training, and thus prevent the overfitting.. Conceptually, it forces the network to be simpler. It artificially restricts the model's flexibility so that it cannot memorize the noise, forcing it to focus only on the strongest, most generalizable patterns.

In mathematical terms, many regularization techniques work by adding a "penalty" to the loss function.

Total Loss=Data Loss+λ(Regularization Penalty)

(Where λ is a number you choose to decide how harsh the penalty should be).

There are three very popular and efficient regularization techniques called L1L2, and dropout.

I. L1 and L2 regularization

L1 regularization (Lasso)

Loss=Error(y,y^)Loss function with no regularizationLoss=Error(y,y^)+λi=1N|wi|Loss function with L1 regularization
Advantages
Use Case

When you suspect that only a small number of features are actually relevant to the task.

L2 regularization (Ridge / Weight Decay)

Loss=Error(y,y^)+λi=1Nwi2Loss function with L2 regularization
Advantages
Use Case

L2 regularization is useful when you believe that most features contribute to the prediction, in varying degrees.

Differences between L1 and L2

L1 regularization L2 regularization
Penalty L1 regularization adds a penalty proportional to the absolute value of the weight coefficients, leading to sparse models. L2 regularization adds a penalty proportional to the square of the weight coefficients, leading to smaller but non-zero weights.
Feature Selection L1 tends to produce sparse solutions, effectively selecting a subset of features L2 tends to shrink weights uniformly
Gradient Behavior The gradients of L1 regularization are not continuous, which can lead to convergence issues in optimization L2 has continuous gradients, making optimization smoother.

II. Dropout Regularization

Process of Dropout - Training Phase

1. Define Dropout Rate (p):

2. Random Deactivation:

maskiBernoulli(1p)maski={0Deactivate neuron i1Keep neuron i active

3. Dropping Neurons:

4. Forward Pass:

5. Backward Pass (Backpropagation):

6. Repeat Per Mini-Batch:

7. Inverted Dropout (The Modern Standard)

Testing Phase

During testing, dropout is not applied, as the intention is to evaluate the entire network without randomness. Instead, the weights learned during training are scaled to account for the earlier dropout.

1. Disable Dropout:

2. Scale Weights for Each Layer:

3. Forward Pass:

4. Final Prediction:

ML_AI/images/dropout-2.png750

III. Regularization by Early Stopping

Advantages

test