Introduction
Layer Normalization (LayerNorm) is a normalization technique used to stabilize and accelerate the training of deep neural networks. Unlike Batch Normalization, which computes statistics across a mini-batch, Layer Normalization computes statistics within a single training sample across its features.
Since it does not depend on the batch size, LayerNorm performs consistently even when training with very small batches or processing one sample at a time. This makes it the preferred normalization technique for Transformers, Recurrent Neural Networks (RNNs), Large Language Models (LLMs), and Natural Language Processing (NLP) tasks.
Modern AI models such as BERT, GPT, LLaMA, T5, RoBERTa, and Vision Transformers (ViTs) rely heavily on Layer Normalization for stable and efficient training.
What is Layer Normalization?
Layer Normalization is a technique that normalizes the activations of all features within a single sample before passing them to the next layer.
Instead of calculating the mean and variance across an entire mini-batch, LayerNorm computes these statistics independently for each training example.
In simple terms:
Layer Normalization ensures that each individual sample has a stable feature distribution, regardless of the batch size.
Why Do We Need Layer Normalization?
Batch Normalization works extremely well for CNNs trained with large mini-batches. However, many modern neural networks operate under conditions where Batch Normalization becomes less effective.
Some common challenges include:
- Very small batch sizes
- Variable batch sizes
- Variable sequence lengths
- Processing one sample at a time
- Sequential models such as RNNs and Transformers
Layer Normalization solves these problems because every sample is normalized independently.
How Does Layer Normalization Work?
Input Sample↓
Calculate Mean
↓
Calculate Variance
↓
Normalize Features
↓
Scale Using γ
↓
Shift Using β
↓
Output Sample