Normalizes the input vector to a layer to have zero mean and unit variance, making training more efficient. Training deep neural networks is complicated by the fact that the distribution of each layer’s inputs changes during training, as the parameters of the previous layers change. This slows down the training by requiring lower learning rates and careful parameter initialization. This phenomenon is referred to as internal covariate shift.
Adding to the normalized input and scaling it by ensures the model does not lose representational power as a result of the normalization.
Batch Normalization is often found to improve generalization performance (Zhang et al. (2016)).
The batch-normalized version of the inputs, , to a layer is:
Where and are learned and is a small hyperparameter that prevents division by zero. If there are multiple batch normalization layers a separate and will be learned for each of them.
and are moving averages of the mean and variance of . They do not need to be learned. The moving averages are calculated independently for each feature in .
Batch normalization does not work well with small batch sizes (Wu and He, 2018). Small batches cause the statistics to become inaccurate. This can cause problems when training models with large images where large batches will not fit in memory.
Batch normalization’s stabilizing effect is helpful during training but unnecessary at inference time. Therefore, once the network is trained the population mean and variance are used for normalization, rather than the batch mean and variance. This means the networks output can depend only on the input, not also on other examples in the batch.
Application to RNNs¶
Batch normalization is difficult to apply to RNNs since it requires storing the batch statistics for every time step in the sequence. This can be problematic if a sequence input during inference is longer than those seen during training.
Coojimans et al. (2016) propose a variant of the LSTM that applies batch normalization to the hidden-to-hidden transitions.
Conditional batch normalization¶
The formula is exactly the same as normal batch normalization except and are not learned parameters, but rather the outputs of functions.
Was used to achieve state of the art results on the CLEVR visual reasoning benchmark.
This class of normalizations refers to methods that transform the inputs to the model, as opposed to the activations within it.
Scaling the inputs to the network with a linear transformation. Examples include min-max and z-score normalization.
Feature scaling is motivated by practical considerations in optimization.
Rescales the features so they have a specified minimum and maximum.
To rescale to between a and b:
When computing the min and max be sure to use only the training data, as opposed to calculating these statistics on the entire dataset.
Principal Component Analysis (PCA)¶
Decomposes a matrix into a set of orthogonal vectors. The matrix represents a dataset with examples and features.
Method for PCA via eigendecomposition:
- Center the data by subtracting the mean for each dimension.
- Compute the covariance matrix on the centered data .
- Do eigendecomposition of the covariance matrix to get .
- Take the k largest eigenvalues and their associated eigenvectors. These eigenvectors are the ‘principal components’.
- Construct the new matrix from the principal components by multiplying the centered by the truncated .
PCA can also be done via SVD.
The process of transforming the inputs so that they have zero mean and a covariance matrix which is the identity. This means the features will be linearly uncorrelated with each other and have variances equal to 1.
Like PCA, ZCA converts the data to have zero mean and an identity covariance matrix. Unlike PCA, it does not reduce the dimensionality of the data and tries to create a whitened version that is minimally different from the original.
The features are transformed by subtracting their mean and dividing by their standard deviation:
where is the jth instance of feature i and and are the mean and standard deviation of feature x_i respectively.
Ensure that the mean and standard deviation are calculated on the training set, not on the entire dataset.
Group normalization implements the same formula as batch normalization but takes the average over the feature dimension(s) rather than the batch dimension. This means it can be used with small batch sizes, unlike batch normalization, which is useful for many computer vision applications where memory-consuming high resolution images naturally restrict the batch size.
Where and are learned and is a small hyperparameter that prevents division by zero. Separate gamma and beta are learned for each group normalization layer. and make sure the model does not lose any representational power from the normalization.
Can be easily applied to RNNs, unlike batch normalization.
If the hidden state at time of an RNN is given by:
Then the layer normalized version is:
where and are the mean and variance of .
The weights of the network are reparameterized as:
where is a learnt scalar and is a learnt vector.
This guarantees that without the need for explicit normalization.
Simple to use in RNNs, unlike batch normalization.
Unlike batch normalization, weight normalization only affects the weights - it does not normalize the activations of the network.