Skip to applet controls
← AI Playgrounds

Transformer Language Modeling

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.
Quick Assign · QA-TRANSFORMER-01 · 10–15 min

Attend, then predict

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.

For teachers

Curriculum: Tokenization, embeddings, position, query–key scores, causal masking, softmax, logits, temperature, and evidence limits.

Pre-exploration prompts

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

Read the current model state in the applet’s text-state panel.

Important results are available as text and do not depend only on color or motion. This does not replace a full human assistive-technology audit.

↑ Back to the applet controls

Guided Challenges · predict before reveal

Accessible numeric state

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.