Inside the encoder, in 3D #3D#Architecture
Rotate the model and take it apart: embedding tables, feature stack, bridge, sequence stack and bottleneck.
Encoder architectureEmbeddings
Drag to rotate and click any block for what it does and how many parameters it holds. Tall plates read across fields; long plates read across time.
Transcript
The norm episode ended on a question: what does the whole encoder look like, and how big is it? Here it is: five blocks. Maya's card history flows down through all five, and out come sixty-four numbers per payment. Inside the five sit one point three million learnt numbers. By the end, you'll know what each block does, where those numbers sit, and what sits on top.
First, one word. A parameter is a learnt number: one the model adjusts in training. Each training step nudges it a little, up or down, toward a better guess. Our encoder has one million, two hundred and ninety-one thousand, one hundred and thirty-six of them. Counted on tfm-bench's own model, configured for the Sparkov data this season uses. Every size in this episode is that one.
Block one turns each field into a whole number, a token: like these real Sparkov amount bins, from the episode on tokens.
Each of the twelve fields has its own table: five hundred and eighty-five rows in all, one per token value. A token picks its row: sixty-four learnt numbers. Five hundred and eighty-five rows of sixty-four make thirty-seven thousand, four hundred and forty. Then a projection, one learnt matrix shared by all twelve fields, widens each field's sixty-four numbers to a hundred and twenty-eight. With its bias and a norm, that adds eight thousand, four hundred and forty-eight. Block one: forty-five thousand, eight hundred and eighty-eight.
Block two is field attention, from the episode on reading one payment. In the lab, every field scores every other.
In our model, a payment has twelve fields, so twelve field vectors read each other. Each adds a mix of what it read to what it already was. And no order among them: a receipt has none. Two layers of a hundred and ninety-seven thousand, eight hundred and eighty-eight: three hundred and ninety-five thousand, seven hundred and seventy-six.
You met the next two in the episode on habits. A payment arrives as twelve field tokens, and two field layers read it whole. Then the bridge folds its twelve field vectors into one.
Inside, one learnt query reads the twelve field vectors and weighs each one. The weighted mix becomes one vector per payment: a hundred and twenty-eight numbers. This attention pool costs forty-nine thousand, five hundred and thirty-six learnt numbers.
Block four is sequence attention, from the episode on query, key and value. A payment asks the earlier ones: who is like me?
Here each dot is eight of the card's payments. The newest reads back over the ones before it. Only inside a window: sixty-four payments, itself included, in a history of a hundred and twenty-eight. And never forward: no payment sees the one after it. Rotary positions turn each payment’s query and key by its place in the history: by order, not by clock time. Four layers, the same size as before: seven hundred and ninety-one thousand, five hundred and fifty-two.
Block five, the output, takes the stream's hundred and twenty-eight numbers and squeezes each payment to sixty-four. Those sixty-four numbers are the embedding: what the task heads read. Sixty-four is our base design. The lab in the episode on what a TFM is used two hundred and fifty-six: its own design. A norm and one small matrix: eight thousand, three hundred and eighty-four learnt numbers.
Here's what a language model doesn't have. It runs one attention, along a line of text. A TFM runs two. First across the fields of each payment, then the bridge folds each payment into one vector, and sequence attention reads across payments. A payment is a set of fields, and a card is a story of payments: two axes, two attentions.
Every one of those attention layers is the block from the norm episode: a vector riding a stream, carried from layer to layer. Norm, attention, add. Norm, feed-forward, add. Each part adds what it computed to what the stream already was.
Here are all six attention layers, two field and four sequence. Field or sequence, every one is the same size. A hundred and ninety-seven thousand, eight hundred and eighty-eight each: both kinds work on vectors of a hundred and twenty-eight numbers. Inside each, attention takes sixty-five thousand, five hundred and thirty-six. The two norms, just two hundred and fifty-six. The rest, about two thirds, is the feed-forward from the norm episode: a hundred and thirty-two thousand and ninety-six. Now three settings from earlier episodes: the window, the history length, and rotary positions. Each adds zero parameters. Rotation is a formula, not a table, so a longer history adds no learnt numbers. They change how much the model computes, not how big it is.
Follow one window through the shapes. In: a hundred and twenty-eight payments, twelve tokens each. The tables give each token sixty-four numbers. The projection widens each to a hundred and twenty-eight. Field attention and the bridge leave one vector of a hundred and twenty-eight per payment. Sequence attention and the bottleneck end at sixty-four numbers per payment.
Now the whole encoder as one bar, split by block. Together: one million, two hundred and ninety-one thousand, one hundred and thirty-six. Sequence attention holds sixty-one percent of it. Only because it has four layers to field attention's two, not because its layers are bigger. Beside it, the next-event head: the part that guesses each next payment in pretraining, the model's first training. Two hundred and thirty-two thousand, seven hundred and seventy-seven. The task heads that come later don't need it. With it: one million, five hundred and twenty-three thousand, nine hundred and thirteen. To recap: five blocks, one point three million learnt numbers, nine in ten in six identical layers, and settings like the window cost none.
And at the start, nearly every one of those numbers is random. No one labelled her payments. So how does it learn? That's the next episode: guess the next payment.