SproutStackSproutStack home

Transformer Architecture Simplified

5 min readBeginner-friendlyFree to read

Read a little, play a little. No scary maths, and no rush.

Share:

LEGO bricks, stacked 100 high

A transformer is one block design, repeated dozens of times. Tokens enter at the bottom as embeddings (meaning-vectors) plus position information (order matters in language). Each block refines every token's representation using context from all the others, then a final layer converts the top representation into next-token probabilities.

The star brick: self-attention

Consider "bank": river bank vs money bank. The word's meaning depends on its neighbors. Self-attention lets every token look at every other token and decide how much each matters: in "open an account at the bank," the tokens account and bank attend strongly to each other, and bank absorbs the financial meaning.

Mechanically: each token emits a query ("what am I looking for?"), keys ("what do I offer?"), and values ("what do I contribute?"). Query·key scores decide weights; values mix accordingly. Play /animations/attention to watch it happen.

The supporting bricks

  • Multi-head attention: several attention mechanisms in parallel — one tracks grammar, another tracks who-did-what-to-whom, another tracks long-range references. Different views, same text.
  • MLP (feed-forward): after mixing context, each token is processed alone through a small neural net — where much of the model's "knowledge" is thought to live.
  • Layer norm + residuals: training stabilizers that let 100-layer stacks actually learn instead of collapsing.
  • KV-cache: during generation, past keys/values are reused rather than recomputed — why the second token is cheaper than the first.

Following one sentence through the stack

Take "The animal didn't cross the street because it was too tired." What does "it" refer to? A person knows instantly; the model has to work it out.

In the first layers, "it" is just a pronoun with a position. As it passes up through the blocks, attention lets "it" look back at every earlier token. "Tired" is something animals get, not streets, so in later layers "it" attends strongly to "animal", and its representation now carries that link. Change the last word to "wide" and the same machinery points "it" at "street" instead.

No rule about pronouns was ever written. The model learned these patterns because resolving them made its next-token predictions better during training.

Encoders, decoders, and which one you are calling

The original transformer had two halves, and today's models usually use one:

  • Decoder-only models (the GPT family, and most chat models) generate text. Each token may only attend to tokens before it, never after, because when writing word 10 the model cannot peek at word 11. This is called a causal mask.
  • Encoder-only models (the BERT family) read a whole passage at once, looking both ways. They are not built to generate text, but they are excellent at understanding it, and many embedding models are built this way.

So when you call a chat API you are using a decoder, and when you embed documents for search you are often using an encoder.

Why builders should care (a little)

You won't design transformers, but the architecture explains the quirks: why long contexts cost and degrade (attention is quadratic-ish), why order and phrasing matter (position + attention), and why "show your work" prompting helps (more tokens = more mixing steps).

You don't need to derive softmax to use LLMs. Remember: context mixing + depth.

Remember this

  • Embeddings in, attention mixes context, MLP stores knowledge, repeat 12–100×.
  • Architecture explains behavior: cost, context limits, and phrasing sensitivity.

Check your understanding

5 questions · first-try answers earn the most XP

1. What is the job of self-attention inside a transformer block?
2. What components make up one repeated transformer block?
3. Why do long contexts get expensive and less reliable in a transformer?
4. What does the KV-cache store and reuse during text generation?
5. Why does the chapter say you do not need to derive softmax to work with these models?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.