Trace a tiny deterministic decoder-like block from toy tokens to causal self-attention to next-token probabilities. Every displayed number is computed locally from fixed teaching weights.
AI Playgrounds
Evidence boundary. This is a toy deterministic model, not a pretrained LLM. It does not reproduce GPT, Claude, Gemini, or another frontier model. Its attention weights expose one numeric mixing mechanism; they are not a general explanation of model reasoning or understanding.
1.00
1 · Tokenizesurface text → toy token IDs
2 · Representembedding + position
3 · AttendQKᵀ / √dₖ → mask → softmax
4 · Predictfinal state → logits → probabilities
TOKENS · buttons support keyboard selection
Selected token vectors
Attention is not an explanation. These weights show how this toy head combines value vectors. The largest weight is not automatically the reason for a final output logit.
Next-token distribution
Columns show token, relative bar, logit, and probability. Temperature rescales fixed logits before softmax; it does not retrain the model or change its learned weights.
Self-attention calculation
The scaled score matrix, causal mask, and post-softmax attention weights are shown separately. Weight cells retain exact numbers, so color intensity is redundant rather than the sole information channel. Permitted weight cells are keyboard-operable buttons.
1 · Scaled scores q·k / √dₖ
2 · Causal mask
3 · Attention weights after softmax
Select a permitted attention cell to inspect its source key/value vectors, raw dot product, scaled score, and weight.
✨ Featured experiment
The causal mask blocks the future
Core question: Why must a next-token model hide later positions?
Run and watch: Apply the mask-leak scenario and compare the same attention row with the mask on and off.
🎯 Try these scenarios first
Pick a scenario, predict what should happen, then apply it and compare the result with your prediction.
Scenario 1: From prompt to prediction
Core question: How does the final token become a probability distribution?
Run and watch: Use “I like cats” with positions and the causal mask on, then follow the final token through all four stages.
Predict first: Predict which permitted source position will receive the largest attention weight.
Explain afterward: Explain how the selected token’s final state becomes logits and probabilities.
Scenario 2: The causal mask blocks the future
Core question: Why must a next-token model hide later positions?
Run and watch: Apply the mask-leak scenario and compare the same attention row with the mask on and off.
Predict first: Predict which previously blocked cells will gain nonzero weight.
Explain afterward: Explain why using a future token would make the next-token test invalid.
Scenario 3: Word order changes the representation
Core question: Why are the same words in a different order not the same input?
Run and watch: Apply the order scenario, then compare the final-token vector with position information on and off.
Predict first: Predict where the first numerical difference will appear.
Explain afterward: Explain what position vectors add that token embeddings alone do not.
Scenario 4: One score change can spread forward
Core question: How can a small query or key change affect the final prediction?
Run and watch: Apply the Q/K perturbation and trace the changed score, attention weight, final state, and probability.
Predict first: Predict which source token’s weight will move most.
Explain afterward: Explain why changing a score can affect every normalized weight in the row.
Scenario 5: Temperature changes confidence, not learning
Core question: What changes when temperature changes but model weights stay fixed?
Run and watch: Apply the temperature scenario and compare the logits with the probability distribution.
Predict first: Predict whether the top token changes or only the sharpness changes.
Explain afterward: Explain why temperature does not retrain the model.
Use one Guided Challenge. Predict first, reveal the mechanism, then connect a concrete attention/logit/probability change to the next-token distribution.
Use the existing Guided Challenge for the run/reveal step. Responses stay in this browser unless you deliberately copy or print them.
State snapshot appears here.
Before you read
A Transformer turns tokens into vectors, lets each position mix permitted earlier information, and converts the final vector into next-token probabilities. This lab keeps every number small enough to inspect.
Terms used in this explanation
Token
A piece of text represented by one ID in this toy vocabulary.
Embedding
The starting vector for a token.
Position vector
Extra values that tell the model where a token appears.
Query, key, value
Three vectors used to score and mix information.
Causal mask
A rule that blocks attention to future positions.
Attention weight
A softmax-normalized coefficient used to mix value vectors.
Logit
An unnormalized score for a possible next token.
Temperature
A scale applied to fixed logits before softmax.
1. Tokenize and add position
The toy tokenizer maps each displayed piece to a fixed ID. An embedding table turns each ID into a vector.
A position vector is added to that embedding. Without it, repeated tokens begin with the same representation wherever they appear.
2. Score permitted source positions
The model derives a query, key, and value vector at each position. A query–key dot product measures one numerical match, then division by the square root of the key dimension keeps scores in a workable range.
The causal mask replaces future scores before softmax. A masked position receives no attention weight.
3. Mix values, not token labels
Softmax turns the permitted scores into weights that sum to one. The attention output is the weighted sum of value vectors.
A large weight matters only through the value it multiplies. The weight alone is not a complete explanation of the prediction.
4. Convert the final state into a prediction
The toy block combines the attention output with its residual and feed-forward path. Output weights map the final state to one logit per vocabulary item.
Softmax converts logits into probabilities. Temperature rescales those same logits: lower values sharpen the distribution and higher values flatten it.
What this model leaves out
This deterministic block is not pretrained, does not learn during the activity, and does not reproduce a production language model. Real systems use many layers, heads, larger vocabularies, learned parameters, and a separate generation rule.
Attention weights show one mixing operation. They do not reveal a model’s complete reasoning, understanding, or causal explanation.
What information is lost if token order is ignored?
Why should a next-token predictor be unable to read the next token?
What is the difference between a score and a probability?
Post-exploration prompts
Change one token and identify the first changed number.
Turn the mask off. Which calculation becomes invalid for next-token prediction?
Change temperature. Which values stay fixed?
Why is the largest attention weight not the whole explanation?
Misconceptions to test: one token always equals one word; attention is understanding; the largest weight is the complete reason; temperature changes learned weights; the highest-probability token must always be selected.
♿ Text and keyboard support
Text and keyboard support
Use Tab and Shift+Tab to move through controls. Use Enter or Space on buttons and arrow keys on sliders or select controls.
Text equivalent for the current visualization state.
Check your model of the model
“A token is one word.”Not generally. This applet uses a deliberately simple source-locked toy tokenizer; unknown words map to <UNK> and a period is its own token.
“Attention tells us what the model understands.”No. Attention weights are numeric mixing coefficients, not a direct reading of understanding.
“The largest attention weight is the reason for the prediction.”No. Value vectors, residual paths, the feed-forward transform, and output weights also affect logits.
“The transformer searches the internet for the next word.”Not here. The applet makes no network request or retrieval call.
“The causal mask makes the model forget future words it already saw.”The mask is a structural constraint on which source positions a destination may use.
“Temperature changes the learned model weights.”No. Temperature rescales fixed logits before softmax.
“The most probable token is always selected.”A probability distribution and a generation selection rule are different.
“Position vectors are word meanings.”No. They contribute position-dependent information to this toy representation.
“The model stores complete answers and retrieves them.”This applet computes logits from numeric state. Retrieval is a separate mechanism.