Markov chain
Looks up which tokens followed the same context in the training text.
- Memory
- Transition table
- Context
- Last 1–2 tokens
- Training
- Count once
Train both on the same text. One counts transitions; one learns weights. Then compare what they write.
Waiting to count transitions.
Waiting to train.
Looks up which tokens followed the same context in the training text.
Uses attention and learned weights to score every token.
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 can only use tokens from the 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 predict, sample, and append. They learn in different ways.
lowercase the training text, then split it 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 seenlowercase the training text, then split it 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