Change the wording, keep your experiment. Saved in this browser when storage is available.
Inside a prediction
How context changes a prediction
Try “river bank” and “savings bank”. The surrounding word changes which next words look likely. The model’s stored settings stay the same; the calculations change with your sentence. That is why changing a prompt is different from training a model.Change "river" to "savings" and follow the next-word probabilities. This shows how context can change a prediction without changing the model’s weights, a distinction that helps explain why editing a prompt differs from training a model.
Real calculations with hand-designed teaching weights. This is a miniature explanation, not a trained language model.
Change river to savings to compare the results. Both sentences use the same fixed parameters.
Rows: The, river, bank, is. Columns: f1 to f4. Depth: four calculation snapshots.
Each tile is a number, not a fact or physical memory location. Inspect the selected snapshot with its tiles or arrow keys. Choose another stage to inspect its numbers, or use Flat view to unlock every snapshot.
Step 1 of 5
Look up the token embedding
Inspect a number
After the final word “is”
What could come next?
All eight words in this toy vocabulary. These are next-token probabilities, not confidence that a statement is true.
Change the context word to compare predictions, or select Next step to inspect the calculation.
Inspect the tables and calculations
The cube, tables and arithmetic show the same selected word and coordinate. Expand a section below to inspect its values or read how they are calculated.
Read the cube as a table
The table and cube read the same four arrays. Cube tiles round to three decimal places for readability; full values and exports preserve the browser numbers. More dimensions are possible; a three-dimensional picture is only one way to show them.
Where do the first numbers come from?
A token ID selects a row in an embedding table. That is an actual lookup. The ID itself is an address, not a score for meaning. Real models learn their embedding values during training; Jonathan and AI assistance authored this tiny table to make the arithmetic legible.
| Token ID | Word | f1 | f2 | f3 | f4 |
|---|---|---|---|---|---|
| 0 | The | 0 | 0 | 0 | 1 |
| 1 | river | 2 | 0 | 1 | 0 |
| 2 | savings | 0 | 2 | 1 | 0 |
| 3 | bank | 0 | 0 | 1 | 1 |
| 4 | is | 0 | 0 | 1 | 0 |
| 5 | muddy | 1 | 0 | 0 | 0 |
| 6 | closed | 0 | 1 | 0 | 0 |
| 7 | quiet | 0 | 0 | 0 | 0 |
No coordinate is a universal “river” or “money” axis. Larger language models usually split text into subword tokens and learn distributed representations.
Are these numbers still made of bits?
Yes. Bits encode the numbers; tensors organize them into arrays. Select a tile above to see that number rounded to a 32-bit floating-point representation.
One sign bit, eight exponent bits and 23 fraction bits. This browser computes using 64-bit JavaScript numbers. The 32-bit display is a separate conversion, so rounding may change the value.
How does attention mix information?
Attention mixes information from the available words. It calculates how much each word contributes, with shares adding up to one, then combines their numbers using those shares. Select a word and a number in the cube to inspect the calculation. The technical names for these parts are query, key and value.A query is compared with each available key. The comparisons become shares that sum to one. Each share multiplies a value vector, and the results are added. Select a word and coordinate above to see its exact calculation.
Causal language models cannot use later words to predict an earlier one. Turn this off as a comparison experiment; it is no longer causal attention. The final position has no future word in either mode.
Q = XWq; K = XWk; V = XWv; A = softmax(QKᵀ / √4 + mask); C = AV
The next step applies a feed-forward transformation independently to each position: F = ReLU(CW1)W2. Finally softmax(FWout + bias) gives the eight output probabilities.
Each position is calculated from the same input snapshot. Within this one block, the updated “bank” row does not feed into “is”. A later block could use the updated rows. The final “is” row supplies the next-word prediction shown here.
Weights, working numbers and retrieved text
Parameters
These are the model’s stored settings. Real models usually learn them during training. They stay fixed while the model answers. This toy’s settings were designed by hand.Embedding and projection tables. In an ordinary model these are learned during training and held fixed while answering. This toy uses authored parameters.
Activations
These are the working numbers you see in the cube. A different sentence changes them. They are temporary calculations, not a permanent store of facts.The cube's intermediate calculations. They change with the input and context. They are not a permanent filing cabinet of facts.
External retrieval
A separate search can find documents and add text to a model's context. This exhibit does not retrieve documents. That process is different from selecting an embedding row or combining vectors.
Real language models repeat many blocks and commonly include position information, multiple attention heads, residual connections and normalization. Those are omitted here. The four slices are teaching snapshots, not four complete Transformer layers. An output also need not be the highest-probability token; sampling can choose another.
Try the idea on a new sentence.
Imagine “The wooden bat is” and “The flying bat is”. Before context is mixed, what happens to the embedding for the same token “bat”?
Choose a prediction. Assume the same token ID and fixed embedding table.
Save or rerun this experiment
Keep every input, parameter and result, or run the calculation yourself with standard Python. No package installation needed.
Next: See what changes when a model receives a missing source sentence. Retrieving a document supplies context; it is different from looking up a token's embedding.
Sources and how this was made
An original explanation by Jonathan Simone with AI assistance. No pretrained model or live inference service is running here. All lesson calculations run in your browser.
- PyTorch: embedding lookup
- Vaswani and colleagues: attention, feed-forward layers and output softmax
- NVIDIA: binary floating-point representation
- Lewis and colleagues: retrieval-augmented generation
- Brendan Bycroft's LLM visualization and Transformer Explainer inspired the linked views. No code or artwork copied.