In machine learning, normalization is a statistical technique with various applications. There are two main forms of normalization, namely data normalization and activation normalization. Data normalization (or feature scaling) includes methods that rescale input data so that the features have the same range, mean, variance, or other statistical properties. For instance, a popular choice of feature scaling method is min-max normalization, where each feature is transformed to have the same range (typically [0,1] or [−1,1]). This solves the problem of different features having vastly different scales, for example if one feature is measured in kilometers and another in nanometers. Activation normalization, on the other hand, is specific to deep learning, and includes methods that rescale the activation of hidden neurons inside neural networks. Normalization is often used to:
increase the speed of training convergence, reduce sensitivity to variations and feature scales in input data, reduce overfitting, and produce better model generalization to unseen data. Normalization techniques are often theoretically justified as reducing covariance shift, smoothing optimization landscapes, and increasing regularization, though they are mainly justified by empirical success.
Batch normalization
Batch normalization (BatchNorm) operates on the activations of a layer for each mini-batch. Consider a simple feedforward network, defined by chaining together modules: x(0)↦x(1)↦x(2)↦⋯ where each network module can be a affine transform, a nonlinear activation function, a convolution, etc. x(0) is the input vector, x(1) is the output vector from the first module, etc. BatchNorm is a module that can be inserted at any point in the feedforward network. For example, suppose it is inserted just after x(l), then the network would operate accordingly: ⋯↦x(l)↦BN(x(l))↦x(l+1)↦⋯The BatchNorm module does not operate over individual inputs. Instead, it must operate over one batch of inputs at a time. Concretely, suppose we have a batch of inputs x(1)(0),x(2)(0),…,x(B)(0), fed all at once into the network. We would obtain in the middle of the network some vectors:xvector coordinate(layer):x(1)(l),x(2)(l),…,x(B)(l)The BatchNorm module computes the coordinate-wise mean and variance of these vectors:μi(l)=1B∑b=1Bx(b),i(l)(σi(l))2=1B∑b=1B(x(b),i(l)−μi(l))2where i indexes the coordinates of the vectors, and b indexes the elements of the batch. In other words, we are considering the i-th coordinate of each vector in the batch, and computing the mean and variance of these numbers. More transparently, we may writeμvector coordinate i(layer ℓ)=Avg(b,x(batch b),i(l))(σi(l))2=Avg(b,(x(b),i(l)−μi(l))2)It then normalizes each coordinate to have zero mean and unit variance:x̂(b),i(l)=x(b),i(l)−μi(l)(σi(l))2+ϵThe ϵ is a small positive constant such as 10−9 added to the variance for numerical stability, to avoid division by zero. The entire operation is a data whitening transformation of the x(batch b),vector coordinate i(layer ℓ) tensor over the b-index, with the small positive constant ϵ added for numerical stability. We notate it as:x̂(batch b),vector coordinate i(layer ℓ)=Whitenϵ(x(b),i(l)|b)Finally, it applies a affine transformation:y(b),i(l)=γi(ℓ)x̂(b),i(ℓ)+βi(ℓ)Here, γ and β are parameters inside the BatchNorm module. They are learnable parameters, typically trained by gradient descent, while ϵ is a hyperparameter (i.e. not trained) of the BatchNorm module. More succinctly,y(batch b),vector coordinate i(layer ℓ)=γi(ℓ)Whitenϵ(x(b),i(l)|b)+βi(ℓ)More succinctly,
Interpretation γ and β allow the network to learn to undo the normalization, if this is beneficial. BatchNorm can be interpreted as removing the purely affine transformations, so that its layers focus solely on modelling the nonlinear aspects of data, which may be beneficial, as a neural network can always be augmented with a affine transformation layer on top. It is claimed in the original publication that BatchNorm works by reducing internal covariance shift, though the claim has both supporters and detractors.
Special cases The original paper recommended to only use BatchNorms after a affine transform, not after a nonlinear activation. That is, ϕ(BN(Wx+b)), not BN(ϕ(Wx+b)). Also, the bias b does not matter, since it would be canceled by the subsequent mean subtraction, so it is of the form BN(Wx). That is, if a BatchNorm is preceded by a affine transform, then that affine transform's bias term is set to zero.
CNN For convolutional neural networks (CNNs), BatchNorm must preserve the translation-invariance of these models, meaning that it must treat all outputs of the same kernel as if they are different data points within a batch. This is sometimes called Spatial BatchNorm, or BatchNorm2D, or per-channel BatchNorm. Concretely, suppose we have a 2-dimensional convolutional layer defined by:xh,w,c(l)=∑h′,w′,c′Kh′−h,w′−w,c,c′(l)xh′,w′,c′(l−1)+bc(l)where:
xh,w,c(l) is the activation of the neuron at position (h,w) in the c-th channel of the l-th layer. KΔh,Δw,c,c′(l) is a kernel tensor. Each channel c corresponds to a kernel Kh′−h,w′−w,c,c′(l), with indices Δh,Δw,c′. bc(l) is the bias term for the c-th channel of the l-th layer. In order to preserve the translational invariance, BatchNorm treats all outputs from the same kernel in the same batch as more data in a batch. That is, it is applied once per kernel c (equivalently, once per channel c), not per activation xh,w,c(l+1):μc(l)=1BHW∑b=1B∑h=1H∑w=1Wx(b),h,w,c(l)(σc(l))2=1BHW∑b=1B∑h=1H∑w=1W(x(b),h,w,c(l)−μc(l))2where B is the batch size, H is the height of the feature map, and W is the width of the feature map. That is, even though there are only B data points in a batch, all BHW outputs from the kernel in this batch are treated equally. Subsequently, normalization and the affine transform is also done per kernel:x̂(b),h,w,c(l)=x(b),h,w,c(l)−μc(l)(σc(l))2+ϵy(b),h,w,c(l)=γc(ℓ)x̂(b),h,w,c(l)+βc(ℓ)This generalizes to n-dimensional CNN.
The original BatchNorm is a special case of BatchNorm for 0-dimensional CNN.
RNN A multilayered recurrent neural networks (RNN) is similar to a 1-dimensional RNN. Consequently, BatchNorm for 1D CNN applies.
… excerpt ends here. Continue reading the full article.