Part 14
Visual Learning Resources
ten interactive guides that show how AI works
Ten visual and interactive resources that let you see inside a language model: Transformer Explainer, LLM Visualization, 3Blue1Brown, The Illustrated Transformer, TensorFlow Playground, a visual guide to attention variants, a visual guide to mixture of experts, the LLM Inference Handbook, Neuronpedia, and Embedding Atlas. Each section explains what the resource shows, how to use it in minutes, and what to check, with its own diagram, a worked example, a layman's version, and a practice task. প্রতিটি টপিকের সাথে বাংলা ব্যাখ্যাও আছে।
10 sections · 32 sources · three voices
01
Transformer Explainer: watch a model predict the next token
A live GPT-2 in your browser. See tokens, embeddings, attention, and sampling in the order they happen.
Live view · 1 page
Transformer Explainerpoloclub.github.ioOpen in a new tab ↗ Pick an example or type a prompt, press Generate, and click a token to follow it through the model. The page downloads GPT-2 into your browser, so the first load can take a while.
The page loads from its own site when you click. Works best on a wide screen.
Transformer Explainer is a free web page from the Polo Club of Data Science at Georgia Tech. It runs a live GPT-2 (small) model inside your browser. You type a prompt, and the page shows every stage that turns your text into a prediction for the next token.[2][1]
Open it: poloclub.github.io/transformer-explainer. No install and no account. The model runs on your own machine, so your text does not leave the browser.[1]
What the page shows
GPT-2 (small) has 124 million parameters. That is tiny next to a modern chat model, but its design is the same: a stack of transformer blocks that predicts one token at a time.[2][3]
| Stage | What happens | GPT-2 (small) numbers |
|---|---|---|
| Tokenize | Text is cut into tokens. Each token gets an integer id. | Vocabulary of 50,257 tokens |
| Embed | Each id becomes a vector. A position vector is added, so the model knows the order. | 768 numbers for each token |
| Attention | Each token looks at the earlier tokens and takes in the useful ones. Several heads do this in parallel. | 12 heads in each block |
| MLP | A small network refines each token on its own. | Expands 768 to 3,072, then back |
| Repeat | The attention and MLP pair repeats. Each repeat is one transformer block. | 12 blocks |
| Output | The last vector becomes one score for every token in the vocabulary. Softmax turns the scores into probabilities. | 50,257 probabilities |
| Sample | One token is picked from the probabilities. Temperature, top-k and top-p control this pick. | One new token |
Temperature, top-k and top-p, with numbers
The page has sliders for the three sampling settings. Each setting changes the pick from the probability list, not the model itself.
- Temperature
T: divide every score byTbefore softmax. A smallTmakes the top token even more likely. A largeTflattens the list. - Top-k: keep only the
kmost likely tokens, then pick among them. - Top-p: keep the smallest group of tokens whose probabilities add up to at least
p, then pick among them.
softmax(score / T). Real models have 50,257 candidates, not five.softmax(score / T) দিয়ে হিসাব করা। আসল মডেলে পাঁচটির জায়গায় ৫০,২৫৭টি candidate থাকে।At T = 0.5 the top token “mat” takes about 76% of the probability. At T = 2.0 it takes about 37%, and the unlikely word “moon” grows from under 0.1% to 6%. This is why a high temperature gives more creative text and also more mistakes.
A 10-minute path through the page
- Pick an example prompt, or type The cat sat on the. Press Generate.
- Click a token. Watch the page zoom from the embedding to the attention stage.
- Open the attention view. Hover over a token and see which earlier tokens it reads.
- Set temperature to
0.2, generate three times, then set it to1.5and generate three times. Compare the answers. - Set top-k to
1. The output is now the same every time. This is greedy decoding.
Know the limit. GPT-2 (small) is from 2019. It shows the shape of a transformer, not the quality of a modern model. Newer models change parts of the design, such as how attention heads share keys and values (see section 6) and how the MLP is split into experts (see section 7).
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Predict the next word, then check it in the explainer
Why this matters
A language model only ever answers one question: what token comes next? You will see the answer as a list of chances, not as one word.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. It asks for a list of chances.
Prompt Finish this sentence. Do not write the sentence again. The cat sat on the Give me the 5 most likely next words. For each word, give your best guess of its percentage chance. The five percentages must add up to about 100%. Show a small table only.
You should see: A list of five words with percentages. The percentages add up to about 100%. One word is clearly the top choice.
Example answer
| Word | Chance | |---|---| | mat | 45% | | floor | 20% | | couch | 15% | | bed | 12% | | roof | 8% |
Your answer will be worded differently.
Step 2
Same chatOpen Transformer Explainer. Type The cat sat on the and press Generate. Look at the list of next-token probabilities.
You should see: A list of candidate tokens with real probabilities from GPT-2. The top words are common places or objects, such as a floor, a bed, or a couch. They may differ from the chat answer. That is fine.
Step 3
Same chatIn the explainer, move the temperature slider to
0.2, then to2.0. Generate each time. In the chat, ask: Why does a high temperature give stranger words?You should see: At
0.2the top word wins almost every time. At2.0rare words appear. The chat answer says that a high temperature flattens the probabilities.
What just happened
A model produces a list of chances for every token. A sampling setting then picks one. Temperature changes how flat the list is.
You are done when You saw the same idea in two places: an estimate from a chat model and the real numbers from GPT-2.
Check yourselfYou set top-k to 1. Will the output change if you generate twice?Show answer
No. With top-k = 1 the model always picks the single most likely token. This is greedy decoding, so the output is the same each time.
Watch · 3 videos
Transformers, the tech behind LLMs | Deep Learning Chapter 5 3Blue1Brown
[Demo Video] Transformer Explainer: Learning LLM Transformers with Interactive Visual Explanation Polo Club of Data Science @ Georgia Tech
Transformers Explained Visually: Learn How LLM Transformer Models Work Polo Club of Data Science @ Georgia Tech
02
LLM Visualization: a 3D tour inside a GPT
Fly through the layers of a GPT-style model. See the real size of every matrix and follow one token from input to output.
Live view · 1 page
LLM Visualizationbbycroft.netOpen in a new tab ↗ Press Continue to start the guided walkthrough. Pick a model at the top: GPT-2 (small), nano-gpt, GPT-2 (XL), or GPT-3. Use the full-screen button for a bigger view.
The page loads from its own site when you click. Works best on a wide screen.
LLM Visualization is a 3D walkthrough of a GPT-style model. Brendan Bycroft built it. Every number inside the model is drawn as a small cube. You fly through the model and read a guided text that explains each step, from the input tokens to the output probabilities.[4][5]
Open it: bbycroft.net/llm. Use a desktop browser. The page is a 3D scene and a phone screen is too small for it. Scroll, or use the walkthrough buttons, to move forward.
What the page shows
The page includes these four models: nano-GPT, GPT-2 (small), and GPT-2 (XL), and GPT-3. They share one design, so the shapes below are the same kind of object at four sizes. The GPT-3 row uses the sizes from its paper.[5][32]
| Model | Positions (T) | Width (C) | Heads | Blocks | Vocabulary | Parameters |
|---|---|---|---|---|---|---|
| nano-GPT | 11 | 48 | 3 | 3 | 3 | about 86K |
| GPT-2 (small) | 1,024 | 768 | 12 | 12 | 50,257 | about 124M |
| GPT-2 (XL) | 1,024 | 1,600 | 25 | 48 | 50,257 | about 1.56B |
| GPT-3 | 2,048 | 12,288 | 96 | 96 | 50,257 | about 175B |
nano-GPT is the one the guided walkthrough uses. It has a vocabulary of only 3 tokens (the letters A, B and C) and sorts a short string of them. It has about 85,584 parameters, which is small enough that the page can draw every weight. For a minimal GPT in code, read Andrej Karpathy's nanoGPT next.[6]
Why a 3D picture helps
- You see the size of things. A weight matrix of 768 × 2,304 looks very different from a bias vector of 768 numbers. A formula hides this. The 3D scene does not.
- You see the data flow. A cube leaves one stage and enters the next. You can follow one position all the way through.
- You see the same block repeat. GPT-2 (small) has 12 identical blocks. Once you understand one, you understand all of them.
- You can compare sizes. Switch from nano-GPT to GPT-2 (XL). The shape stays the same. Only the numbers get bigger.
A 15-minute path through the page
- Start the walkthrough on nano-GPT. Read the Embedding step. Find the token embedding and the position embedding. They are added.
- Move to Self-Attention. Find the three matrices Q, K and V. Find the 11 × 11 attention map and the masked area above the diagonal. That area is the causal mask: a token cannot read the future.
- Move to the MLP step. Find the 4× wider middle layer. For nano-GPT it is 48 → 192 → 48.
- Move to the Output step. Find the logits and the softmax. They match the last two steps in section 1.
- Switch the model to GPT-2 (small). Look at the 12 blocks stacked in a row. Zoom in on one block and check that it is the same as the nano-GPT block, only wider.
Know the limit. The page shows one forward pass of fixed models. It does not train anything, and it does not show newer parts such as grouped-query attention or mixture of experts. Use it to build a clear picture, then read the formulas in section 4.
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Count the numbers inside a tiny model
Why this matters
A model is a big pile of numbers. When you count them once by hand, the words parameter and width stop being vague.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. It uses the real nano-GPT shape from the page.
Prompt A tiny GPT model has these sizes: vocabulary 3, positions 11, width C = 48, 3 transformer blocks. Each block has: two layer norms (2 × 48 weights and 2 × 48 biases in total for both), one attention layer (a 48 × 144 matrix and 144 biases for Q, K, V; then a 48 × 48 matrix and 48 biases for the output), and one MLP (48 × 192 plus 192 biases, then 192 × 48 plus 48 biases). The output layer shares its weights with the token embedding. There is one final layer norm (2 × 48). Count the parameters. Show a table: token embedding, position embedding, one block, three blocks, final layer norm, total. Show the arithmetic.
You should see: A short table. The token embedding has 144 parameters (3 × 48). The position embedding has 528 (11 × 48). The total for the whole model is close to 85,000.
Example answer
| Part | Parameters | |---|---| | Token embedding 3 × 48 | 144 | | Position embedding 11 × 48 | 528 | | One block | 28,272 | | Three blocks | 84,816 | | Final layer norm | 96 | | Total | 85,584 |
Your answer will be worded differently.
Step 2
Same chatOpen bbycroft.net/llm on a desktop browser. Start the walkthrough. Find the Embedding step and look for the sizes of the token table and the position table.
You should see: A token table with 3 rows and a position table with 11 rows. Each row has 48 numbers. This matches your count.
Step 3
Same chatIn the chat, ask: If I change the width C from 48 to 96 and keep everything else, how many parameters does the model have now? Show the arithmetic.
You should see: A number close to 337,000. The parameter count grows roughly by 4× when the width doubles, because most weight matrices are C × C or C × 4C.
What just happened
Parameters live mostly in the weight matrices of the blocks. When the width doubles, the count grows by about four times.
You are done when You counted the parameters of a small GPT by hand and checked the shapes in a 3D picture.
Check yourselfWhy is the attention map in nano-GPT 11 × 11?Show answer
Each of the 11 positions can look at positions before it. So the map has one row and one column for every position. The upper triangle is empty because of the causal mask.
Watch · 4 videos
03
3Blue1Brown: neural networks and transformers, animated
Seven short lessons that build from one neuron to the attention and MLP layers inside an LLM.
Live view · 1 page
3Blue1Brown: Neural networks3blue1brown.comOpen in a new tab ↗ The lesson list of the series. Start with But what is a neural network?. The videos below play the lessons on this page.
The page loads from its own site when you click. Works best on a wide screen.
3Blue1Brown is Grant Sanderson's math channel. Its Neural networks series explains deep learning with animations. The last three chapters cover transformers, attention, and how an LLM can store facts. This is the best first stop if you want the idea before the code.[7]
Open it: 3blue1brown.com, topic: neural networks. The same site also has series on linear algebra and calculus. They give the math behind the chapters below.
The seven chapters
| # | Chapter | The idea you take away | Where it shows up in this site |
|---|---|---|---|
| 1 | But what is a neural network? | Layers of neurons. Each neuron holds a number. Weights and biases are the knobs. A network for handwritten digits has about 13,000 of them. | Section 5 (TensorFlow Playground) |
| 2 | Gradient descent, how neural networks learn | A cost function scores the network. The negative gradient tells you which way to turn the knobs to lower the cost. | Section 5 |
| 3 | Backpropagation, intuitively | Each training example nudges every weight. Backpropagation finds the size of each nudge. | Section 5 |
| 4 | Backpropagation calculus | The chain rule explains why backpropagation works. | Optional math |
| 5 | Transformers, the tech behind LLMs | Tokens, embeddings, attention, MLP, and softmax with temperature. | Section 1 (Transformer Explainer), section 2 |
| 6 | Attention in transformers, step-by-step | Queries, keys, values, the causal mask, and multiple heads. | Section 4 (Illustrated Transformer), section 6 |
| 7 | How might LLMs store facts | The MLP layers hold much of the model's knowledge. Many ideas share the same neurons. | Section 9 (Neuronpedia), section 7 |
Gradient descent in six lines
Chapter 2 is the key to all training, including the training of an LLM. The idea fits in one loop. Measure the slope of the loss, then move the weight a little in the downhill direction. Repeat.[7]
# Gradient descent on a one-weight "network": loss = (w - 3)**2 + 1
w, lr = 0.0, 0.3
for step in range(5):
grad = 2 * (w - 3) # slope of the loss at this w
w = w - lr * grad # take a step downhill
print(step, round(w, 3))
# 0 1.8
# 1 2.52
# 2 2.808
# 3 2.923
# 4 2.969A real network has billions of weights, not one. The loop is the same. The slope becomes a long list of slopes, one for each weight, and backpropagation (chapters 3 and 4) computes all of them in one pass.
How to watch the series
- Watch chapters 1 and 2 first, even if you know the words. The pictures of weights and cost fix the vocabulary.
- Pause before each result and guess what the next picture will show. This is much more effective than watching passively.
- Watch chapter 5 together with section 1. Switch between the video and Transformer Explainer.
- Watch chapter 6 together with section 4. Pick the same example sentence in both.
- Skip chapter 4 on a first pass. Come back to it when you want the proof.
Know the limit. The videos teach ideas, not production code. They use simple networks and they do not cover newer designs such as grouped-query attention or mixture of experts. Use sections 6 and 7 for those.
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Run gradient descent by hand, then break it
Why this matters
Training an LLM is gradient descent at a huge scale. If you can do three steps on one weight, you understand the loop.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. It asks for three steps with exact numbers.
Prompt A model has one weight w. Its loss is (w - 3)^2 + 1. The slope of the loss is 2 * (w - 3). Start at w = 0. Use a learning rate of 0.3. Apply the rule w_new = w - 0.3 * slope. Do 3 steps. Show a table with the columns: step, slope, new w. Show the arithmetic.
You should see: A table with three rows. After step 1 the weight is 1.8. After step 2 it is 2.52. After step 3 it is 2.808.
Example answer
| Step | Slope | New w | |---|---|---| | 1 | 2 × (0 − 3) = −6 | 0 − 0.3 × (−6) = 1.8 | | 2 | 2 × (1.8 − 3) = −2.4 | 1.8 + 0.72 = 2.52 | | 3 | 2 × (2.52 − 3) = −0.96 | 2.52 + 0.288 = 2.808 |
Your answer will be worded differently.
Step 2
Same chatCheck step 1 with a calculator:
0 − 0.3 × (2 × (0 − 3)). Then watch the first half of chapter 2 on the 3Blue1Brown page and find the picture of the ball rolling down the cost surface.You should see: 1.8. The chat answer matches. The video shows the same idea in many dimensions.
Step 3
Same chatCopy this prompt, paste it in the same chat, and press Enter. It uses a step size that is too big.
Prompt Same loss and same start, but now use a learning rate of 1.1. Do 3 steps. Then explain in two sentences why the loss does not go down.
You should see: The weight jumps past the bottom and the steps get bigger: 6.6, then −1.32, then about 8.18. The loss is growing, not shrinking.
Example answer
Step 1: w = 0 − 1.1 × (−6) = 6.6 Step 2: w = 6.6 − 1.1 × 7.2 = −1.32 Step 3: w = −1.32 − 1.1 × (−8.64) = 8.184 Each step jumps over the bottom and lands farther away. The step is too large, so the loop diverges.
Your answer will be worded differently.
What just happened
Gradient descent is a loop: measure the slope, step downhill. The learning rate sets the step size. A step that is too large makes training fail.
You are done when You ran the training loop for one weight and saw it converge and diverge.
Check yourselfWhy do real LLM training runs often start with a small learning rate and increase it slowly?Show answer
At the start the weights are random and the slopes are noisy. Large steps can throw the weights far away, as in the last step above. A small first step is safer.
Watch · 6 videos
But what is a neural network? | Deep learning chapter 1 3Blue1Brown
Gradient descent, how neural networks learn | Deep Learning Chapter 2 3Blue1Brown
Backpropagation, intuitively | Deep Learning Chapter 3 3Blue1Brown
Transformers, the tech behind LLMs | Deep Learning Chapter 5 3Blue1Brown
Attention in transformers, step-by-step | Deep Learning Chapter 6 3Blue1Brown
How might LLMs store facts | Deep Learning Chapter 7 3Blue1Brown
04
The Illustrated Transformer: Q, K and V, explained with pictures
Jay Alammar's classic walk through the transformer, with one drawing for each step of attention.
Live view · 1 page
The Illustrated Transformerjalammar.github.ioOpen in a new tab ↗ The full post, live. Read the self-attention part first. Scroll inside the frame, or open the post in a new tab for the full width.
The page loads from its own site when you click. Works best on a wide screen.
The Illustrated Transformer is a blog post by Jay Alammar from 2018. It walks through the paper Attention Is All You Need with one drawing for each step.[8][3] Many readers still call it the clearest explanation of queries, keys and values (Q, K and V).
Open it: jalammar.github.io/illustrated-transformer. It is a long page. Read it in two sittings: self-attention first, then the rest.
Q, K and V in one picture
Every token creates three vectors from its own embedding. The three vectors have three different jobs:
- Query (Q): what this token is looking for.
- Key (K): a label that says what this token offers.
- Value (V): the content that this token hands over when someone picks it.
A token compares its query with the key of every token it may read. A high match gives a high score. Softmax turns the scores into weights that add up to 1. The token then takes a weighted sum of the values. The result is a new vector that holds information from the tokens that matter.[3][8]
A worked example with numbers
Use two tokens, a key size d_k = 2, and these vectors. Token 1 asks the question. Token 1 has query q = [1, 0].
| Token | Key k | Value v | Score q·k | Scaled (÷ √2) | Weight (softmax) |
|---|---|---|---|---|---|
| 1 | [1, 0] | [1, 2] | 1 | 0.707 | 0.670 |
| 2 | [0, 1] | [3, 4] | 0 | 0.000 | 0.330 |
The output is 0.670 × [1, 2] + 0.330 × [3, 4] = [1.66, 2.66]. The output sits closer to the value of token 1, because its key matched the query better.
The size of the original model
The post follows the base model of the paper. Its sizes give a feel for real numbers:[3][8]
| Piece | Size in the base model | Job |
|---|---|---|
Embedding width d_model | 512 | Length of the vector for each token |
| Heads | 8 | Eight attention patterns in parallel |
| Q, K, V per head | 64 numbers each | Small spaces where tokens are compared |
| Scale factor | √64 = 8 | Stops the scores from growing too large |
| Feed-forward layer | 512 → 2,048 → 512 | Refines each token on its own |
| Layers | 6 encoder + 6 decoder | Each layer repeats attention and feed-forward |
What the post covers, in order
- Embeddings and positional encoding: the model adds a position signal, because attention alone does not know the order.
- Self-attention: Q, K, V, scores, scaling, softmax, weighted sum.
- Multi-head attention: eight copies with different weights. The outputs are joined and projected back to 512 numbers.
- Residual connections and layer normalisation around each sub-layer.
- The decoder: masked self-attention (no peeking ahead), then encoder-decoder attention, where Q comes from the decoder and K and V come from the encoder.
- The last linear layer and softmax, which turn the final vector into word probabilities.
What changed since the post
| In the post | In most LLMs today |
|---|---|
| Encoder and decoder stacks (made for translation) | Decoder only (GPT style). No encoder, no encoder-decoder attention. |
| Sinusoidal position signal added to the input | Often rotary position embedding (RoPE), applied inside attention[31] |
| Every head has its own K and V | Heads often share K and V (see section 6) |
| Attention was invented for RNN translation[9] | Attention is the core of the whole model[3] |
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Compute attention for two tokens, then ask why we divide
Why this matters
Attention is only a few multiplications and one softmax. When you do them once, the formula stops looking like magic.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. The numbers are the same as in the worked example above.
Prompt Compute one step of scaled dot-product attention by hand. Query q = [1, 0]. Key 1 = [1, 0], Key 2 = [0, 1]. Value 1 = [1, 2], Value 2 = [3, 4]. The key size d_k is 2. Show: the scores q·k, the scaled scores (divide by sqrt(d_k)), the softmax weights, and the final output vector. Round to 3 decimals.
You should see: Weights near 0.670 and 0.330. The output is near [1.66, 2.66].
Example answer
Scores: 1 and 0. Scaled: 0.707 and 0. Softmax weights: 0.670 and 0.330. Output: 0.670 × [1, 2] + 0.330 × [3, 4] = [1.660, 2.660].
Your answer will be worded differently.
Step 2
Same chatOpen The Illustrated Transformer. Find the step where the scores are divided by 8. Then copy this question into the same chat.
Prompt Why do we divide the scores by sqrt(d_k) before softmax? Answer in 3 short sentences. Use the case d_k = 64 as an example.
You should see: The post divides by 8, which is the square root of 64, the key size in the base model.
Example answer
Dot products of long vectors grow with the vector size. For d_k = 64 the scores can be around eight times larger than for d_k = 1. Large scores push softmax to nearly 0 and 1, so the gradients become tiny. Dividing by 8 keeps the scores in a range where softmax still learns.
Your answer will be worded differently.
Step 3
Same chatAsk the chat: In the sentence “The animal didn't cross the street because it was too tired”, which word does “it” attend to? What changes if we replace “tired” with “wide”?
You should see: Animal for the first sentence. Street for the second. The meaning of the last word changes what it points to.
What just happened
Attention is match, normalise, blend: compare Q with K, turn the scores into weights, then mix the V vectors.
You are done when You computed one attention step by hand and checked the reason for the scale factor.
Check yourselfA token has a very high score for token 2 and a very low score for token 1. What does its output look like?Show answer
It is almost equal to the value vector of token 2, because softmax gives token 2 a weight near 1.
[0, 1] and ask the chat to redo the calculation. Predict first which value the output will be close to.Watch · 4 videos
Attention in transformers, step-by-step | Deep Learning Chapter 6 3Blue1Brown
A gentle visual intro to Transformer models Hugging Face
Learn how ChatGPT and DeepSeek models work: How Transformer LLMs Work [Free Course] Jay Alammar
The Illustrated Transformer: Jay Alammar's Classic, Read and Highlighted Standarity
05
TensorFlow Playground: train a tiny network and break it
A small neural network in your browser. Change one setting at a time and see what it does to learning.
Live view · 1 page
TensorFlow Playgroundplayground.tensorflow.orgOpen in a new tab ↗ The circle dataset with only X1 and X2 is ready. Press play, then try the experiments in the list below: add the squared features, add a hidden layer, or set the activation to Linear.
The page loads from its own site when you click. Works best on a wide screen.
TensorFlow Playground is a tiny neural network that trains in your browser. You pick a dataset, choose the inputs and the layers, press play, and watch the network learn a boundary between two classes.[10][11]
Open it: playground.tensorflow.org. It needs no install. The training runs on your own machine. The authors describe the design in a paper on direct-manipulation visualization.[11]
What every control does
| Control | What it changes | What to try |
|---|---|---|
| Data | The shape of the two classes: circle, exclusive or (XOR), Gaussian, spiral | Start with circle, end with spiral |
| Features | Which inputs the network sees: X1, X2, X1², X2², X1X2, sin(X1), sin(X2) | Turn a feature off and see if the problem becomes harder |
| Hidden layers and neurons | The size of the network. Each neuron draws one line or curve. | Zero layers, then one layer with 2 neurons, then 4 |
| Activation | The curve applied after each neuron: ReLU, Tanh, Sigmoid, Linear | Switch to Linear and watch the boundary stay straight |
| Learning rate | How big each step of gradient descent is | 0.03 learns well. 10 jumps around. |
| Noise | How many points land on the wrong side by accident | Raise it to 40 to simulate messy data |
| Regularization (L1, L2) and rate | A penalty on large weights | Use L2 to calm a network that fits the noise |
| Ratio of training to test data | How many points are used for learning and how many for checking | Compare training loss and test loss |
Five experiments that teach one idea each
- A line is not enough. Choose the circle dataset. Use only X1 and X2, with no hidden layers, and press play. The loss stays high. One neuron can only draw a straight line.
- A good feature can replace depth. On the same data, turn on X1² and X2². The loss drops to near zero within seconds. In the new feature space the ring becomes a straight line (see the figure below).
- Hidden layers learn their own features. Turn the squared features off again and add a hidden layer with 3 or 4 neurons. The network now finds the circle by itself. Hover over a neuron to see the shape it draws.
- A linear activation stays linear. Set the activation to Linear and add many layers. The boundary is still a straight line. A stack of linear steps is one linear step.
- Training can fail. Set the learning rate to 10 and watch the loss jump. Then set noise to 40, make the network large, and compare training loss with test loss. A big gap means the network learned the noise (overfitting).
X1² + X2² = r² becomes the straight line u + v = r².X1² + X2² = r² সোজা রেখা u + v = r² হয়ে যায়।How this connects to an LLM
The playground uses the same four steps that train an LLM:
- Forward pass: the inputs flow through the weights to an output.
- Loss: a number says how wrong the output is.
- Backward pass: the slope of the loss for every weight is computed (see section 3).
- Update: every weight takes a small step downhill. The learning rate sets the step size.
An LLM does the same on text. It has billions of weights instead of about 25, and its output is a probability for each token instead of one class.
Know the limit. The playground uses two input numbers and small data. It cannot show attention, tokens, or scale. Treat it as a gym for the training loop, not as a model of an LLM.
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Predict, test and explain: why the circle needs more than a line
Why this matters
A good habit is to predict a result before you run an experiment. Then the result teaches you something, whichever way it goes.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. It asks for a prediction.
Prompt A classifier can draw only one straight line. The data has two classes in 2D. Class A is a filled disc around the origin (radius up to 1.5). Class B is a ring around it (radius from 2.2 to 3.1). Can one straight line separate the classes using only the inputs x1 and x2? If not, name one extra feature that makes it possible and explain in two sentences why. Do not use more than 70 words.
You should see: The answer says no, one straight line cannot split the classes. It suggests a feature such as X1² + X2² (the distance from the centre).
Example answer
No. Every line leaves part of the ring on both sides of the disc. Add the feature x1² + x2², which is the squared distance from the centre. In that feature, class A has small values and class B has large values, so a single threshold separates them.
Your answer will be worded differently.
Step 2
Same chatOpen playground.tensorflow.org. Choose the circle dataset. Turn on only X1 and X2. Remove all hidden layers. Press play and wait 10 seconds. Then turn on X1² and X2².
You should see: With X1 and X2 only, the loss stays near 0.5 and the background stays muddy. After you add the squared features, the loss falls close to 0 and the dots split cleanly.
Step 3
Same chatBack in the chat, ask: I set the activation to Linear and added three hidden layers. Will the circle be solved with only X1 and X2? Explain. Then try it in the playground.
You should see: The chat says no. A stack of linear layers is still linear. The playground confirms: the boundary stays a straight line.
What just happened
A network can only draw boundaries that its features and activations allow. A better feature, or a non-linear activation with a hidden layer, solves a problem that a line cannot.
You are done when You predicted, tested, and explained a result. This is how you check a model idea.
Check yourselfWhy does adding hidden layers with a Linear activation not help?Show answer
Each linear layer multiplies and adds. A chain of such steps equals one multiplication and one addition. So the whole network is still linear and draws a straight line.
Watch · 3 videos
Deep Learning 101: Tensorflow Playground Prof. Ryan Ahmed
TensorFlow Playground Demo (Beginner Friendly) Byte Size ML
Neural Network Demonstration with TF Playground IIT Madras - B.S. Degree Programme
06
A Visual Guide to Attention Variants: MHA, GQA, MLA, sliding window and more
How modern LLMs make attention cheaper for long inputs, compared side by side.
Live view · 2 pages
LLM Architecture Gallery (Sebastian Raschka)sebastianraschka.comOpen in a new tab ↗ A gallery of model cards from the same author. Use it to check which attention variant a model uses, and compare it with the table in this section.
The page loads from its own site when you click. Works best on a wide screen.
A Visual Guide to Attention Variants in Modern LLMsmagazine.sebastianraschka.comOpen in a new tab ↗ The article for this section, with all of its diagrams. The publisher does not allow it inside other sites, so open it in a new tab.
Open in a new tab ↗
A Visual Guide to Attention Variants in Modern LLMs is an article by Sebastian Raschka (22 March 2026). It compares the attention designs that open-weight models use today, with a diagram for each.[12] The goal is simple: every variant tries to make attention cheaper for long inputs, in memory, in compute, or in both.
Open it: magazine.sebastianraschka.com/p/visual-attention-variants. The article also points to the author's gallery of LLM architecture model cards.
Why there are so many variants
Standard attention (MHA) has two costs that grow with the length of the input. The first is the KV cache: the model stores the keys and values of every earlier token, so it does not recompute them for each new token. The second is the compute of comparing every token with every earlier token, which grows with the square of the length.[12][3]
Each variant attacks one of these costs:
| Variant | What it saves | How | Examples named in the guide |
|---|---|---|---|
| MHA (multi-head) | Nothing. This is the baseline. | Every head has its own K and V | GPT-2, OLMo 2 7B |
| GQA (grouped-query)[13] | KV cache memory | Several query heads share one K and V | Llama 3 8B, Qwen3 4B, Gemma 3 27B |
| MLA (multi-head latent)[14] | KV cache memory | Store one compressed latent and rebuild K and V | DeepSeek V3, Kimi K2, GLM-5 |
| SWA (sliding window)[15] | Compute and memory at long length | Each token reads only a window of recent tokens | Gemma 3 27B, OLMo 3 32B |
| DSA (DeepSeek sparse) | Compute at long length | A learned selector keeps the useful earlier tokens | DeepSeek V3.2, GLM-5 |
| Gated attention | Stability of full-attention layers | A gate after the attention output | Qwen3-Next, Qwen3.5, Trinity |
| Hybrid | Cost at very long length | Mostly cheap linear layers, a few full-attention layers | Qwen3-Next |
The KV cache, in numbers
Take a model shaped like Llama 3 8B: 32 layers, 32 query heads, head size 128, FP16 (2 bytes per number). For each token and layer, the cache holds one K and one V for each KV head.[13][12]
| Design | KV heads | Cache per token | Cache at 128K tokens |
|---|---|---|---|
| MHA | 32 | 512 KiB | 64 GiB |
| GQA (Llama 3 8B uses 8) | 8 | 128 KiB | 16 GiB |
| MQA | 1 | 16 KiB | 2 GiB |
The formula is 2 × layers × kv_heads × head_size × bytes × tokens. MLA goes further than GQA. The DeepSeek-V2 paper reports a KV cache that is 93.3% smaller than that of its earlier dense model, DeepSeek 67B.[14]
Cheaper attention: fewer pairs, or fewer full layers
- Sliding window: a token reads only the last
wtokens. Gemma 3 uses five local layers for each global layer, with a window of 1,024 tokens. The guide notes that its ablation shows only a small loss in quality.[12] - DeepSeek sparse attention: the window is not fixed. A small indexer scores earlier tokens, and a selector keeps the best ones. The model decides which tokens are worth revisiting.[12]
- Hybrid: most layers use a linear or state-space mixer that costs little at long length. Every few layers, a full-attention layer restores exact lookup. Qwen3-Next uses a 3 : 1 mix. The guide notes a small quality trade-off.[12]
How to use the guide
- Read part 1 (MHA) quickly, even if you know it. It sets the names used in the other parts.
- For each later variant, ask two questions: what does it save? and what does it give up?
- Open a model card of a model you use. Find which variant it has. Compare its context limit with the numbers in the table above.
Know the limit. The article is a guide to architecture ideas. It does not rank the models. Real speed also depends on the serving software and the GPU (see section 8).
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Size the KV cache for a long chat, then see what GQA saves
Why this matters
Long chats fail on memory more often than on speed. The KV cache is a big reason. You can estimate it with one formula.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. It uses a Llama 3 8B style shape.
Prompt A model has 32 layers, 8 KV heads, and a head size of 128. It stores the KV cache in FP16 (2 bytes per number). Formula: bytes per token = 2 (K and V) × layers × kv_heads × head_size × bytes. 1. Compute the KV cache per token in KiB. 2. Compute the cache for a context of 131,072 tokens in GiB. Show the arithmetic.
You should see: 128 KiB per token, and about 16 GiB for 131,072 tokens.
Example answer
1. 2 × 32 × 8 × 128 × 2 = 131,072 bytes = 128 KiB per token. 2. 131,072 × 131,072 = 17,179,869,184 bytes = 16 GiB.
Your answer will be worded differently.
Step 2
Same chatAsk in the same chat: Now the same model, but with 32 KV heads (standard multi-head attention). How big is the cache for 131,072 tokens? How many times bigger is it?
You should see: About 64 GiB. That is 4 times bigger, because there are 4 times as many KV heads.
Step 3
Same chatOpen the article and find the GQA section. Look for the sentence that explains why GQA lowers KV-cache traffic.
You should see: The article says GQA lets several query heads share the same key-value projections. This makes KV caching much cheaper, mostly as a memory reduction.
What just happened
The KV cache grows with layers × KV heads × context length. GQA cuts the middle factor. MLA shrinks what is stored per head.
You are done when You sized the KV cache of a long context and saw why most modern models use fewer KV heads.
Check yourselfA model has 32 query heads and 8 KV heads. How many query heads share each KV head?Show answer
4. The 32 query heads are split into 8 groups of 4, and each group reads one K and V.
Watch · 3 videos
07
A Visual Guide to Mixture of Experts: routers, experts and load balancing
Why many modern LLMs use only a few of their experts for each token, and how routers are kept fair.
Live view · 1 page
A Visual Guide to Mixture of Experts (MoE)newsletter.maartengrootendorst.comOpen in a new tab ↗ The article with more than 50 diagrams. The publisher does not allow it inside other sites, so open it in a new tab. The author's own video version is in the video list below.
Open in a new tab ↗
A Visual Guide to Mixture of Experts (MoE) is an article by Maarten Grootendorst (7 October 2024). It uses more than 50 diagrams to explain the two parts of an MoE layer: the experts and the router.[16]
Open it: newsletter.maartengrootendorst.com. The page has a table of contents. Use it to jump between topics.
The idea: a big layer where only a few parts work
In a standard transformer block, a feed-forward network (FFN) refines each token after attention. This FFN holds most of the block's parameters. An MoE block replaces this one FFN with many FFNs, called experts, and adds a small router. For each token, the router picks a few experts. The other experts do no work for that token.[16][17]
The router in four steps
- Score: multiply the token vector by the router weights
W. This gives one score for each expert. - Softmax: turn the scores into probabilities
G(x). - Keep top-k: keep the
klargest values (for example 2). Set the others to zero. - Combine: run the chosen experts and add their outputs, each multiplied by its router probability.
The router is itself a small FFN that is trained together with the experts. When most tokens go to a few experts, those experts learn faster, and the router sends even more tokens to them. This loop is the main training problem of MoE.[16]
What an expert learns
The word “expert” suggests a specialist in a subject, such as biology or law. The guide shows that this is misleading. In decoder models, experts seem to handle patterns of tokens and syntax, not subjects. The guide shows a Mixtral figure in which each token is coloured by its first expert choice. Experts focus on syntax rather than on one subject.[16][19]
Load balancing: keeping all experts busy
| Fix | How it works | Source |
|---|---|---|
| KeepTopK with noise | Add trainable noise to the router scores. Keep only the top k. | Shazeer et al. 2017[17] |
| Auxiliary (balancing) loss | Add a loss term that is high when some experts get more tokens than others. | Shazeer et al. 2017; simplified in Switch[17][18] |
| Expert capacity | Each expert may take only a fixed number of tokens. An extra token overflows to the next layer. | Guide; Switch Transformer[18] |
| Top-1 routing | Send each token to one expert only. This is simpler and more stable. | Switch Transformer[18] |
Sparse and active parameters
An MoE model has two sizes. The sparse (total) size counts every expert. The active size counts only the experts that run for one token. The guide uses Mixtral 8x7B as the example.[16][19]
| Model | Experts in each layer | Used per token | Total parameters | Active per token |
|---|---|---|---|---|
| Mixtral 8x7B[19] | 8 | 2 | about 47B | about 13B |
| DeepSeek-V2[14] | many fine-grained experts | a small subset | 236B | 21B |
What this means in practice. Compute for each token is like a small dense model (about 13B for Mixtral). The memory is like a large model (all 47B must be loaded). MoE models need more VRAM to load, and they run faster at inference than a dense model of the same total size.
How to use the guide
- Read the dense-layer part first. MoE only makes sense as a change to the FFN.
- In the router part, follow the numbers for one token from scores to the final sum.
- Read load balancing last. It is the part that decides whether an MoE model trains well.
- Then open a model card and look for the words experts, top-k, active parameters.
Know the limit. Total size and active size are different numbers, and a model name often hides this. Check both before you compare the cost of two models, or before you pick a GPU for self-hosting (see Part 7).
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Compute total size and active size of an MoE model
Why this matters
A model name like “8x7B” hides two different numbers. You need both to estimate memory and cost.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. The numbers are the ones from the Mixtral 8x7B example in the guide.
Prompt A mixture-of-experts model has 8 experts in each layer. Each expert (all layers together) has 5.6 billion parameters. The router picks 2 experts for each token. Ignore the shared parameters. 1. How many parameters must be loaded in memory (total)? 2. How many parameters are used for one token (active)? 3. If each parameter takes 2 bytes (FP16), how many GB of memory do the experts need? Show the arithmetic in a short list.
You should see: Total 44.8B, active 11.2B, and about 89.6 GB of memory for the experts.
Example answer
1. Total: 8 × 5.6B = 44.8B. 2. Active: 2 × 5.6B = 11.2B. 3. Memory: 44.8B × 2 bytes = 89.6 GB. (The real Mixtral has some shared parameters, so its totals are 46.7B and about 12.8B.)
Your answer will be worded differently.
Step 2
Same chatOpen the guide. Go to the last part, Active vs. Sparse Parameters with Mixtral 8x7B. Compare its numbers with the chat answer.
You should see: The guide says each expert is 5.6B, not 7B. It gives 46.7B to load and about 12.8B to use. Your chat answer is a bit lower because it ignored shared parameters.
Step 3
Same chatAsk in the same chat: A dense 13B model and this MoE model have almost the same speed per token. Why does the MoE model still need about 3.5 times more GPU memory?
You should see: All experts must be loaded, because the router may choose any of them for the next token. The memory depends on total size, and the speed depends on active size.
What just happened
Memory follows the total parameters. Speed per token follows the active parameters.
You are done when You separated total size from active size for a real MoE example and checked it against the guide.
Check yourselfA router picks the top 2 of 64 experts. What fraction of the expert parameters runs for one token?Show answer
2 of 64, which is 1/32, about 3%. The other 62 experts are loaded but idle for that token.
Watch · 3 videos
A Visual Guide to Mixture of Experts (MoE) in LLMs Maarten Grootendorst
Mixture of Experts (MoE), Visually Explained Jia-Bin Huang
Mixture of Experts (MoE) Explained: Bigger AI Models Without More Compute | LLM Efficiency AIChronicles_JK
08
LLM Inference Handbook: from prompt to first token and beyond
Tokenizing, scheduling, prefill and decode, and the techniques that make serving faster and cheaper.
Live view · 1 page
LLM Inference Handbookhandbook.modular.comOpen in a new tab ↗ The first page of the handbook. Press play on the LLM Inference Visualizer to follow one prompt through Tokenizer, Scheduling, Prefill, and Output.
The page loads from its own site when you click. Works best on a wide screen.
The LLM Inference Handbook is a free online guide to everything that happens between your prompt and the answer. Its first chapter, What is LLM inference?, defines the terms. The next chapters cover how inference works and how to make it faster and cheaper.[20]
Open it: handbook.modular.com. The first page has an interactive LLM Inference Visualizer. It follows one prompt through four steps: Tokenizer, Scheduling, Prefill, and Output.
Four terms the handbook separates
| Term | Meaning | Example |
|---|---|---|
| Inference | The computation: tokens in, a probability for the next token out, repeated until the answer is complete. It can run in a notebook with no server. | A Python script that loads a model and calls generate |
| Inference server / framework | The software that loads the model, uses the GPU, and handles requests. It offers batching, streaming, scaling, and monitoring. | vLLM, SGLang, MAX, TensorRT LLM |
| Serving | The whole production service: API, queues, batching across users, load balancing, autoscaling, versions, health checks. | A chat product for 10,000 users |
| Inference optimization | Techniques that make inference faster, cheaper, or both, without lowering quality much. | Quantization, prefix caching |
The handbook notes that people often use these words as if they were the same, because one tool often does several of these jobs. The difference matters when you design infrastructure.[20]
What happens to one request
- Tokenize: the server cuts the prompt into tokens and turns them into ids.
- Schedule: the scheduler puts the request in a queue and joins it to the batch that is running on the GPU.
- Prefill: the model reads the whole prompt in one pass. It builds the KV cache, which holds the keys and values of every prompt token (see section 6). The first output token comes out at the end of this step.
- Decode: the model makes one token per step. It reads the cache, adds the new token to it, and repeats until it makes an end-of-text token or reaches the limit.
- Stream: the server sends each token to the user as soon as it exists, so the user starts reading early.
Optimizations, and what each one helps
| Technique | Idea | Helps most |
|---|---|---|
| Continuous batching | Add and remove requests from the running batch at every step, not once per batch. | Throughput, GPU use |
| Prefix caching | Reuse the KV cache of a prompt start that was seen before, such as a long system prompt. | TTFT |
| KV cache management[21] | Store the cache in small pages, so memory is not wasted. More requests fit on one GPU. | Capacity, cost |
| Speculative decoding[22] | A small draft model proposes several tokens. The big model checks them in one pass. | TPOT |
| Quantization | Store weights in fewer bits, such as INT8 or FP8. Decode reads fewer bytes. | Memory, TPOT |
| Parallelism | Split the model over several GPUs. | Model size, context length |
The handbook lists these strategies on its first page and points to a chapter on inference optimization for details.[20]
How to use the handbook
- Press play on the visualizer. Name each of the four steps to yourself.
- Read What is an inference server? and the page on serving versus inference. Write one line for each term in your own words.
- Choose one optimization from the table. Read its chapter. Find the metric it improves: TTFT, TPOT, or throughput.
- Return to Part 7 of this site and read the section on servers and quantization with the same vocabulary.
Know the limit. Speed numbers depend on the model, the GPU, the batch size, and the prompt length. Treat any example number, including the numbers in this section, as a way to practise the formulas. Measure your own system.
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Time one request, then test two speed-ups
Why this matters
To improve speed you must know which number you improve. This task gives you the formula and two cases to compare.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. It uses the end-to-end formula from the diagram.
Prompt An LLM request has a time to first token (TTFT) of 400 ms and a time per output token (TPOT) of 25 ms. The answer has 200 tokens. Formula: end-to-end time = TTFT + (tokens - 1) x TPOT. 1. Compute the end-to-end time in ms and in seconds. 2. Compute how many tokens per second the user sees after the first token. Show the arithmetic.
You should see: 5,375 ms, about 5.4 seconds. A user also sees about 40 tokens per second during decode.
Example answer
1. 400 + 199 x 25 = 400 + 4,975 = 5,375 ms, which is 5.38 s. 2. 1000 / 25 = 40 tokens per second.
Your answer will be worded differently.
Step 2
Same chatAsk in the same chat: Prefix caching cuts TTFT from 400 ms to 100 ms. Speculative decoding instead cuts TPOT from 25 ms to 15 ms. Compute the new end-to-end time for each, and say which one helps more for a 200-token answer.
You should see: Prefix caching gives 5,075 ms. Speculative decoding gives 3,385 ms. For a long answer, the TPOT change helps more.
Example answer
Prefix caching: 100 + 199 x 25 = 5,075 ms. Speculative decoding: 400 + 199 x 15 = 3,385 ms. For 200 tokens, speculative decoding saves more because the decode phase is most of the time.
Your answer will be worded differently.
Step 3
Same chatOpen the handbook page and press play on the visualizer. In the chat, ask: For a chatbot with 4,000-token system prompts and 20-token answers, which optimization is more useful, prefix caching or speculative decoding? Why?
You should see: Prefix caching. The prompt is long and the answer is short, so prefill (TTFT) is most of the wait. Caching the shared system prompt removes most of it.
What just happened
Pick the optimization by the metric that hurts: TTFT for long prompts, TPOT for long answers.
You are done when You computed a request time and compared two speed-ups with the same formula.
Check yourselfA user complains that the first word takes 6 seconds to appear, but the rest streams fast. Which phase is slow, and which technique do you try first?Show answer
The slow part is TTFT: queueing and prefill. Try prefix caching for repeated prompt starts, and check the queue time and batching settings.
Watch · 3 videos
Efficient LLM Serving with vLLM (Ray x AI21 Meetup) AI21 Labs
An Intermediate Guide to Inference Using vLLM Red Hat Open
vLLM Deep Dive: PagedAttention, Continuous Batching & 24x Throughput Latest AI Technolgy Breakdowns
09
Neuronpedia: look at what features inside a model mean
An open platform to browse, test, and steer the features that sparse autoencoders find inside language models.
Live view · 2 pages
Neuronpedia: a real feature (Gemma 2 2B, layer 20, feature 1000)neuronpedia.orgOpen in a new tab ↗ The auto-written label says elements related to React component structure and rendering methods. Read the top activating text and check the label. Then type your own text in the test box.
The page loads from its own site when you click. Works best on a wide screen.
Neuronpedia homeneuronpedia.orgOpen in a new tab ↗ The full site. Use Search to find features by text, and Steer to push a feature up or down while a model writes.
The page loads from its own site when you click. Works best on a wide screen.
Neuronpedia is an open-source platform for interpretability research. You can explore, visualize, and steer the inside of AI models in your browser.[23] It hosts large public sets of features: directions inside a model that stand for ideas such as a place, a language, or a style. The page lists more than five terabytes of activations, explanations, and metadata.[23]
Open it: neuronpedia.org. The menu has Search, Steer, SAE Evals, Exports, Guides, and API. The site also hosts a Circuit Tracer, which traces the internal steps of a model's reasoning.[23]
The problem: neurons are hard to read
You might hope that each neuron in a model means one thing. It does not. A model must represent far more ideas than it has neurons, so it packs many ideas into the same neurons, in overlapping ways. This is called superposition. A single neuron then fires for several unrelated things, which makes it hard to read.[26]
The tool: a sparse autoencoder
A sparse autoencoder (SAE) is a small network that is trained on a model's activations. It turns each activation into a very wide vector where only a few entries are active. Each entry is a feature. Then it rebuilds the original activation from those few features. The penalty on active entries pushes each feature toward one clear meaning.[24][26]
Neuronpedia shows the output of such SAEs. One featured release is Gemma Scope, a set of open SAEs that Google DeepMind trained on Gemma 2.[25][23]
How to read a feature page
- Top activating examples: do all of them share one idea? If yes, the feature is clean.
- Weak examples: scroll down to the lower activations. Do they show a second meaning?
- Density: a feature that fires on a tiny share of tokens is usually specific. A feature that fires on many tokens may be broad or noisy.
- Explanation: an automatic system often writes it. Treat it as a first guess, not as a fact.
Steering: test a feature by pushing it
A feature is a direction in the model's activation space. To test whether it matters, you add a scaled copy of that direction to the activation while the model writes: a' = a + α · d. If the output moves toward the feature's idea, the feature has a causal role. Neuronpedia has a Steer tool for this.[23][26]
| α (strength) | What you usually see |
|---|---|
| 0 | Normal output. |
| Small | A faint lean toward the feature's idea. |
| Medium | The idea appears often and the text stays fluent. |
| Too large | The model fixates on the idea and the text breaks down. |
Why this matters for engineers
- Safety: researchers look for features that relate to deception, harmful content, or sycophancy, and try to monitor or control them. See Part 11.
- Debugging: a feature view can show why a model gave a strange answer. Circuit tracing goes further and follows how features feed into each other.[27]
- Trust: interpretability gives evidence about how a model works, which is stronger than only testing its outputs.
Know the limits. Features are hypotheses. An SAE rebuilds an activation only approximately, so some information is missing. Labels can be wrong. The same idea can split into several features in a wider SAE. Check a claim with examples and with steering before you rely on it.
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Check a feature label with its examples
Why this matters
Features have automatic labels. A good engineer reads the examples and decides if the label is right. This task gives you that habit.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. It asks for the idea of superposition with two neurons.
Prompt A layer has only 2 neurons, but it must store 3 different ideas (A, B, C). The ideas rarely appear at the same time. Explain in under 80 words how the layer can still store all three. Use the word "direction".
You should see: The answer explains that three ideas can be stored as three directions in a 2D space, for example 120 degrees apart. It works because the ideas rarely appear together.
Example answer
Each idea gets its own direction in the 2D plane, for example three arrows 120 degrees apart. When idea A appears, the two neurons move along A's arrow. Because the ideas rarely appear together, the layer can tell them apart by direction. This is superposition: more ideas than neurons.
Your answer will be worded differently.
Step 2
Same chatOpen neuronpedia.org. Use Search and look for features about a simple idea, for example ocean. Open two features. For each one, read its explanation and its top examples. Then scroll to its weaker examples.
You should see: For each feature, most top examples match the explanation. Some weaker examples show a second meaning or a different use of the word.
Step 3
Same chatBack in the chat, ask: Give me 3 reasons why an automatically written label for an SAE feature can mislead a reader.
You should see: Three reasons, for example: the label may come from only the top examples; the feature may fire on a second, weaker meaning; the label comes from a model guess, which can be wrong.
What just happened
A feature label is a hypothesis. You test it with the examples, with the weak activations, and with steering.
You are done when You explained superposition and checked real feature pages against their labels.
Check yourselfWhy does a sparse autoencoder penalize the number of active features?Show answer
The penalty forces the autoencoder to explain each activation with only a few features. This pushes each feature to stand for one clear pattern, which is easier to read.
Watch · 3 videos
10
Embedding Atlas by Apple: a visual map of your embeddings
Turn a table of text, images or audio into a map. See clusters, neighbours and outliers, and filter with linked charts.
Live view · 2 pages
Embedding Atlas: IEEE VIS publications exampleapple.github.ioOpen in a new tab ↗ A live Embedding Atlas on a public example dataset of about 3,750 publications. Colour the map by conference, pan and zoom, click a point to read it, and use the linked charts to filter. The map needs a browser with WebGPU, such as a recent Chrome, Edge, or Safari.
The page loads from its own site when you click. Works best on a wide screen.
Embedding Atlas: load your own fileapple.github.ioOpen in a new tab ↗ Drop a CSV, JSONL, or Parquet file here. The page says that the data stays in your browser. You can use the
tickets.csvfile from the practice task below.The page loads from its own site when you click. Works best on a wide screen.
Embedding Atlas is an open-source tool from Apple. It turns a table of text, images or audio into a map. Similar rows sit close together. You can click, search, and filter the map to understand a dataset that is too big to read.[28][29]
Open it: apple.github.io/embedding-atlas. The site has live examples. You can also load your own file on the site. The docs say it then computes the embedding and the projection in your browser, and your data does not leave your machine.[28]
How it works
An embedding is a list of numbers that stands for the meaning of a piece of data. Rows with similar meaning get similar numbers. A table of 100,000 rows becomes 100,000 vectors.[28]
UMAP is a method that keeps nearby points near each other when it moves from many dimensions to two.[30] Embedding Atlas ships a WebAssembly version of UMAP, plus nearest-neighbour search and a density-based clustering step.[28]
What the tool gives you
| Feature | What it does | Question it helps with |
|---|---|---|
| Automatic clustering and labels | Finds dense regions and names them | What are the main topics in my data? |
| Search and nearest neighbours | Finds rows similar to a query or to a selected point | Do I already have an example like this one? |
| Density rendering with WebGPU | Draws up to a few million points with density contours | Where is the data thick, and where is it thin? |
| Linked charts and cross-filtering | A chart and the map filter each other | Which part of the map has the low-rated rows? |
| Multimodal viewers | Text, image, audio, numeric, categorical, and time columns | Can I look at pictures or listen to clips, not only read text? |
| MCP server | Lets an AI agent query the data, make charts, and take screenshots | Can an agent explore the data for me? |
The feature list follows the project's home page and overview.[28]
Three ways to run it
- In the browser: open the website and use Load Data. Supported files are Parquet, JSONL, and CSV.[28]
- Command line: install the Python package and point it at a file (see below). The default models are all-MiniLM-L6-v2 for text, google/vit-base-patch16-224 for images, and laion/clap-htsat-fused for audio. The docs say these defaults may change.[28]
- In a notebook or an app: the package has a Jupyter widget and a Streamlit component. You can pass a pandas DataFrame directly. A separate npm package has the interface components, for use in your own web app.[28]
# Install, then open a file in your browser
pip install embedding-atlas
embedding-atlas tickets.csv --text message
# The tool embeds the "message" column, runs UMAP,
# and prints a local URL such as http://localhost:5055/If you already have vectors, pass them with --vector. If you already have a 2D projection, pass it with --x and --y. This makes the map repeatable.[28]
Use it for AI engineering work
- Debug retrieval (RAG): embed your document chunks and your user questions into one map. Questions that fall in an empty region show a gap in your knowledge base. See Part 4.
- Clean a dataset: look for tight groups of near-duplicates and for lone points that may be wrong labels or junk.
- Check evaluation coverage: plot your test questions on top of real traffic. Regions with traffic but no tests are untested.
- Compare embedding models: load the same data with two models. If the clusters change a lot, the choice of model matters for your task.
Know the limits. A 2D map loses information. Treat the distance between two far clusters as a rough hint, not as a measure. The clusters depend on the embedding model and on the UMAP settings. Automatic labels are guesses. Always open some rows to check what a region contains.
Practice · 1 task
Open any free AI chat: ChatGPT · Claude · Gemini
How practice works
- A new chat is a fresh conversation with no history. In ChatGPT, Claude, or Gemini, click New chat. It is usually at the top left.
- Same chat means: keep typing in the chat that is already open. The AI remembers what you sent before.
- To use a prompt: click Copy, click in the message box of the chat, paste it (Ctrl+V, or press and hold on a phone), and press Enter.
- AI answers are a little different every time. Your answer does not need to match the example word for word. Look for the same idea.
- Use made-up data only. Do not paste private information into a chat.
Task 1
Map 40 messages and find the one that does not belong
Why this matters
A map helps you see problems that a table hides. You will build a small dataset with one planted mistake, then find the mistake on the map.
Step 1
New chatCopy this prompt, paste it in an AI chat, and press Enter. It makes a small CSV. Copy the CSV text into a file called
tickets.csv.Prompt Create a CSV with the header: message,topic Write 40 short customer-support messages (8 to 15 words each) from an online shop. Use exactly 4 topics, 10 rows each: billing, login, shipping, returns. Then add one extra row at the end: a message about baking a chocolate cake, with the topic "unknown". Output only the CSV in a code block.
You should see: A CSV with the header
message,topicand 40 rows: 10 rows for each of 4 topics. One row, about cooking, does not fit any topic.Example answer
message,topic I was charged twice for the same order this month,billing My password reset email never arrives in my inbox,login The parcel has been stuck at the depot for five days,shipping How do I send back a jacket that is too small,returns ... What is the best way to bake a moist chocolate cake,unknown
Your answer will be worded differently.
Step 2
Same chatOpen Embedding Atlas, choose Load Data, and select
tickets.csv. If it asks, choose themessagecolumn as the text. Wait for the map. If the tool has a colour setting, colour the points bytopic.You should see: A map with 4 clear groups (billing, login, shipping, returns). One lone point, the cake message, sits away from all groups.
Step 3
Same chatHover over the lone point and read its text. Select one point in the login group and look at its nearest neighbours. In the chat, ask: The map shows 4 groups and one lone point. Name 3 things I should check before I say the lone point is a labelling error.
You should see: The neighbours of the login point are other login messages. The chat suggests: read the row, check the topic label, and test with another embedding model or other UMAP settings.
What just happened
Similar rows form clusters. A lone point is a row to read. Before you act on it, check the row and the settings.
You are done when You built a small dataset, mapped it, and found a planted outlier.
Check yourselfTwo clusters are far apart on the map. Can you say they are twice as different as two clusters that are half as far apart?Show answer
No. UMAP keeps nearby points close, but it does not keep long distances reliably. Use far distances as a rough hint only.
Watch · 2 videos
References
Sources
All citations resolve to primary papers (arXiv), vendor docs (OpenAI, Anthropic, Google), or official team blogs. IDs were verified by fetching each page and extracting the citation metadata.
- [1]Cho et al., "Transformer Explainer: Learning LLM Transformers with Interactive Visual Explanation and Experimentation" (arXiv, 2024)
- [2]Polo Club of Data Science, Georgia Tech, "Transformer Explainer" (interactive page)
- [3]Vaswani et al., "Attention Is All You Need" (NeurIPS 2017)
- [4]Brendan Bycroft, "LLM Visualization" (interactive 3D page)
- [5]Brendan Bycroft, "llm-viz" (source code of the LLM Visualization page)
- [6]Andrej Karpathy, "nanoGPT" (minimal GPT training and inference code)
- [7]3Blue1Brown, "Neural networks" (video lesson series, Deep Learning chapters 1–7)
- [8]Jay Alammar, "The Illustrated Transformer" (blog post, 2018)
- [9]Bahdanau, Cho, Bengio, "Neural Machine Translation by Jointly Learning to Align and Translate" (ICLR 2015)
- [10]Smilkov, Carter et al., "TensorFlow Playground" (interactive page)
- [11]Smilkov, Carter, Sculley, Viégas, Wattenberg, "Direct-Manipulation Visualization of Deep Networks" (ICML Workshop on Visualization for Deep Learning, 2016)
- [12]Sebastian Raschka, "A Visual Guide to Attention Variants in Modern LLMs" (Ahead of AI, 22 March 2026)
- [13]Ainslie et al., "GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints" (EMNLP 2023)
- [14]DeepSeek-AI, "DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model" (2024)
- [15]Beltagy, Peters, Cohan, "Longformer: The Long-Document Transformer" (2020)
- [16]Maarten Grootendorst, "A Visual Guide to Mixture of Experts (MoE)" (Exploring Language Models, 7 October 2024)
- [17]Shazeer et al., "Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer" (ICLR 2017)
- [18]Fedus, Zoph, Shazeer, "Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity" (JMLR 2022)
- [19]Jiang et al., "Mixtral of Experts" (Mistral AI, 2024)
- [20]"LLM Inference Handbook", chapter "What is LLM inference?" (handbook.modular.com)
- [21]Kwon et al., "Efficient Memory Management for Large Language Model Serving with PagedAttention" (SOSP 2023)
- [22]Leviathan, Kalman, Matias, "Fast Inference from Transformers via Speculative Decoding" (ICML 2023)
- [23]Neuronpedia, "An open source interpretability platform" (neuronpedia.org)
- [24]Cunningham et al., "Sparse Autoencoders Find Highly Interpretable Features in Language Models" (2023)
- [25]Lieberum et al., "Gemma Scope: Open Sparse Autoencoders Everywhere All At Once on Gemma 2" (Google DeepMind, 2024)
- [26]Bricken et al., "Towards Monosemanticity: Decomposing Language Models With Dictionary Learning" (Anthropic, Transformer Circuits Thread, 2023)
- [27]Lindsey et al., "On the Biology of a Large Language Model" (Anthropic, Transformer Circuits Thread, 2025)
- [28]Apple, "Embedding Atlas" (documentation and live demo)
- [29]Ren, Hohman, Lin et al., "Embedding Atlas: Low-Friction, Interactive Embedding Visualization" (2025)
- [30]McInnes, Healy, Melville, "UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction" (2018)
- [31]Su et al., "RoFormer: Enhanced Transformer with Rotary Position Embedding" (2021)
- [32]Brown et al., "Language Models are Few-Shot Learners" (NeurIPS 2020)