HeyMSK

Build a small language model

Let's compare what we're building here with current state-of-the-art language models.

FeatureOur small modelGPT-6 AstraClaude Opus 5.5
What it doesTrained on simple addition examplesGeneral-purpose, multimodalGeneral-purpose, multimodal
Parameters (numbers adjusted during training)413,440Approx. hundreds of billions to trillionsApprox. hundreds of billions to trillions
Training timeApprox. 51 seconds in our recorded runApprox. several monthsApprox. several months
Text it can use at once (context window)32 tokens1,050,000 tokens1,000,000 tokens
Where it runsYour browser or computerHosted serversHosted servers
Downloadable weights (learned parameter values)YesNo public downloadNo public download

Language models behind tools like ChatGPT generate text one token at a time. They learn patterns from training examples, then use those patterns to predict what comes next. A token can be a word, part of a word or a character.

In this tutorial I use addition to build a small model you can run here. A calculator follows an addition rule. My model learns from examples such as 1+1=2 and predicts one character at a time. That means it can also get the answer wrong.

Run 1+1=, then try 1+1. Compare what it writes next.

Try the finished model

Runs on your device. First load is about 14 MB.

Improved model

Exact input: "1+1="

Model output
No output yet
Input + output
1+1=

Run to see a prediction.

Model and input details

Printable ASCII is passed verbatim. BOS is added once. All 98 tokens remain available. Context: 32 tokens. Run budget: 16 output tokens, capped by remaining context. EOS ends generation. Unexpected PAD or BOS tokens are visible.

Improved model. Epoch 140. 1.74 MB of weights. The WASM runtime is downloaded on first use.

Start building
  1. Predict one character
  2. Prepare examples
  3. Turn text into tokens
  4. Build the network
  5. Train it
  6. Test it
  7. Teach a new format
  8. Check probabilities
  9. Train from feedback
  10. Understand the model’s limits
Code and training steps