a project by Cheng Lou · explained
When would you want your JavaScript to learn?
When you have code people trust, rules that must stay exact, and data that should tune the numbers. Handwired runs that code as a neural net, exactly, so it can learn. Try the most common case right here.
your ranking code runs as a Handwired net
- pinned result on top
- out-of-stock in top 10
- shoppers' favourite in top 3
results for “wireless headphones” · or click one yourself
Shoppers are simulated with a hidden taste (2·match + 1·pop + 4·fresh + 3·rating, hidden from both models), attention that fades with position (1 / (1 + 0.35 × position)), and less interest in out-of-stock items. Rates are measured live on seeded test lists of 20 results each. Full walkthrough, including the generic model that breaks the rules →
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. Upstream's 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
Upstream's 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.