Back to Playground
AIJavaScriptWebGL

browser-train

Full LLM training in one HTML file. No server, no deps, just open it.

The Story

This is a 345K-parameter GPT (3 layers, 4 heads, d=96) that trains from scratch in your browser using plain JS. Character-level tokenizer, tape-based autograd, AdamW, the whole thing. It fits in ~500 lines because I didn't try to make it pretty.

The default corpus is 14KB of Shakespeare. With 345K params the model can't memorize it — it has to learn actual patterns: word structure, line breaks, which characters tend to follow which. Give it a few minutes and it starts producing recognizable iambic-ish dialogue.

You can also paste your own text. Anything works as long as it's over 100 chars.

Nerd details: causal self-attention (each position only sees previous positions), cross-entropy loss, gradient clipping at norm 1.0, LR warmup then cosine decay. Backprop walks a tape in reverse — same idea as PyTorch autograd but dumber. Open multiple tabs and they sync weights via BroadcastChannel.