The assembly
Every big idea you've learned so far, prediction, tokens, learning, embeddings, attention, is a building block. Alone, each one is pretty simple. Together, they form something remarkable.
Imagine building a tower out of LEGO. Each brick is just a brick. But when you stack them in the right order, you get a skyscraper.
That's exactly what a transformer is: all these simple ideas, stacked together in a specific way. The transformer processes the text you give it right now, but all its knowledge comes from the training data it read before, billions of sentences from books, websites, and more, compressed into its weights.
You already understand every piece. Now let's see how they fit.
The flow
Watch the diagram on the right. Press "Play" and follow the dot as it moves through the transformer.
Data flows in one direction: top to bottom. Text goes in, gets transformed step by step, and a prediction comes out.
You can click on any stage to learn more about it. You can also use "Step" to move through one stage at a time.
Notice how every stage you click connects back to something you've already learned. There's nothing new here, just a new way of combining familiar pieces.
Loading activity…
Embedding layer
Remember embeddings? Words that mean similar things live close together in a giant number space.
The embedding layer is the transformer's front door. Every token that enters gets looked up in a big table and swapped for its vector of numbers.
After this step, the transformer doesn't see words anymore. It sees patterns of numbers, and those patterns carry meaning. "King" and "queen" start out with similar numbers. "Cat" and "refrigerator" start far apart.
This is the foundation that everything else builds on.
Attention layer
Now comes the magic ingredient: attention.
After embedding, every token knows about itself but nothing about its neighbors. The attention layer fixes this. Each token gets to "look around" at all the other tokens and figure out which ones are important.
When the model reads "The cat sat on the mat because it was tired," the attention layer is how "it" figures out it's talking about the cat, not the mat.
This is the heart of the transformer. It's what makes these models so good at understanding language.
Feed-forward layer
After attention, each token knows about its neighbors. But it hasn't had time to "think" about what all that information means.
That's what the feed-forward layer does. Think of it as the "processing" step. Attention is "gathering information," and the feed-forward layer is "making sense of it."
It's like reading a sentence (attention) and then pausing to think about what it means (feed-forward). Each token processes its gathered information independently, kind of like everyone in a room thinking quietly after a group discussion.
Stack and repeat
Here's a secret: the transformer doesn't do attention and thinking just once. It does it over and over, many times in a row.
Imagine re-reading a paragraph. The first time, you get the basic meaning. The second time, you notice connections you missed. The third time, you understand the deeper implications.
That's what stacking layers does. Each layer refines the model's understanding. Early layers catch simple patterns, like which words go together. Later layers grasp harder things, like sarcasm, logic, or what "it" refers to in a complex sentence.
Modern models stack 32, 64, even 96 layers deep.
Final prediction
After all that processing, embedding, attention, thinking, repeating, the transformer has one final job: pick a word.
The numbers that come out of the last layer get converted back into scores for every word the model knows. The word with the highest score wins.
And then? The model takes that word, adds it to the sentence, and does the whole thing again to pick the next word. And the next. And the next.
That's it. That's the entire process. From text to tokens to numbers to attention to prediction, one word at a time. And you now understand every step of it.
You made it
Congratulations. You now understand how AI language models work, from the ground up.
Let's recap everything you've learned:
Prediction: AI generates text by predicting the next word, one at a time.
Tokens: Text gets broken into small pieces the model can handle.
Learning: The model starts bad and gets better by adjusting itself based on its mistakes.
Embeddings: Words become numbers that capture meaning, similar words get similar numbers.
Attention: The model figures out which words are important for understanding each other.
The Full Picture: All these pieces stack together into a transformer.
The next time someone talks about GPT, LLaMA, or any AI model, you'll know what's happening under the hood.
Ready for the next lesson?
Answer 2 remaining questions above to finish this lesson.