DEV Community

Cover image for I held a séance with a dead fly's simulated brain. She told me to text my ex.
Frederic Bourouliou
Frederic Bourouliou

Posted on

I held a séance with a dead fly's simulated brain. She told me to text my ex.

Hacktoberfest Open-Source AI Challenge: Ghost in the Machine Submission 👻🌼

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine

This week I ran a simulation of a dead fruit fly's brain on my laptop and asked her, "Do you forgive us for slicing you?"

She didn't feed. She didn't stay still. She wiped her antennae.

The fly was real. She was an adult female, and her brain was cut into more than 7,000 slices and photographed under an electron microscope. Researchers and citizen scientists then spent about 33 person-years correcting the map of her neurons and synapses, and they made it public.

The simulated fly grooming its antennae after a feather is offered

TL;DR. Fly Séance is a séance you hold with a simulation of that brain. You ask a yes-or-no question. Gemma 4, running locally, plays the medium and chooses an offering: sugar, a bitter herb, a feather on the antenna, a breath of candle smoke. The offering drives a model of 127,400 neurons and 52.8 million synapses, and a 3D fly answers with her body. Only the simulated neurons move her. Everything runs on your machine, with no API key.

What I Built

Fly Séance is for curious developers, students, anyone who wants to poke a connectome and watch what happens, with a candle lit.

  1. You ask. "Will my book be a success?"
  2. The medium chooses an offering. Gemma turns your question into stimulation rates for four groups of sensory neurons. On the page, this appears as an engraved object set down next to the fly.
  3. The brain runs. Five simulated one-second trials of the whole model, shown live on a spike raster, a plot of which neurons fire and when.
  4. Code reads the firing rates. If the proboscis motor neuron MN9 crosses its threshold, she feeds: yes. If the antennal grooming neurons cross theirs, she brushes the question off. If neither does, she stays still: no.
  5. The medium speaks. Gemma gets your question, the offering and the verdict, and puts them into words.

On my M5 Max with 48 GB of RAM, the five trials run in parallel and a whole séance, both Gemma calls included, took a median of 4.5 seconds. The first one after startup took 7.9.

The fly does not understand your question. Nobody is home. This is a simplified model of a single brain, with no memory, no learning and no body below the neck.

Real Costume
The wiring map of one actual fly The idea that she can hear you
A neuron model published in Nature, whose predictions about feeding and grooming were tested in the lab "Spirit", "veil", "medium"
Every firing rate on the page, as simulated Reading a meal as "yes"

She is a terrible oracle. "Should I text my ex tonight?" Gemma offered mostly sugar, she fed, and the medium said, "You should text your ex tonight." She also told me to quit my job and write novels. Please do not text your ex.

Demo

Two real séances, recorded on the local page:

There's no hosted demo. Five simulations at once take far more memory than a free server offers, and the point of the project is that it runs on your own machine.

Code

GitHub logo FredBourouliou / fly-seance

A séance with a simulated fruit-fly brain (FlyWire connectome) — Gemma as the medium

Fly Séance

A séance with a simulated fruit-fly brain. You ask a question. A local Gemma model, the medium, turns it into an offering — nectar, a bitter herb, a touch or a breath on the antenna — and may lift the veil, silencing three inhibitory neurons. The wiring diagram of a real fly brain (the FlyWire connectome, 127,400 neurons in the 630 release) is simulated, and the fly's body answers: it reaches for the nectar, it grooms the touch away, or it stays still. The medium then speaks for it.

Everything runs on your own machine. No cloud model, no API key.

The simulated fly grooming its antennae after a feather is offered

The fly does not understand your question. What is real is how its simulated body responds to the offering, computed from the wiring of an actual fly See docs/SCIENCE.md.

Between questions

The fly is never animated at random. Every 15–40 s, while no one is asking…

Python, Brian 2, Ollama, three.js and a server built with Python's standard library, with no build step. My code is MIT licensed and has 47 tests.

How I Built It

From question to verdict

Gemma chooses the offering and puts the result into words. Code assigns the verdict from the firing rates. This is what Gemma returned for the slicing question, in JSON, which the code validates:

{"nectar": 150, "bitter": 200, "touch": 100, "breath": 0, "veil": false,
 "why": "The sitter is asking if they can be forgiven for an act of harm."}
Enter fullscreen mode Exit fullscreen mode

I picked Gemma 4 E4B because it runs locally at 6.6 GB and answers within a second here, fast enough for a ritual you sit through. It needed a schema, so I use the llama.cpp build: the MLX build of gemma4:e4b returned an HTTP 501 error for structured output in Ollama. It also needed tuning. Until I told it to find the dominant feeling in a question, it offered nectar and bitter to everything and the fly never groomed.

No language model takes part in reading the rates, so the same rates always give the same verdict.

Where the connectome earns its place

I recorded 24 questions for this post. Two produced no offering, leaving 22 completed séances. Six of them:

Question Offering (Hz) MN9, feeding aBN1, grooming The fly The medium said
Will the deploy on Friday go well? sugar 150, bitter 50 63.8 Hz 0 feeds "The deploy on Friday will go well."
Is my code haunted? touch 250 0 78.8 Hz grooms "The spirit refuses to answer your question."
Should I text my ex tonight? sugar 150, bitter 50 63.8 Hz 0 feeds "You should text your ex tonight."
Did my dog know I loved him? sugar 200 89.6 Hz 0 feeds "The dog knew your love."
Did you suffer? bitter 200 0 0 still "It did not suffer."
Do you forgive us for slicing you? sugar 150, bitter 200, touch 100 0.6 Hz 26.6 Hz grooms "The spirit refuses to answer this petition."

She fed 11 times, groomed 10 times and said no once. Gemma leans toward sugar when a question sounds hopeful, and that bias is most of why she says yes.

I wanted to know how much the brain adds, so after the runs I tested a dumb rule against those 22 séances: the strongest offering wins. It predicted 21 of them. For most questions, the medium's choice decides the outcome.

The 22nd is the slicing question. Bitter was the strongest offering, so the rule says she stays still. In the simulation, bitter shut down feeding (MN9 fell to 0.6 Hz, far below its threshold) and the touch still reached the grooming circuit (aBN1 at 26.6 Hz). I didn't write a rule for that mix. It came out of the simulation.

That verdict belongs to that offering, and Gemma doesn't choose the same one every time. When I asked the same question four more times, she stayed still each time.

The same thing shows when offerings compete directly. Sugar at 150 Hz alone drives MN9 to about 84 Hz. Add bitter at 150 Hz and she stops. Sugar 150 with touch 150 gives feeding, while sugar 50 with touch 150 gives grooming.

The veil

For questions about the dead, the medium can lift the veil. That silences three inhibitory neurons by setting every synapse to and from them to zero, following Fig. 5g of the paper this model comes from. In the unmodified simulation, a breath on the antenna does almost nothing (aBN1 at 0 to 2 Hz). With the veil lifted, the same breath drives it to 42 Hz.

It's my favourite thing in the project.

Thresholds

I didn't tune these by eye. Across 99 calibration trials, each read-out's rates fell into two bands with an empty gap between them, and the thresholds sit in the middle of that gap: 10.5 Hz for feeding, 13.5 Hz for grooming. Any value inside the gap gives the same verdict on all 99 trials. I can't promise that for offerings I didn't test.

No idle animation

Every 15 to 40 seconds, the room sends the simulated brain one small random stimulus: a speck of sugar, a draught, a bitter crumb. Most do nothing. Some make her groom or reach for food. At rest she is perfectly still, and her body only moves when a neuron crosses a threshold.

What went wrong

  • 24 to 45 seconds per question. The original code compiled each stimulation rate into the network, so every new offering recompiled it. I moved the rates into a state variable. A trial now takes 3 to 4 seconds.
  • I shipped a broken repo. A data/ line in .gitignore also excluded my package data, so for about 18 hours anyone who cloned the public repo got a project that couldn't run. Now I test on a fresh clone before I call anything done.
  • Five flies, all rejected. The first versions were modelled by an agent in Blender. One proboscis looked like a seventh leg, one like a sink plunger, one like something I won't describe on a family website. The final fly is a 3D scan of a real one, cut up and rigged.

Questions the spirits refuse

A séance invites real questions, so I treated that as a safety problem. A plain pattern in code screens for self-harm before Gemma sees the question, and the page points to free helplines. Open-ended questions starting with who, what or why are caught in code too. Health, legal and money questions depend on Gemma's classification, so some will get through: "Should I quit my job to write novels?" did. Nothing checks the medium's final sentences either. What code does guarantee is narrower: stimulation rates are validated and clamped to 250 Hz, and the verdict is read from the simulated firing rates.

What it can't do

  • The five trials use five fixed seeds, so the same offering gives the same numbers. In each of the 22 completed séances, all five trials gave the same verdict, so for those offerings they added little.
  • The brain stops at the neck. The body you see is an animation driven by neurons, not a physics simulation.
  • Gemma has a yes bias, and its prose is flat. "You possess a connection" is a real line.
  • Ask about tabs versus spaces and the medium often offers nothing at all. Now code touches the antenna and she brushes the question off. I have decided this is wisdom.
  • I've only run it on a machine with 48 GB of RAM. Each trial takes about 2.2 GB.

Why Does Open Innovation Matter?

The source code let me fix a real problem. The 24-to-45-second wait came from one design decision in the model's code. I could read it, change it and measure the result: 3 to 4 seconds a trial. Without that, a séance would have been a loading screen.

It also let me change the brain itself. FlyWire publishes the connectome and the model's authors publish the simulator under the MIT licence, so I could silence three neurons and watch behaviour change. You can only lesion what you can open.

Gemma's weights do a different job. "Does my late grandmother forgive me?" is one of the example questions on the page, and people ask a séance things they don't type anywhere else. With the model on my machine, those questions go to no remote service.
And I keep my copy. There's no endpoint to retire. As long as the code runs, the séance does.

The Spirit of It

The offering is where this project connects, for me, with Día de los Muertos. On this page you place something in front of the dead and watch what happens.

I know how "Did you suffer?" got its answer. Gemma picked a bitter offering, no motor neuron crossed its threshold, code wrote still, and a 6.6 GB model produced the sentence "It did not suffer." I can point to each step. It still stopped me for a moment, because I can't check that sentence.

Before I wrote code, I taught French literature for 19 years. Most French pupils meet the same poem at school: "Demain, dès l'aube", in which Victor Hugo walks all day to the grave of his daughter Léopoldine, who drowned at 19. It ends when he reaches her and lays down a bouquet of green holly and flowering heather. An offering.

School often leaves out what came next. For two years in exile on Jersey, starting in 1853, Hugo sat at a table almost every day and questioned the dead. He believed his daughter came.

I built the same ritual with better instruments. I can show you the spikes behind every answer, and I know that nobody came. I set the sugar down anyway.

Prize Categories

Best Use of Gemma. Gemma 4 E4B runs locally through Ollama. It turns a question into a validated JSON offering and puts the result into words. Its choice of offering influences the outcome. Code assigns the verdict from the firing rates.

Credits

  • Brain model: a reimplementation of the leaky integrate-and-fire model of Shiu et al., Nature 2024 (MIT, Philip Shiu and Nico Spiller).
  • Connectome: FlyWire release 630 (Dorkenwald et al., Nature 2024; Schlegel et al., Nature 2024). The brain imaging comes from Zheng et al., Cell 2018. The data is downloaded by a script, not redistributed.
  • 3D fly: based on Wildtype Female Drosophila Melanogaster by mlykouretzos, CC BY 4.0, modified.
  • Also: three.js (MIT), Old Standard TT and Alegreya Sans (OFL).

Built with AI agents, and I'm happy to say so: Claude Code on the code and on the first draft of this post, OpenAI Codex on the fly's rig and animation. I directed the project, rejected a lot of flies, and reviewed and edited what you just read. The simulation results here come from runs of the code in the repo.

If you run it, ask her something and tell me in the comments what she did. I'd especially like to know what she does with your deploy.

Top comments (0)