Batch normalization
What is normalization?
An example
x = [1, 4, 6, 8, 10, 9]
How to normalize it to mean as 0 and variance as 1?
>>> x = [1, 4, 6, 8, 10, 9]>>> mu = sum(x)/(len(x))>>> sigma = sum((xi - mu)**2 for xi in x)/(len(x))>>> mu, sigma(6, 9)>>> x_hat = [(xi - mu)/sigma**0.5 for xi in x]>>> x_hat[-1.6666666666666667, -0.6666666666666666, 0.0, 0.6666666666666666, 1.3333333333333333, 1.0]>>> mu_x_hat = sum(x_hat)/(len(x_hat))>>> sigma_x_hat = sum((xi - mu_x_hat)**2 for xi in x_hat)/(len(x_hat))>>> mu_x_hat, sigma_x_hat(0.11111111111111105, 1.0617283950617284)
What is the batch normalization?
The algorithm is shown above. The first two steps are exactly a normalization process. In the algorithm, is a constant added to the mini-batch variance for numerical stability. [1].
In the TensorFlow implementation, for the epsilon, it has the comment of:
variance_epsilon: A small float number to avoid dividing by 0.
Why Batch Normalization?
So many different explanations. Put some for reference.
Since the question mentioned BatchNorm, I wanted to point out that BatchNorm isn’t really used for regularization. That is, BatchNorm does not smooth the cost. Instead, BatchNorm is added in order to improve the performance of backpropagation. In essence, it keeps the back propagated gradient from getting too big or small by rescaling and recentering; as a technique, it has deeper connections to second-order optimization methods that attempt to model the curvature of the cost surface. As I mentioned above, BatchNorm can be also used to guarantee that the relative scaling is correct if you are going to add random noise to the neural activities. From [2]
The correlation between batch normalization and internal covariate shift is widely accepted but was not supported by experimental results. Scholars recently show with experiments that the hypothesized relationship is not an accurate one. Rather, the enhanced accuracy with the batch normalization layer seems to be independent of internal covariate shift. From [3]
The smoothness of the Optimization Landscape[4]
Batch Normalization (BatchNorm) is a widely adopted technique that enables faster and more stable training of deep neural networks (DNNs). Despite its pervasiveness, the exact reasons for BatchNorm’s effectiveness are still poorly understood. The popular belief is that this effectiveness stems from controlling the change of the layers’ input distributions during training to reduce the so-called “internal covariate shift”. In this work, we demonstrate that such distributional stability of layer inputs has little to do with the success of BatchNorm. Instead, we uncover a more fundamental impact of BatchNorm on the training process: it makes the optimization landscape significantly smoother. This smoothness induces a more predictive and stable behavior of the gradients, allowing for faster training. Abstract from [4]
Reference
[1] Sergey Ioffe, Christian Szegedy, Batch Normalization: Accelerating Deep Network Training b y Reducing Internal Covariate Shift, 2015
[3] https://en.wikipedia.org/wiki/Batch_normalization
[4] Shibani Santurkar, Dimitris Tsipras, Andrew Ilyas, Aleksander Madry, How Does Batch Normalization Help Optimization? NIPS 2018