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.

Layout Can page layout write lorem ipsum?

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.

21K weights · 45,000 boxes · about 0.7 s a character
Canvas Can a 2D canvas hold a conversation?

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.

21K weights · about 40 ms a character
CSS, no script Can a page with no script write by itself?

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.

21K weights · about 40 ms a character
Audio Can you listen to a model think?

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.

10K weights · about 7 ms a digit

The rules

Code: github.com/KealJones/gradient-decent