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

No shoppers yet. Left: the guessed formula. Right: a generic net, starting from random numbers as they do.

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:

favourite in the top 3: –
  • 📌 pinned result first
  • no out-of-stock in the top 10

    A generic neural net

    Learning moves 65 numbers nobody can read:

    favourite in the top 3: –
    • 📌 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?

      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?

      Live demos on this site

      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.