ContentsThe library

The Mathematics of Attention

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.

FIG 1Two ways to slice the same activations
feature 1feature 2feature 3feature 4
example 11.2-0.40.82.1
example 20.31.7-1.10.5
example 3-0.90.21.4-0.3
Batch normalisation takes statistics down the marked column, mixing three examples. Layer normalisation takes them along a row, using one example's four features and nothing else.

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 contents

This 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

The rest of this course

  1. 01Why Attention Needs Three Matrices, Not One
  2. 02Where the Square Root of dkd_k Comes Fromopening only
  3. 03Why Softmax and Not Some Other Normalisationopening only
  4. 04One Weighted Average Is Not Enoughopening only
  5. 05Attention Cannot See Order, So Order Has to Be Addedopening only
  6. 06The Skip Connection Is the Main Roadopening only
  7. 07Why Transformers Normalise Across Features and Not Across the Batchyou are here
  8. 08The Half of the Transformer That Does Not Move Informationopening only

Read alongside