Tiny LLM Lab

A real, very small language model that runs in your browser. It learns which word comes next from any text you give it, saves what it learned as numbers, and uses those frozen numbers to predict.

Untrained · random weights
Step 1 · Train

Learn from text

Tokens and their IDs

Training examples (current token → next token)

Rounds trained0
Error (loss)–
Weights0
Error over time

Weights in memory

rows = current token · columns = possible next token

positive: likely next negative: unlikely next changed most in last training

Biggest changes in the last training

  • Nothing trained yet.
Step 2 · Save

Save the weights to a file

Training happens in memory. Saving writes the learned numbers into a weights file. Prediction only ever uses the saved file.

tiny_model.json
No saved model yet. Train, then save.

Same format as tiny_llm.py, so a model trained in Python can be loaded here.

Step 3 · Freeze and predict

Predict the next token

The saved weights are loaded and frozen. Nothing you do here changes them.

1. Look up the saved weights for ""

Raw scores for every token in the vocabulary.

2. Softmax turns scores into chances

Higher score, higher chance. All chances add up to 100%.

1.0 Low temperature sharpens the chances, high flattens them. Top-k keeps only the k most likely tokens.

Why doesn't it always pick the top token?
Only counts the draws. Nothing is added to the text.

Temperature changes the jar: low makes the top token fill almost every marble, high makes the colours more even. Top-k decides how many different colours are allowed in the jar at all; top-k 1 means only the top token, so it is picked every time.

A simplified model for understanding. Its tokens are whole words, it looks only at the last token, and it uses one grid of weights. Large language models use subword tokens, billions of weights and the whole input to compute their scores, but follow the same cycle: random weights, training that adjusts them, a saved weights file, and frozen weights that score every possible next token. Next: how text becomes numbers.