Skip to content

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]

StageWhat happensGPT-2 (small) numbers
TokenizeText is cut into tokens. Each token gets an integer id.Vocabulary of 50,257 tokens
EmbedEach id becomes a vector. A position vector is added, so the model knows the order.768 numbers for each token
AttentionEach token looks at the earlier tokens and takes in the useful ones. Several heads do this in parallel.12 heads in each block
MLPA small network refines each token on its own.Expands 768 to 3,072, then back
RepeatThe attention and MLP pair repeats. Each repeat is one transformer block.12 blocks
OutputThe last vector becomes one score for every token in the vocabulary. Softmax turns the scores into probabilities.50,257 probabilities
SampleOne token is picked from the probabilities. Temperature, top-k and top-p control this pick.One new token
One generation step. The loop runs once for every new token.Promptplain textTokensidsEmbed768 numbersBlocks12 × attn+MLPLogits50,257 scoresSoftmaxprobabilitiesSampletop-k / top-pappend the new token to the prompt, then run the whole stack again
The text-generation loop that Transformer Explainer animates. The model never writes a whole answer at once. It picks one token, appends it, and repeats.
Transformer Explainer যে text-generation loop দেখায়। মডেল একবারে পুরো উত্তর লেখে না। সে একটি token বাছে, prompt-এ জুড়ে দেয়, তারপর আবার চালায়।

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 by T before softmax. A small T makes the top token even more likely. A large T flattens the list.
  • Top-k: keep only the k most 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.
Same five scores, three temperatures. Prompt: “The cat sat on the”T = 0.5 sharpmat76%floor15%couch7%roof1%moon0%T = 1.0 normalmat53%floor24%couch16%roof6%moon1%T = 2.0 flatmat37%floor25%couch20%roof13%moon6%
Illustrative scores for five candidate tokens, pushed through softmax at three temperatures. The bars are computed with softmax(score / T). Real models have 50,257 candidates, not five.
পাঁচটি candidate token-এর (উদাহরণমূলক) score তিনটি temperature-এ softmax-এর মধ্য দিয়ে। বারগুলো 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

  1. Pick an example prompt, or type The cat sat on the. Press Generate.
  2. Click a token. Watch the page zoom from the embedding to the attention stage.
  3. Open the attention view. Hover over a token and see which earlier tokens it reads.
  4. Set temperature to 0.2, generate three times, then set it to 1.5 and generate three times. Compare the answers.
  5. 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.

  1. Step 1
    New chat

    Copy 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.

  2. Step 2
    Same chat

    Open 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.

  3. Step 3
    Same chat

    In the explainer, move the temperature slider to 0.2, then to 2.0. Generate each time. In the chat, ask: Why does a high temperature give stranger words?

    You should see: At 0.2 the top word wins almost every time. At 2.0 rare 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.

Try a harder versionPick a prompt where you think two words are almost equally likely. Check the explainer to see if you were right.

Watch · 3 videos

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]

ModelPositions (T)Width (C)HeadsBlocksVocabularyParameters
nano-GPT1148333about 86K
GPT-2 (small)1,024768121250,257about 124M
GPT-2 (XL)1,0241,600254850,257about 1.56B
GPT-32,04812,288969650,257about 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]

nano-GPT: the size of the data at each stage (T = 11 positions, C = 48 numbers per position)Tokens11 ids3 lettersEmbedding11 × 48token + positionAttention3 heads11×11 map eachMLP48→192→48per positionBlock ×311 × 48same shape outLogits11 × 3score per letterOne matrix, drawn to scale: 11 rows (positions) by 48 columns (numbers)11 positions48 numbers per positionThe 3D page draws every numberas a small cube. You see thismatrix, then the next, then the next.
The shapes inside nano-GPT. The data is always a table with one row for each position. Each stage changes the numbers in the rows, and the attention stage mixes information between rows.
nano-GPT-র ভেতরে data-র আকার। data সবসময় একটি table, যার প্রতিটি position-এর জন্য একটি সারি। প্রতিটি ধাপ সারির সংখ্যা বদলায়, আর attention ধাপ সারিগুলোর মধ্যে তথ্য মেশায়।

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.
Parameters, log scale. Each step to the right is about 10×.nano-GPT86KGPT-2 (small)124MGPT-2 (XL)1.56BGPT-3175B10^410^510^610^710^810^910^1010^1110^12
Parameter counts computed from the shapes in the table, with the input and output embeddings tied (as in GPT-2). The four models differ by a factor of about 2 million from smallest to largest.
টেবিলের shape থেকে হিসাব করা parameter সংখ্যা (GPT-2-এর মতো input ও output embedding একসাথে বাঁধা)। ছোটতম থেকে বড়তম মডেলের ব্যবধান প্রায় ২০ লক্ষ গুণ।

A 15-minute path through the page

  1. Start the walkthrough on nano-GPT. Read the Embedding step. Find the token embedding and the position embedding. They are added.
  2. 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.
  3. Move to the MLP step. Find the 4× wider middle layer. For nano-GPT it is 48 → 192 → 48.
  4. Move to the Output step. Find the logits and the softmax. They match the last two steps in section 1.
  5. 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.

  1. Step 1
    New chat

    Copy 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.

  2. Step 2
    Same chat

    Open 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.

  3. Step 3
    Same chat

    In 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.

Try a harder versionOpen GPT-2 (small) in the page. Ask the chat to count its parameters from the shape in the table. Compare with about 124 million.

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

The Neural networks series, in watching order1Neuralnetwork2Gradientdescent3Backpropintuition4Backpropcalculus5Transformers(GPT)6Attentionstep by step7Facts inthe MLPHow a network learnsHow an LLM worksChapters 5–7 need only the idea of weights and learning from chapters 1–2.
The series in watching order. Chapters 1 to 4 build one small network and teach how it learns. Chapters 5 to 7 apply the same ideas to the transformer in an LLM.
সিরিজটি দেখার ক্রমে। অধ্যায় ১ থেকে ৪ একটি ছোট network বানায় এবং শেখায় সেটি কীভাবে শেখে। অধ্যায় ৫ থেকে ৭ একই ধারণা LLM-এর transformer-এ প্রয়োগ করে।
#ChapterThe idea you take awayWhere it shows up in this site
1But 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)
2Gradient descent, how neural networks learnA cost function scores the network. The negative gradient tells you which way to turn the knobs to lower the cost.Section 5
3Backpropagation, intuitivelyEach training example nudges every weight. Backpropagation finds the size of each nudge.Section 5
4Backpropagation calculusThe chain rule explains why backpropagation works.Optional math
5Transformers, the tech behind LLMsTokens, embeddings, attention, MLP, and softmax with temperature.Section 1 (Transformer Explainer), section 2
6Attention in transformers, step-by-stepQueries, keys, values, the causal mask, and multiple heads.Section 4 (Illustrated Transformer), section 6
7How might LLMs store factsThe 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.969
Gradient descent on the loss (w − 3)² + 1, start w = 0, step size 0.3start: w = 0.00loss = 10.0 (high)after 5 steps: w = 2.969loss ≈ 1.0 (the bottom)weight wloss
The loop above, drawn. Each step moves the weight a fixed fraction of the way to the bottom. The weights are 0.000, 1.800, 2.520, 2.808, 2.923, 2.969. The step size (learning rate) matters: too big and the ball jumps over the bottom.
উপরের loop-টি আঁকা। প্রতিটি ধাপে weight তলার দিকে নির্দিষ্ট ভগ্নাংশ এগোয়। weight-গুলো হলো 0.000, 1.800, 2.520, 2.808, 2.923, 2.969। ধাপের মাপ (learning rate) জরুরি: বেশি বড় হলে ball তলা পেরিয়ে লাফিয়ে যায়।

A 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

  1. Watch chapters 1 and 2 first, even if you know the words. The pictures of weights and cost fix the vocabulary.
  2. Pause before each result and guess what the next picture will show. This is much more effective than watching passively.
  3. Watch chapter 5 together with section 1. Switch between the video and Transformer Explainer.
  4. Watch chapter 6 together with section 4. Pick the same example sentence in both.
  5. 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.

  1. Step 1
    New chat

    Copy 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.

  2. Step 2
    Same chat

    Check 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.

  3. Step 3
    Same chat

    Copy 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.

Try a harder versionAsk the chat which learning rate in 0.1, 0.5, 1.0 reaches w = 3 in the fewest steps for this loss. Check its answer by hand.

Watch · 6 videos

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]

Self-attention for one head: Attention(Q, K, V) = softmax(Q · Kᵀ / √d_k) · VXembeddingsW_QQqueryW_KKkeyW_VVvalueQ · Kᵀmatch scores÷ √d_kkeep smallsoftmaxweights× Vmix valuesZnew vectorEach token gets its own Q, K and V. The weights say how much of each V flows into Z.
One attention head. The same steps run for every token, and all tokens run at the same time as matrix products.
একটি attention head। প্রতিটি token-এর জন্য একই ধাপ চলে, এবং সব token একই সময়ে matrix গুণফল হিসেবে চলে।

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].

TokenKey kValue vScore q·kScaled (÷ √2)Weight (softmax)
1[1, 0][1, 2]10.7070.670
2[0, 1][3, 4]00.0000.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]

PieceSize in the base modelJob
Embedding width d_model512Length of the vector for each token
Heads8Eight attention patterns in parallel
Q, K, V per head64 numbers eachSmall spaces where tokens are compared
Scale factor√64 = 8Stops the scores from growing too large
Feed-forward layer512 → 2,048 → 512Refines each token on its own
Layers6 encoder + 6 decoderEach layer repeats attention and feed-forward

What the post covers, in order

  1. Embeddings and positional encoding: the model adds a position signal, because attention alone does not know the order.
  2. Self-attention: Q, K, V, scores, scaling, softmax, weighted sum.
  3. Multi-head attention: eight copies with different weights. The outputs are joined and projected back to 512 numbers.
  4. Residual connections and layer normalisation around each sub-layer.
  5. 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.
  6. The last linear layer and softmax, which turn the final vector into word probabilities.
Illustrative attention weights for the token “it” in a sentence ending “… because it was too tired”0.03The0.55animal0.04didn't0.05cross0.04the0.15street0.06because0.08itA trained head puts most weight on “animal”. With “wide” instead of “tired”, it would favour “street”.
The famous example in the post: what does “it” point to? The numbers here are made up to show the pattern. The post shows the real attention of a trained model.
পোস্টের বিখ্যাত উদাহরণ: “it” কিসের দিকে ইঙ্গিত করছে? এখানকার সংখ্যাগুলো প্যাটার্ন দেখানোর জন্য বানানো। পোস্টে একটি trained মডেলের আসল attention দেখানো আছে।

What changed since the post

In the postIn 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 inputOften rotary position embedding (RoPE), applied inside attention[31]
Every head has its own K and VHeads 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.

  1. Step 1
    New chat

    Copy 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.

  2. Step 2
    Same chat

    Open 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.

  3. Step 3
    Same chat

    Ask 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.

Try a harder versionChange the query to [0, 1] and ask the chat to redo the calculation. Predict first which value the output will be close to.

Watch · 4 videos

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

ControlWhat it changesWhat to try
DataThe shape of the two classes: circle, exclusive or (XOR), Gaussian, spiralStart with circle, end with spiral
FeaturesWhich 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 neuronsThe size of the network. Each neuron draws one line or curve.Zero layers, then one layer with 2 neurons, then 4
ActivationThe curve applied after each neuron: ReLU, Tanh, Sigmoid, LinearSwitch to Linear and watch the boundary stay straight
Learning rateHow big each step of gradient descent is0.03 learns well. 10 jumps around.
NoiseHow many points land on the wrong side by accidentRaise it to 40 to simulate messy data
Regularization (L1, L2) and rateA penalty on large weightsUse L2 to calm a network that fits the noise
Ratio of training to test dataHow many points are used for learning and how many for checkingCompare training loss and test loss
The default shape in TensorFlow Playground: 2 → 4 → 2 → 1FeaturesHidden 1Hidden 2OutputX1X2probability of class BEach line is a weight. Each circle sums its inputs, adds a bias, and applies an activation function.
A network in the playground. Each circle is a neuron. Each line is a weight, and its thickness shows its size in the page. Training changes the weights to lower the loss.
Playground-এর একটি network। প্রতিটি বৃত্ত একটি neuron। প্রতিটি রেখা একটি weight, আর পেজে তার মোটা-সরু ভাব weight-এর মান দেখায়। training weight বদলে loss কমায়।

Five experiments that teach one idea each

  1. 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.
  2. 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).
  3. 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.
  4. 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.
  5. 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).
Why a new feature can make a hard problem easyInputs X1, X2: no straight line worksFeatures X1², X2²: one line worksa line cuts through both classesu + v = r² is a straight lineu = X1²v = X2²add X1² and X2²class A (inside)class B (ring)
Experiment 2 in a picture. The points are generated by a fixed pattern for this figure. In the right panel each point is plotted at (X1², X2²), so the circle X1² + X2² = r² becomes the straight line u + v = r².
২ নম্বর পরীক্ষার ছবি। বিন্দুগুলো এই ছবির জন্য একটি নির্দিষ্ট নিয়মে তৈরি। ডান পাশে প্রতিটি বিন্দু (X1², X2²)-এ আঁকা, তাই বৃত্ত X1² + X2² = r² সোজা রেখা u + v = r² হয়ে যায়।

How this connects to an LLM

The playground uses the same four steps that train an LLM:

  1. Forward pass: the inputs flow through the weights to an output.
  2. Loss: a number says how wrong the output is.
  3. Backward pass: the slope of the loss for every weight is computed (see section 3).
  4. 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.

  1. Step 1
    New chat

    Copy 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.

  2. Step 2
    Same chat

    Open 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.

  3. Step 3
    Same chat

    Back 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.

Try a harder versionChoose the spiral dataset. Find a set of features and layers that solves it. Write down the setup that worked.

Watch · 3 videos

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:

VariantWhat it savesHowExamples named in the guide
MHA (multi-head)Nothing. This is the baseline.Every head has its own K and VGPT-2, OLMo 2 7B
GQA (grouped-query)[13]KV cache memorySeveral query heads share one K and VLlama 3 8B, Qwen3 4B, Gemma 3 27B
MLA (multi-head latent)[14]KV cache memoryStore one compressed latent and rebuild K and VDeepSeek V3, Kimi K2, GLM-5
SWA (sliding window)[15]Compute and memory at long lengthEach token reads only a window of recent tokensGemma 3 27B, OLMo 3 32B
DSA (DeepSeek sparse)Compute at long lengthA learned selector keeps the useful earlier tokensDeepSeek V3.2, GLM-5
Gated attentionStability of full-attention layersA gate after the attention outputQwen3-Next, Qwen3.5, Trinity
HybridCost at very long lengthMostly cheap linear layers, a few full-attention layersQwen3-Next
8 query heads (circles) read from the stored keys and values (squares)MHA8 KV heads. Nothing shared.GQA2 KV groups. 4 queries share one.MQA1 KV head. All queries share it.MLAOne small latent. K and V are rebuilt.latent
How MHA, GQA, MQA and MLA store keys and values. Fewer stored entries means a smaller KV cache. MQA is the extreme case of GQA with one group.
MHA, GQA, MQA ও MLA কীভাবে key আর value জমা রাখে। কম জমা মানে ছোট KV cache। MQA হলো GQA-র চরম রূপ, যেখানে গ্রুপ মাত্র একটি।

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]

DesignKV headsCache per tokenCache at 128K tokens
MHA32512 KiB64 GiB
GQA (Llama 3 8B uses 8)8128 KiB16 GiB
MQA116 KiB2 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

Which earlier tokens may each token read? Filled cell = may read.Full (causal)Sliding window, 4Learned sparse (illustrative)cost grows with length squaredcost grows with lengthcost grows with lengthGemma 3 (5 local : 1 global)LLLLLGLLLLLGQwen3-Next (3 linear : 1 full)DDDADDDADDDAL = local window G = global attention D = Gated DeltaNet (linear) A = full attentionLayer patterns follow the guide. The window size for Gemma 3 is 1,024 tokens.
Left to right: full causal attention, a sliding window of 4, and a learned sparse pattern (made up here for illustration). Below: models mix cheap layers with a few full-attention layers.
বাঁ থেকে ডানে: পূর্ণ causal attention, ৪ আকারের sliding window এবং একটি শেখা sparse ধরন (এখানে উদাহরণের জন্য বানানো)। নিচে: মডেল কিছু সস্তা layer আর অল্প কিছু full-attention layer মিলিয়ে ব্যবহার করে।
  • Sliding window: a token reads only the last w tokens. 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

  1. Read part 1 (MHA) quickly, even if you know it. It sets the names used in the other parts.
  2. For each later variant, ask two questions: what does it save? and what does it give up?
  3. 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.

  1. Step 1
    New chat

    Copy 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.

  2. Step 2
    Same chat

    Ask 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.

  3. Step 3
    Same chat

    Open 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.

Try a harder versionAsk the chat to compute the cache for 8 KV heads at 1,000,000 tokens. Can one 80 GB GPU hold it next to the model weights?

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]

One token through one MoE layer (top-2 of 8 experts)Tokenvector xRoutersoftmax(x·W)E1 FFNidleE2 FFNidleE3 FFNg=0.62E4 FFNidleE5 FFNidleE6 FFNg=0.38E7 FFNidleE8 FFNidleg1·E3 + g2·E6weighted sumOutputsame size6 of the 8 experts do no work for this token. The router chooses again for the next token.
One MoE layer. The router gives each expert a score. The top 2 experts (E3 and E6, in this example) run, and the layer adds their outputs, scaled by the router weights g. The numbers are illustrative.
একটি MoE layer। router প্রতিটি expert-কে score দেয়। সেরা ২টি expert (এই উদাহরণে E3 ও E6) চলে এবং layer তাদের output router-এর ওজন g দিয়ে গুণ করে যোগ করে। সংখ্যাগুলো উদাহরণমূলক।

The router in four steps

  1. Score: multiply the token vector by the router weights W. This gives one score for each expert.
  2. Softmax: turn the scores into probabilities G(x).
  3. Keep top-k: keep the k largest values (for example 2). Set the others to zero.
  4. 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

Tokens sent to each expert (1,000 tokens, 8 experts). Illustrative numbers.No balancing: the router favours a few experts410E1320E2150E360E430E515E610E75E8With a balancing loss: roughly equal130E1125E2128E3122E4126E5124E6123E7122E8
Without a fix, a few experts get most tokens and the rest hardly train. A balancing loss pushes the router toward an even split. The counts are made up to show the pattern.
কোনো সমাধান না থাকলে কয়েকটি expert বেশিরভাগ token পায় আর বাকিগুলো প্রায় train হয় না। balancing loss router-কে সমান ভাগের দিকে ঠেলে। সংখ্যাগুলো ধরনটি দেখানোর জন্য বানানো।
FixHow it worksSource
KeepTopK with noiseAdd trainable noise to the router scores. Keep only the top k.Shazeer et al. 2017[17]
Auxiliary (balancing) lossAdd a loss term that is high when some experts get more tokens than others.Shazeer et al. 2017; simplified in Switch[17][18]
Expert capacityEach expert may take only a fixed number of tokens. An extra token overflows to the next layer.Guide; Switch Transformer[18]
Top-1 routingSend 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]

ModelExperts in each layerUsed per tokenTotal parametersActive per token
Mixtral 8x7B[19]82about 47Babout 13B
DeepSeek-V2[14]many fine-grained expertsa small subset236B21B

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

  1. Read the dense-layer part first. MoE only makes sense as a change to the FFN.
  2. In the router part, follow the numbers for one token from scores to the final sum.
  3. Read load balancing last. It is the part that decides whether an MoE model trains well.
  4. 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.

  1. Step 1
    New chat

    Copy 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.

  2. Step 2
    Same chat

    Open 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.

  3. Step 3
    Same chat

    Ask 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.

Try a harder versionLook up a recent MoE model on its model card. Write its total size and its active size. Compute the ratio.

Watch · 3 videos

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

TermMeaningExample
InferenceThe 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 / frameworkThe software that loads the model, uses the GPU, and handles requests. It offers batching, streaming, scaling, and monitoring.vLLM, SGLang, MAX, TensorRT LLM
ServingThe whole production service: API, queues, batching across users, load balancing, autoscaling, versions, health checks.A chat product for 10,000 users
Inference optimizationTechniques 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

One request, from prompt to the last token (not to scale)Tokenizetext to idsQueuewait for a slotPrefillwhole prompt at oncet1t2t3t4t5t6…t200Decode: one token for each stepTTFT: time to first tokenexample: 400 msTPOT25 msEnd-to-end time = TTFT + (tokens − 1) × TPOT = 400 + 199 × 25 = 5,375 ms
The life of one request. The two numbers to watch are TTFT (how long you wait for the first token) and TPOT (the gap between later tokens). The example numbers are made up. The end-to-end time is 5,375 ms for 200 output tokens.
একটি request-এর জীবন। দুটি সংখ্যা দেখার মতো: TTFT (প্রথম token-এর জন্য অপেক্ষা) আর TPOT (পরের token-গুলোর মধ্যে ফাঁক)। উদাহরণের সংখ্যাগুলো বানানো। 200টি output token-এ মোট সময় 5,375 ms।
  1. Tokenize: the server cuts the prompt into tokens and turns them into ids.
  2. Schedule: the scheduler puts the request in a queue and joins it to the batch that is running on the GPU.
  3. 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.
  4. 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.
  5. Stream: the server sends each token to the user as soon as it exists, so the user starts reading early.
Two phases with different bottlenecksPrefillcompute-boundDecodememory-bandwidth-boundPrompt tokens go in together:Big matrix productsKV cache, filled for every prompt token:The GPU does a lot of math. Time ~ prompt length.KV cache, read for every step:newRead all weights + cacheOutput: one token. It joins the cache.Few math operations per byte read, so thememory bus is the limit. Time ~ output length.
Why prefill and decode behave differently. Prefill works on many tokens at once, so the GPU's math units are busy. Decode works on one token at a time, and most of the time goes to reading weights and the cache from memory.
prefill আর decode কেন আলাদা আচরণ করে। prefill অনেক token একসাথে সামলায়, তাই GPU-র গণনা-অংশ ব্যস্ত থাকে। decode একবারে একটি token সামলায়, আর বেশিরভাগ সময় যায় memory থেকে weight ও cache পড়তে।

Optimizations, and what each one helps

TechniqueIdeaHelps most
Continuous batchingAdd and remove requests from the running batch at every step, not once per batch.Throughput, GPU use
Prefix cachingReuse 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
QuantizationStore weights in fewer bits, such as INT8 or FP8. Decode reads fewer bytes.Memory, TPOT
ParallelismSplit 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

  1. Press play on the visualizer. Name each of the four steps to yourself.
  2. Read What is an inference server? and the page on serving versus inference. Write one line for each term in your own words.
  3. Choose one optimization from the table. Read its chapter. Find the metric it improves: TTFT, TPOT, or throughput.
  4. 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.

  1. Step 1
    New chat

    Copy 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.

  2. Step 2
    Same chat

    Ask 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.

  3. Step 3
    Same chat

    Open 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.

Try a harder versionChange the example to 1,000 output tokens. Which speed-up helps more now? Compute both and check against your first answer.

Watch · 3 videos

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]

How a sparse autoencoder (SAE) reads one activation. Sizes are examples.Activation a2,304 numbers, all non-zeroEncoderW_encFeatures f (very wide)16,384 features, about 4 active(each cell stands for many)DecoderW_decâLoss = how far â is from a + a penalty on how many features are active (L1).Sparsity forces each feature to cover one clear pattern. Steering adds a feature's decoder direction to a.Feature ids f₁…f₄ are placeholders, not real Neuronpedia features.
A sparse autoencoder at work. A dense activation of 2,304 numbers becomes a wide vector of 16,384 features with a few active, and the decoder rebuilds the activation. Sizes are examples. Public SAE suites such as Gemma Scope have many widths.
একটি sparse autoencoder-এর কাজ। ২,৩০৪টি সংখ্যার ঘন activation একটি চওড়া vector-এ (১৬,৩৮৪টি feature) পরিণত হয়, যার অল্প কয়েকটি সক্রিয়। decoder মূল activation আবার বানায়। আকারগুলো উদাহরণ। Gemma Scope-এর মতো সর্বজনীন SAE সেটে নানা প্রস্থ আছে।

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

A feature page has the same parts as this mock card. All text here is invented for illustration.Feature #…Explanation (auto-written): “words for places where boats stop”Top activating examplesthe boat drifted slowly into the harborat dawn9.4waves crashed against the rocks near the bayall night8.1they walked along the old stone pierafter lunch7.5the ferry left the dockten minutes late6.2her laptop sat on the docking station0.9Check: the first four match the label. The last one fires weakly on a different meaning (“docking station”).activation
A mock feature card with invented text. The real pages show the same things: an explanation, the text that makes the feature fire most, and how strongly it fires. Always compare the label with the examples.
বানানো লেখাসহ একটি নকল feature card। আসল পাতায় একই জিনিস থাকে: একটি ব্যাখ্যা, যে লেখায় feature সবচেয়ে বেশি সক্রিয় হয়, আর সক্রিয়তার মাত্রা। লেবেলকে সবসময় উদাহরণের সাথে মিলিয়ে দেখুন।
  1. Top activating examples: do all of them share one idea? If yes, the feature is clean.
  2. Weak examples: scroll down to the lower activations. Do they show a second meaning?
  3. 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.
  4. 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
0Normal output.
SmallA faint lean toward the feature's idea.
MediumThe idea appears often and the text stays fluent.
Too largeThe 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.

  1. Step 1
    New chat

    Copy 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.

  2. Step 2
    Same chat

    Open 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.

  3. Step 3
    Same chat

    Back 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.

Try a harder versionOpen the Steer tool for a feature you checked. Try a small strength and a large strength. Write down when the text stays fluent and when it breaks.

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.csv file 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]

From rows of data to a map you can exploreYour datatext, image, audio+ columnsEmbedding modele.g.all-MiniLM-L6-v2Vectors384 numbers per rowUMAP384 numbers → 2Atlas viewmap + linked chartsIn the view you can:see clusters and labelssearch and find neighboursfilter with linked chartshover to read each rowThe embedding model decides what “similar” means. UMAP only draws the result.
The pipeline. The default text model in the docs is all-MiniLM-L6-v2, which gives 384 numbers per row. UMAP then reduces each vector to two numbers, so the rows can be drawn as points.
পাইপলাইন। docs অনুযায়ী text-এর default model all-MiniLM-L6-v2, যা প্রতি সারিতে ৩৮৪টি সংখ্যা দেয়। তারপর UMAP প্রতিটি vector-কে দুটি সংখ্যায় নামায়, যাতে সারিগুলো বিন্দু হিসেবে আঁকা যায়।

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

FeatureWhat it doesQuestion it helps with
Automatic clustering and labelsFinds dense regions and names themWhat are the main topics in my data?
Search and nearest neighboursFinds rows similar to a query or to a selected pointDo I already have an example like this one?
Density rendering with WebGPUDraws up to a few million points with density contoursWhere is the data thick, and where is it thin?
Linked charts and cross-filteringA chart and the map filter each otherWhich part of the map has the low-rated rows?
Multimodal viewersText, image, audio, numeric, categorical, and time columnsCan I look at pictures or listen to clips, not only read text?
MCP serverLets an AI agent query the data, make charts, and take screenshotsCan an agent explore the data for me?

The feature list follows the project's home page and overview.[28]

A mock Embedding Atlas view of support messages (invented data)billinglogin problemsshippingfeature requestsselected+ 3 nearestneighboursoutlierLinked chart: rows by topicbillingloginshippingfeaturesSelect the login cluster.The chart counts only those rows.Same idea in reverse: click a barand the map highlights those points.
What you look for in the map. Clusters show topics. A selected point and its neighbours show what the model thinks is close. A lone point may be an error or a new topic. The data here is invented.
মানচিত্রে কী খুঁজবেন। ক্লাস্টার মানে বিষয়। একটি বাছা বিন্দু ও তার প্রতিবেশী দেখায় মডেল কোনগুলোকে কাছাকাছি মনে করে। একটি একলা বিন্দু ভুল বা নতুন বিষয় হতে পারে। এখানকার data বানানো।

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.

  1. Step 1
    New chat

    Copy 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,topic and 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.

  2. Step 2
    Same chat

    Open Embedding Atlas, choose Load Data, and select tickets.csv. If it asks, choose the message column as the text. Wait for the map. If the tool has a colour setting, colour the points by topic.

    You should see: A map with 4 clear groups (billing, login, shipping, returns). One lone point, the cake message, sits away from all groups.

  3. Step 3
    Same chat

    Hover 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.

Try a harder versionAdd 5 more cake or baking messages to the file and load it again. Does the lone point become a new cluster?

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. [1]Cho et al., "Transformer Explainer: Learning LLM Transformers with Interactive Visual Explanation and Experimentation" (arXiv, 2024)
  2. [2]Polo Club of Data Science, Georgia Tech, "Transformer Explainer" (interactive page)
  3. [3]Vaswani et al., "Attention Is All You Need" (NeurIPS 2017)
  4. [4]Brendan Bycroft, "LLM Visualization" (interactive 3D page)
  5. [5]Brendan Bycroft, "llm-viz" (source code of the LLM Visualization page)
  6. [6]Andrej Karpathy, "nanoGPT" (minimal GPT training and inference code)
  7. [7]3Blue1Brown, "Neural networks" (video lesson series, Deep Learning chapters 1–7)
  8. [8]Jay Alammar, "The Illustrated Transformer" (blog post, 2018)
  9. [9]Bahdanau, Cho, Bengio, "Neural Machine Translation by Jointly Learning to Align and Translate" (ICLR 2015)
  10. [10]Smilkov, Carter et al., "TensorFlow Playground" (interactive page)
  11. [11]Smilkov, Carter, Sculley, Viégas, Wattenberg, "Direct-Manipulation Visualization of Deep Networks" (ICML Workshop on Visualization for Deep Learning, 2016)
  12. [12]Sebastian Raschka, "A Visual Guide to Attention Variants in Modern LLMs" (Ahead of AI, 22 March 2026)
  13. [13]Ainslie et al., "GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints" (EMNLP 2023)
  14. [14]DeepSeek-AI, "DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model" (2024)
  15. [15]Beltagy, Peters, Cohan, "Longformer: The Long-Document Transformer" (2020)
  16. [16]Maarten Grootendorst, "A Visual Guide to Mixture of Experts (MoE)" (Exploring Language Models, 7 October 2024)
  17. [17]Shazeer et al., "Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer" (ICLR 2017)
  18. [18]Fedus, Zoph, Shazeer, "Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity" (JMLR 2022)
  19. [19]Jiang et al., "Mixtral of Experts" (Mistral AI, 2024)
  20. [20]"LLM Inference Handbook", chapter "What is LLM inference?" (handbook.modular.com)
  21. [21]Kwon et al., "Efficient Memory Management for Large Language Model Serving with PagedAttention" (SOSP 2023)
  22. [22]Leviathan, Kalman, Matias, "Fast Inference from Transformers via Speculative Decoding" (ICML 2023)
  23. [23]Neuronpedia, "An open source interpretability platform" (neuronpedia.org)
  24. [24]Cunningham et al., "Sparse Autoencoders Find Highly Interpretable Features in Language Models" (2023)
  25. [25]Lieberum et al., "Gemma Scope: Open Sparse Autoencoders Everywhere All At Once on Gemma 2" (Google DeepMind, 2024)
  26. [26]Bricken et al., "Towards Monosemanticity: Decomposing Language Models With Dictionary Learning" (Anthropic, Transformer Circuits Thread, 2023)
  27. [27]Lindsey et al., "On the Biology of a Large Language Model" (Anthropic, Transformer Circuits Thread, 2025)
  28. [28]Apple, "Embedding Atlas" (documentation and live demo)
  29. [29]Ren, Hohman, Lin et al., "Embedding Atlas: Low-Friction, Interactive Embedding Visualization" (2025)
  30. [30]McInnes, Healy, Melville, "UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction" (2018)
  31. [31]Su et al., "RoFormer: Enhanced Transformer with Rotary Position Embedding" (2021)
  32. [32]Brown et al., "Language Models are Few-Shot Learners" (NeurIPS 2020)