Why Transformers Normalise Across Features and Not Across the Batch
Last timeThe Residual Stream
Batch normalisation works well in vision and badly in language. The reason is about which axis the statistics are taken over, and it decides more than stability.
Normalisation is one of those components that gets described by what it does
rather than by what it is choosing. Both batch and layer normalisation subtract
a mean and divide by a standard deviation. The entire difference is which
numbers go into computing them.
The two axes
Arrange the activations as a table: rows are examples in the batch, columns are
features.
| feature 1 | feature 2 | feature 3 | feature 4 | |
|---|---|---|---|---|
| example 1 | 1.2 | -0.4 | 0.8 | 2.1 |
| example 2 | 0.3 | 1.7 | -1.1 | 0.5 |
| example 3 | -0.9 | 0.2 | 1.4 | -0.3 |
Batch normalisation asks: across all examples in this batch, what is the typical
value of feature 3? Layer normalisation asks: across all features of this
example, what is the typical value?
The consequences are not subtle. Under batch norm, the output for one example
depends on which other examples happen to be in the batch with it. Under layer
norm it does not, ever.
The lesson stops here
10 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents