Just for fun, I trained a fruit fly's brain to write Python 😂
Two weeks ago, Google Research and HHMI Janelia released MaleCNS, a map of all 166,700 neurons and 25.6 million connections in an adult male fruit fly's brain and nerve cord. I turned that wiring diagram into a neural network and trained it on 60,000 short Python programs.
Every connection is a directed edge from one neuron to another, so the connectome is a graph with 166,700 nodes and 25.6 million edges. I treated that graph as one recurrent layer whose weight matrix is its adjacency matrix. A dense 166,700 × 166,700 matrix would have 27.8 billion entries. But only the 25.6 million entries where the fly has a synapse are allowed to be non-zero, which are our trainable weights.
A normal language model has an embedding layer feeding its first layer and an output head reading its last. Here there is only one layer, so I picked 192 random neurons as the input port and 256 random neurons as the output port. Each token has a learned 192-dimensional embedding that is added to the values of the input neurons, and the values of the output neurons go through one linear layer to give next-token logits.
This is essentially like an RNN. The hidden state has one number per neuron, 166,700 in total, and the recurrent weights are the adjacency matrix from above. In a normal RNN that matrix is dense, so every hidden unit reads every other unit at each step, and any input can reach any output in one step. Here each neuron reads only the roughly 150 neurons that connect into it, so information spreads one edge per token, and it is the fly's wiring that decides which neurons a token can reach and how many tokens it takes to get there.
Training is standard next-token prediction with backprop through the recurrence. The model has 27.6M trainable parameters, 25.6M of which are the synapse weights. That is about one-fifth of GPT-2 small.
Over the course of training, perplexity went from 4,096 to 15 on held-out programs. It picks the exact next token 45% of the time, and 75% of the functions it writes are valid Python.
In the video, every neuron is drawn at its real 3D position and colored by region (blue optic lobes, orange central brain, green nerve cord), and a sample of the synapses is drawn as faint lines between cell bodies.
Act I is training. Neurons light up as their synapses change, and the bright lines are the 500 synapses that moved most in the last 500 updates. Next to the brain, the same prompt is decoded at every checkpoint so you can watch the output improve, from random tokens at the start, to syntax-shaped nonsense, to a correct-looking loop by the end.
Act II is the trained brain writing is_prime from an initial prompt. Neurons light up as their state changes on each token, the bright lines are the signal in flight, and the video marks what is wrong with the result line by line.
Nothing about this brain evolved for code though.
It evolved for vision, flight, walking, smell and courtship, but it still learns Python, and the wiring itself is doing work. In fact, in a control experiment, if I keep every neuron's number of connections but shuffle who connects to whom, perplexity gets a third worse, 15.0 to 20.1. And if I freeze the synapses at their anatomical values and train only the output layer, it collapses to 41.9.
It is really amazing that evolution's connectivity helps it learn, even on a task evolution never saw or intended.
Imagine what a whole mouse brain, with hundreds of times more neurons, would be able to learn. Training on real wiring at that scale may teach us things about architecture that no search over transformer variants would find, and the end of that road may be running on the biological hardware itself instead of on a GPU.
What if pig farmers end up with more compute than Jensen 😂