a project by Cheng Lou · explained
Handwired: your JavaScript, running as a neural net that can learn
Handwired, by Cheng Lou, turns ordinary JavaScript into an exact neural net: same answers, but differentiable, so data can tune its constants while its rules stay exact. Watch it happen below.
Live demo: a search ranking that learns from clicks
Each shopper sees the list on the left and clicks what they like. After every 25 shoppers, both models take a few learning steps on all the clicks so far.
Your formula, as a Handwired net
Learning moves only these four numbers:
- 📌 pinned result first
- no out-of-stock in the top 10
A generic neural net
Learning moves 65 numbers nobody can read:
- 📌 pinned result first
- no out-of-stock in the top 10
Shoppers are simulated (hidden taste: 2·match + 1·pop + 4·fresh + 3·rating). Measured live on 200 seeded test searches. How this works, step by step →
When would you use this?
Ranking from clicks
Your hand-tuned search formula learns its weights from shoppers. "Pinned first" and "never show out-of-stock" stay exact. A generic model breaks both.
Layout from a designer's drags
Drag a few cards to the sizes you want; the layout function's constants update and every card follows, with zero overflows.
Physics from a recording
Fit gravity, drag and bounce so a simulated ball matches a recorded path, then replay it as code.
Accessible colour themes
Point at the colours you like; the theme function learns its constants for light and dark, and every text pair stays WCAG AA.
Search 100,000 JSON docs on the GPU
Cheng Lou's demo: plain-looking matching code run as GPU programs, with the same answers as JavaScript.
New to the idea? The beginner lesson (a cat deciding how hard to jump) explains it from scratch in three minutes.
Handwired is an open-source project by Cheng Lou that turns regular JavaScript code into a neural net: no training, exact, yet fully differentiable, and runnable in a browser without a GPU. This site is an independent, hands-on guide with live demos that run the real Handwired runtime.
What is Handwired?
Handwired is a way to write a program as a fixed list of 32-bit float operations — weighted sums, products with a ReLU, and a few exact helpers — so the program is a neural network. Its weights are written by hand (hence the name) instead of learned, which is why it is exact. Because it only uses differentiable primitives, you can still compute gradients through it and train its numbers later.
The canonical example from the Handwired homepage:
// your code
const result = a > 4 ? 10 : 12
// turns into (relu(x) is Math.max(0, x))
const above4 = relu(a - 4) - relu(a - 5)
const result = above4 * 10 + (1 - above4) * 12
For any integer a, both versions return the same number. Try it live →
What can you do with it?
- Run UI logic as a network. Handwired's own Mini OS is a small desktop — windows, dragging, stacking, springs, a photo gallery — driven by one compiled program with 9,909 weights in 130 layers and zero training.
- Unfreeze the weights and train them. The Learned gallery trains a program's coefficients in real time with its own gradients.
- Get GPU-scale parallelism from single-threaded-style code. The JSON search demo writes its programs as WebGPU shaders and searches 100,000 JSON documents at each keystroke.
Live demos on this site
Soft switch
Drag a and watch a > 4 ? 10 : 12 computed by ReLUs.
Exact comparisons
emitCompare, emitSelect, emitMinimumExact vs plain JS, fuzzed.
Code → network
See the operations and layers a program becomes.
Unfreeze & train
Gradient descent on a handwired program's constants.
Toggle switch
Handwired's own template app, a spring-animated switch run as one program.
Where do I start?
Read Why Handwired for the idea, Concepts for how conditionals become ReLUs and why the result is both exact and differentiable, then Getting started to run it yourself. Common questions are answered in the FAQ.