Kolkata ·  
AI engineering
foundations
deep · 6 min

Transformer

The architecture behind LLMs: stacked attention and feed-forward layers. Concept level, no math derivations.

updated 23 Sept 2026

There's a page called Transformer Explainer that runs GPT-2 small right in your browser. Type a prompt, and you can click into every step it takes to pick the next word. GPT-2 small is from 2019 and tiny by today's standards, but it's built from the same parts as today's LLMs, so it's a good one to take apart. Let's give it this prompt and follow it through:

Data visualization empowers users to

The trip through

First the text is split into tokens, ids from a vocabulary of 50,257 (tokenization). Each id picks a row of 768 numbers from the embedding table (embeddings), and information about each token's position gets added in, so the model knows the order.

Then those vectors go up through 12 blocks. Each block takes one vector per token and hands back one vector per token, the same size, with a bit more context in it.

At the top, only the last position's vector is used. It gets turned into 50,257 scores, one per token in the vocabulary, and softmax turns the scores into probabilities. One token is picked and stuck on the end of the text, and the whole trip runs again. That's the loop from next-token prediction.

The two ends are plumbing. The interesting part is the stack of blocks in the middle. So what's in a block?

Two halves

Every block has the same two parts, in the same order.

First, attention. This is where tokens talk to each other. Each token looks back at the earlier ones and pulls in what it needs. After it, the vector for "users" carries some of "data visualization".

Second, a feed-forward network, also called the MLP. Here the tokens don't talk at all. The same small network runs on each token's vector on its own, all positions in parallel. In GPT-2 small it stretches each vector from 768 numbers to 3,072 and squeezes it back to 768.

So the work splits cleanly. Attention moves information between positions. The MLP works on what each position now holds.

You'd think attention, the famous part, would be most of the model. In GPT-3 it's about a third of the parameters, just under 58 billion of 175 billion. Most of the rest are in the MLPs.

A running total

Here's the detail that makes it all stack up. Neither half replaces a token's vector. Each one works out a change and adds it to the vector that came in.

So picture each token as one line running up through the model. The embedding starts it off. Each attention step reads from the line (and from earlier tokens' lines) and adds its change back on. Each MLP reads from the line and adds its own change. What reaches the top is the starting vector plus everything every layer added along the way.

Those add-it-back shortcuts are called residual connections, and they're what made very deep networks trainable in the first place. Each block also has normalisation steps that keep training stable. You can treat both as plumbing.

Stack it

One block can't do much, so the block gets copied, each copy with its own weights, and stacked. Block 2 works on vectors block 1 already filled with some context, and so on up.

ModelYearBlocksNumbers per token vectorParameters
GPT-2 small201912768124 million
GPT-320209612,288175 billion
DeepSeek V3202461not given here671 billion

That's the architecture: embed, a tall stack of attention-plus-MLP blocks, score. A model's size is mostly how many blocks and how wide the vectors are.

The original was built for translation

If you look up "transformer", you'll probably find a diagram with two towers. That's the original from 2017, "Attention Is All You Need", which was built for translation. One half, the encoder, read the whole source sentence, every word seeing every other. The other half, the decoder, wrote the translation one word at a time, looking at the encoder's output and at its own earlier words, never ahead.

Later models kept one half or both. Encoder-only models like BERT (2018) are good at understanding tasks, like classifying sentences. Encoder-decoder models like T5 suit tasks with an input and an output, like translation. GPT-style models are decoder-only. There's no separate encoder: your prompt and the answer are one sequence, read left to right, each token seeing only what came before. So when you look at that two-tower diagram for an LLM, keep the decoder side and drop its link to the encoder.

Why did this design win over what came before? Earlier language models were mostly recurrent: they read text one position at a time, each step waiting for the last, which made them slow to train on GPUs. A transformer has no such chain inside a text. Attention compares all positions at once and the MLP runs on all positions at once. The 2017 model reached top translation quality after as little as twelve hours on eight GPUs.

That same shape shows up in how long you wait for an answer. All the tokens of your prompt can go up the stack together. The answer can't: each new token needs the one before, so the model runs the whole stack once per output token. Those two phases are prefill and decode, and the stored keys and values that keep the second one affordable are the KV cache.

What's changed since GPT-2

Less than you'd guess. Put GPT-2 next to open models from 2024 and 2025 and the block is recognisably the same. Parts got swapped. Position information is now usually added by rotating vectors (RoPE) instead of a learned table. Most models use grouped-query attention, where heads share keys and values to save memory. Normalisation moved to before each half instead of after.

The biggest swap is mixture of experts. Instead of one MLP per block, there are many "expert" MLPs and a router that picks a few for each token. DeepSeek V3 has 256 experts per module and uses 9 per token, so only 37 billion of its 671 billion parameters do any work on a given token. When you compare model sizes, ask for both numbers.

Is the core still settled? Some 2025 models mixed in cheaper kinds of attention, and one lab went back after finding them weak on reasoning. That story is in attention. And all of this comes from papers and open-weight models. What's inside a closed model is a guess unless the lab published it.

Which brings us back to the browser. You can open an open model's config file now and read off its number of layers, vector width, heads and experts, and each one maps onto a part we just walked through. The architecture is the skeleton. A checkpoint is one set of trained weights for it.

Further reading