The Code/X ArchiveView on X
Cheng Lou

@_chenglou

My dear friends, I’d like to show you my latest toy project

Introducing Handwired: turn your regular JavaScript code into a neural net!
- no training
- exact outputs vs the JS program
- fully differentiable

All runnable in a browser, without GPU
4531K11.3K13.5K
Cheng Lou

@_chenglou

Handwired bridges the gap between traditional code and a neural net in a funny way. It turns if-else and loops into weights, like so:
Image from the post
1012629154
Cheng Lou

@_chenglou

Here’s a little OS made with it. Giant scroll views, idiomatic text input, animation and styling, etc. You can check in the browser inspector that there’s no diffusion, no llm, and just regular DOM elements

Yet if you check the GitHub source, it’s a bunch of compiled neural net numbers doing inference in real time in a browser
68686166
Cheng Lou

@_chenglou

Isn’t a neural net probabilistic? Yes if you train it, no if you hand-wrote the weights that correspond exactly to your program, lol 🙂
51675967
Cheng Lou

@_chenglou

What happens in we unfreeze some of these weights and actually train them? Well you can apply existing neural net techniques to it, losses and backprops and all, and now the UI becomes a bit more “learned”

Here’s a photo gallery where on the left I edit the rectangles and the right side gives me a new view where the photos learn to align themselves, training in real time as you drag (because the param count is so tiny).

This demo done fully in JavaScript, with JS looping through them numbers and backpropping. Stupid but fun! I’ve exposed the loss param slider you can play around with
813575134
Cheng Lou

@_chenglou

One more demo! Searching through 100k JSONs in real time. The code was written mostly traditionally, then transformed into actual WebGPU matrices to massively parallelize the JSON search. The regex, JSON parsing, highlighting & matching are all one giant exact neural net
719632175
Cheng Lou

@_chenglou

You can also imagine attaching a specific Handwired neural program to, say, nanoGPT. Now your llm can speak both Shakespeare and that exact specific JavaScript program =D
1428735
End of thread