7/29
Part 2 of 5 · The blockLearn and do
The block: two steps, each added back
This is the heart of the model. Every block does two steps, and each step adds its result back to the tokens' vectors. Tap each piece of the picture:
The stream: each token's C numbers, (B, T, C). It runs through every block and is never replaced. Each step only adds to it.
Read the picture top to bottom:
- The line down the left is the stream: the tokens' vectors,
(B, T, C). It goes through every block, and it never gets replaced. Each step only adds to it. - Step 1, attention. Each token gathers information from the tokens before it. This is your multi-head attention, and it's the only place where tokens see each other.
- Step 2, the MLP. Each token works on its own vector, alone. It's two linear layers with a GELU between them: up to
4 * Cnumbers, then back down to C. GELU is a smooth version of ReLU. - LayerNorm, before each step. It rescales each token's C numbers so they have mean 0 and spread 1. Each step then gets inputs of a steady size, whatever happened in the blocks before.
In the editor, x is 2 sentences of 5 tokens with C = 8 numbers each. Build mlp with nn.Sequential, run it on x to get out, and count its weights and biases in n.