Gradient Decent
Parts of the browser that were built for drawing and styling, used as accidental calculators to run small neural networks: the page layout engine, canvas blend modes, CSS colour maths and 3D transforms, the Web Audio graph and an SVG filter. None of it is useful and all of it is slow. The point was to see whether it could be done at all, and then to check that it gets the right answer.
The name is the joke. Gradient descent is how models get trained. Nothing on these pages trains anything (the few models made for this were trained ahead of time, in a script, the normal way): they only run models, using actual colours and gradients. So it's gradient, and it's decent.
The experiments
Each page runs a real model, shows the browser feature doing the work, walks through how it works, and races it against a plain JavaScript copy of the same model so you can check the answers and see what the trick costs. Speeds are from headless Chrome on a modest test machine.
You always pour lorem ipsum into a page layout. This page layout writes its own. A small attention model trained on Cicero, the book lorem ipsum was cut from, where every multiply, sum and pick is the size of a box. What it writes gets typeset into a fake magazine.
31K weights · 66,000 boxes · about 0.6 s a word piece Layout Can page layout run a language model?
A tiny Shakespeare babbler where every number is the size of a box: aspect-ratio multiplies,
rows of boxes add, leftover space subtracts, and the longest bar in a grid column is the next letter.
A chat model that talks like a three-year-old. The weights are pictures and every matrix multiply is a blend mode.
1.8M weights · about 15 tokens a second Canvas Can blend modes write a story?A model that writes wobbly children's stories. Its weights are only ever -1, 0 or 1, so every weight is a red, green or black pixel.
1M weights · 20 to 30 tokens a second CSS Can a stylesheet run a language model?
The Shakespeare babbler's whole forward pass as CSS colour maths: color-mix() adds and
relative colours multiply.
The same babbler with the JavaScript taken out. The clock, the memory, the dice and the text are CSS.
21K weights · a little under one character a second · Chrome and Edge only CSS Can CSS transforms multiply matrices?
The babbler as a wall of tilting cards. Every neuron is a long chain of
matrix3d() transforms, and the answer is how far its card tips.
The babbler as a Web Audio graph. The weights are a sound file, each layer is a convolution reverb and the activation is a distortion curve.
21K weights · about 13 ms a character SVG filter Can a photo filter read handwriting?
Not a language model: a digit reader. Draw a digit and a single SVG <filter> runs the
whole network, with feConvolveMatrix for the layers and feMorphology for the
pooling.
The rules
- The maths has to be done by something that wasn't meant for it. A blend mode, a colour function, a transform, a reverb, a layout pass, a filter. Not WebGPU, WebGL or WASM, which is how everyone else does it.
- JavaScript is allowed for the bookkeeping. Every page says exactly which steps are script and which aren't, and the page source is commented so you can check.
- It has to be a real model and it has to be right. Each one is checked against an ordinary implementation of the same weights, and the page lets you rerun that check.
- It doesn't have to be fast. It won't be. Each page says how slow.
- It doesn't have to work everywhere. These lean on the newest corners of the browser. They are tested in Chrome; the lorem page also runs in Safari on iOS, and the no-script page needs Chrome or Edge. Each page lists what it needs.