Layer Normalization
Topics: Neural Networks
Motivation
In traditional neural network training, the activations of each layer can vary drastically, which is known as internal covariance shift. This leads to issues like exploding or vanishing gradients. Similarly to Batch Normalization, Layer Normalization addresses these issues, as well as some of the shortcomings of BN.
The working principle is similar to BN (compute metrics, normalize, and scale); however, in LN, the mean and variance are computed across the features for every data vector in the batch instead of computing them across the batch for every feature.
Details of Layer Normalization
Step 1: Compute Mean and Variance for Each Feature
The mean and variance are computed across features (or neurons) for every element of the batch:
where is the number of features.
For example, if the first layer has outputs, and a batch size of is used, then, means and variances are computed across the features.
Step 2: Normalize the Input
Each feature is normalized by the calculated layer mean and variance to obtain features with mean and unit variance:
where is a small constant added for numerical stability.
Step 3: Apply Scaling and Shifting
Similarly to BN, scaling and shifting is applied using learnable parameters and to ensure that the normalized activations can still cover a wide range of values:
In practice, and are not single scalars, but vectors of parameters, where each feature has its own parameters: .
PyTorch Example

References
Backlinks
Notes that reference this page.
Connections
Direct relationships to this note.