0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09Hook: "Attention Is All You Need"
In two thousand seventeen, a team of researchers published a paper with a bold title: "Attention Is All You Need." It described a new architecture built mostly out of the self-attention we built last episode. They called it the transformer. It was designed for translation. Within a few years, transformers had reshaped the whole field. They're behind modern machine translation, search, code assistants, and the large language models that power chat assistants, and versions of them work on images and audio too. Today, the season finale: we assemble the complete machine, part by part, and you'll understand every component.
Then we'll fly over the whole of Season Two. Season Two, Module Ten, the final peak: the transformer.
1:02Positional encodings: giving attention a sense of order
First, a problem. Self-attention has no sense of order. If you shuffle the words, every word still produces the same output vector as before. Self-attention treats a sentence like a bag of tokens. But "dog bites man" and "man bites dog" are not the same news. The fix is to add a position signal to every token's embedding. The original transformer used waves: each position gets a pattern of sines and cosines at different frequencies. Position zero is zero, one, zero, one. Position one is zero point eight four, zero point five four, and so on.
Like the hands of a clock, the fast waves distinguish neighbouring positions, while the slow waves distinguish distant ones. Every position gets a unique fingerprint. Other designs learn a vector for each position directly, and many recent language models use a method called rotary position embeddings, which builds position information into the attention scores themselves. One caveat: this corner of AI moves quickly. These examples were current when we made this video, and they may look different on the day you watch it.
2:18Multi-head attention
Next, multi-head attention. One attention pattern can only capture one kind of relationship at a time. So the transformer runs several attention "heads" in parallel, eight in the original, each with its own query, key and value matrices, each working on a slice of the vector, sixty-four numbers out of five hundred and twelve. Different heads can learn to look for different things. One might link pronouns to the nouns they refer to, another might focus on the previous word, another on which adjective describes which noun.
Their outputs are glued back together and mixed by one more matrix. Counting the four matrices, query, key, value and output, each five hundred and twelve by five hundred and twelve, plus biases, the attention part of one layer has just over a million parameters.
3:11The feed-forward network
After the tokens have exchanged information through attention, each token goes through a small feed-forward network on its own: the same two-layer network, applied separately to every position. It expands each vector from five hundred and twelve numbers to two thousand and forty-eight, applies an activation, and shrinks it back. A helpful way to think of it: in attention, the tokens talk to each other. In the feed-forward network, each token processes what it has heard. And here's a surprising fact: with about two point one million parameters, the feed-forward part holds roughly two thirds of each layer's weights.
Researchers have found evidence that a lot of a language model's stored knowledge lives in these layers.
3:59Residual connections and layer norm (add & norm)
Every sub-layer, attention and feed-forward, is wrapped in two things you already know from episode twenty-eight. A residual connection adds the sub-layer's input back to its output, giving gradients a highway through the network. And layer normalisation keeps the values in a steady range. The original transformer normalised after adding the residual. Many later large models normalise before each sub-layer instead, which tends to make very deep models more stable to train. Dropout is applied too, during training.
4:35The full transformer block, stacked
Put it together and you get a transformer block: multi-head self-attention, add and normalise, then the feed-forward network, add and normalise. What comes out has exactly the same shape as what went in: one vector per token. So blocks can be stacked, one on top of another. The original model stacked six. One block of this size has about three point one five million parameters. The original base transformer, with its embeddings, had about sixty-five million. As we'll see in Season Three, today's large language models stack many more, wider blocks, reaching billions of parameters.
But the block itself is recognisably the same. As vectors rise through the stack, each layer refines them. Studies that probe these models suggest that lower layers tend to capture more local, grammatical patterns, and higher layers more abstract meaning.
5:36Encoder, decoder and cross-attention
The original transformer had two stacks, for translation. The encoder reads the source sentence with unmasked self-attention, so every word sees every other word. The decoder writes the translation. Its blocks have masked self-attention over the words written so far, plus an extra layer called cross-attention, where the decoder's queries look at the encoder's outputs. That's the same encoder–decoder attention from episode thirty-four, rebuilt from attention alone. At the very top, a final linear layer turns each vector into a score for every word in the vocabulary, and softmax turns the scores into next-word probabilities.
And thanks to the causal mask, training is massively parallel. Every position in a sentence learns to predict its next word at the same time, instead of one step after another as in an RNN. That speed is a big reason transformers could be trained on so much data.
6:37The transformer in 60 seconds
Here's the whole machine in one breath. Text becomes tokens. Tokens become embeddings, plus position signals. Then a stack of blocks: in each one, tokens exchange information through multi-head attention, masked if we're generating, then each token is processed by a feed-forward network, with residual connections and normalisation around both. At the top, a linear layer and softmax turn each token's final vector into probabilities for the next token. Every piece of that sentence is something you've now built: the dot product, softmax, embeddings, attention, ReLU-style activations, residuals, normalisation, cross-entropy and backpropagation.
7:24Three families: BERT, GPT and T5
From this one design grew three families. Encoder-only models, like BERT, from two thousand eighteen, keep the full, unmasked attention and are trained by hiding some of the words in a sentence and predicting them. They're excellent at understanding: classifying support tickets, powering search, finding similar reviews. Decoder-only models, like the GPT series, keep only the masked decoder and are trained to predict the next token. They're built for generating text, and they became the basis of most large language models.
And encoder–decoder models, like the original transformer and later T5, map one sequence to another, for translation and summarisation.
8:11Try it yourself: count a 124-million-parameter model
Let's count a real-sized model using exactly the formulas from this episode. Width seven hundred and sixty-eight, twelve heads, a feed-forward layer of three thousand and seventy-two, and twelve layers. Pause and estimate the total before we count.
Attention: about two point three six million per layer. Feed-forward: about four point seven two million. Add the layer norms, and one layer is just over seven million. Twelve layers: eighty-five million. Then the embedding table, about thirty-eight point six million for a vocabulary of fifty thousand two hundred and fifty-seven tokens, plus position vectors and a final layer norm. The total: a hundred and twenty-four million, four hundred and thirty-nine thousand, eight hundred and eight, about the size of a well-known small GPT-style model released in two thousand nineteen.
You can now count a real language model's parameters by hand.
9:16Predict: which transformer family fits the task?
Three Brightcart tasks: labelling reviews as positive or negative, drafting replies to customers, and translating product descriptions into French. Which family suits each? Pause. Labelling reviews is understanding, where seeing the whole text at once helps: an encoder-only model. Drafting replies is generating, word by word: a decoder-only model. Translation reads one sequence and writes another, the job the original encoder–decoder design was built for, though today large decoder-only models handle it well too. The families are design choices, not strict rules.
10:02Pre-norm vs post-norm
One small detail has a big effect. In the original transformer, layer normalisation came after the residual addition. Many later models move it before the sublayer instead, so the residual path runs as a clean highway from the input all the way to the output. This pre-norm arrangement tends to make very deep stacks easier to train, and some models use a simpler variant of normalisation as well. It's a reminder that architectures evolve through many small, tested improvements.
10:36How a transformer is trained
How is a decoder trained? Feed in a sentence, and thanks to the causal mask, every position predicts its next token at the same time, so one sentence provides many training examples at once. The losses are averaged, and backpropagation does the rest. The learning rate usually starts with a warm-up, rising from almost zero, then slowly decays, a recipe used since the original transformer paper, with Adam-style optimisers and dropout. Next season, we'll train a tiny transformer ourselves and watch it learn.
11:12The residual stream: a shared whiteboard
Here's a helpful way to picture a transformer. Think of each token's vector as a stream flowing through all the layers. Each attention layer and each feed-forward layer reads from the stream, computes something, and adds its result back in, never replacing what was there. It's like a shared whiteboard where every layer reads the board and adds a note. Many researchers who study how transformers work inside use exactly this picture.
11:42From a vector to the next word
And finally, how does the model pick the next word? The last position's final vector is compared with every token in the vocabulary, producing more than fifty thousand scores. Softmax turns them into probabilities: perhaps "shipped" is most likely after "Your parcel has", with "arrived" close behind. How we choose from those probabilities, always the top one or a little randomly, makes a big difference to the writing, and that's where Season Three begins.
12:14Myth vs Fact
Myth: transformers are only for language. Fact: anything that can be cut into a sequence of tokens can go through a transformer. Images are split into patches, audio into short frames, and the same architecture is used for vision, speech, biology and models that combine several kinds of data, as we'll see in Season Three.
12:37Season 2 finale: the flight over the mountains
And that's Season Two. Let's look back at the climb. We built a single artificial neuron, stacked neurons into networks, and learned how backpropagation trains every weight. We trained a digit reader from scratch, and learned the techniques that make deep networks train: better optimisers, initialisation, normalisation, dropout and residual connections. We taught networks to see, with convolutions, transfer learning and detection. We gave them memory, with RNNs and LSTMs. And finally we built attention and the transformer, the architecture behind modern AI.
Now look ahead: the pink valley of Season Three, generative AI. We'll train language models, from how they learn on enormous amounts of text, to scaling laws, to human feedback, to how they choose each word, and we'll build a tiny GPT ourselves. Then we'll learn how machines create images out of pure noise.
13:44Next: Season 3, how an LLM is trained
Mission complete, and Season Two complete. You've assembled the transformer, and you understand every part of it. Season Three begins with the biggest question in AI today: how does a large language model actually learn? By reading an almost unimaginable amount of text and predicting one token at a time. See you in the valley. Thank you for learning with MOFUSA Tech Academy.