Markov chain
It asks: “What exact tokens came next after this exact context in the training text?”
- Memory
- Transition table
- Context
- Last 1–2 tokens
- Training
- Count once
Give both models the exact same evidence. One memorizes transition counts. The other learns thousands of numerical weights. Then watch them write side by side.
Waiting to count transitions.
Waiting to train.
It asks: “What exact tokens came next after this exact context in the training text?”
It asks: “Which parts of the recent context should influence my learned probability for every token?” PyTorch can run those calculations on a remote GPU.
Same goal, different machinery. Both output a probability distribution over the same vocabulary. The difference is how they produce it.
Its counted-path output will appear here.
Generate to reveal this model's next-token probabilities.
Its neural output will appear here.
Generate to reveal this model's next-token probabilities.
✓ Both models are hard-limited to tokens found in your shared training text.
| Question | Markov chain | Tiny transformer |
|---|---|---|
| What gets learned? | Counts of observed transitions | Embeddings and matrix weights |
| Can it score an unseen path? | No, it backs off to a shorter seen context | Yes, every vocabulary token gets a score |
| Does word similarity exist? | No, tokens are just table keys | Partly, tokens get learned vectors |
| Where does it run? | Locally in this browser | PyTorch on a Modal T4, with a browser CPU fallback |
| Best teaching insight | Prediction can start with simple statistics | Attention learns which context matters |
Both repeat “predict, sample, append.” Training is where their paths split.
split the training text into tokens
for every token:
count what followed the last 1–2 tokens
to generate:
look up the current context
sample from its counted next tokens
back off if that context was never seensplit the training text into tokens
give each token and position a learned vector
repeat for 6 passes, bounded to 120–600 updates:
split Q, K, V across 4 attention heads
attention ← softmax(QKᵀ + padding mask) × V
hidden ← 2 × (attention + feed-forward block)
predict the next training token
update every weight using the prediction error
save the weights under a short-lived model ID
to generate on the GPU:
predict and sample one vocabulary token
stream that token back to the browser
append it and repeat