Even inside a fruit fly's head, no bigger than a speck, signals travel along set paths. The antennae and compound eyes turn the world into electrical signals, the nerves sort and carry those signals, and the brain recognizes "that's food" or "that's danger." And the rules behind those judgments weren't handed down by anyone — they were learned from experience. Follow this path, and you'll naturally see how artificial neural networks grow from an ultra-simple model into multilayer deep learning.
The human brain is too big, and computer neural networks are too abstract. The fruit fly is just the right size in between. You can take in the whole path from sense organs to behavior at a glance, and you can actually switch individual neurons along that path on and off in experiments.
In 2024, a wiring diagram (connectome) of every neuron and connection in the fruit fly brain was completed. In neural-network terms, it's like being able to see a model's entire architecture and connections.
Smelling something and approaching it, seeing a looming shadow and taking off. The path of senses → nerves → brain → behavior is short, so it's easy to follow step by step.
Genetic tools can stop specific neurons from working. It's like deleting one unit from a neural network and seeing how its performance changes.
Light is photons, smell is molecules, sound is vibrations in the air, and taste is substances dissolved in water. They're all different kinds of stimuli, yet by the time they reach the brain they all have the same form: changes in the voltage across a neuron's membrane, and electrical pulses (spikes).
Light changes the shape of a molecule, and that change opens ion channels that alter the cell's voltage.
When odor molecules bind to receptors, ions flow in and out and the voltage rises; once it crosses a threshold, the neuron fires a spike.
When the tip of the antenna vibrates, the mechanosensory neurons inside are stretched and produce electrical signals.
Fruit flies taste with their legs too. When sugar or a bitter substance touches them, taste neurons send out electrical signals.
There are exceptions. Neurons that send signals only a short distance, like the photoreceptors in the compound eye, transmit by raising and lowering their voltage continuously instead of spiking. Pick "Light" to see the difference.
Each brain region is drawn as dots, like a fluorescently stained microscope image. Pink dots are nerve tissue, red dots are sense organs, and the green glow is a signal flowing right now. This is a schematic model, not real anatomical data. The front-back and left-right relationships between regions are correct, but sizes and shapes are simplified.
The fruit fly's four stages map one-to-one onto the basic structure of a neural network. Every model in the ladder below is a story of adding layers within this framework.
Olfactory receptor neurons in the antennae respond to odor molecules, and the ommatidia of the compound eye respond to light. The strength of the response is the number.
The antennal lobe and lamina gather incoming signals, balance their strength, and convert them into handy forms such as getting brighter or darker.
The mushroom body, lateral horn and lobula extract meanings like "this smell is food" or "this shadow is an approaching predator."
Approach, avoid, or take off? The scores of several signals are compared, and one behavior wins.
There are two ways to get a computer to do a job. A person can write out the rules one by one (rule-based), or you can give it only examples and outcomes and let it find the rules on its own (learning-based). Deep learning is the second way, and the fruit fly brain contains both.
The rules are visible, so they're easy to understand. But you have to know every possible situation in advance, and when the environment changes, whoever wrote the rules has to fix them by hand. In a situation the rules don't cover, it's helpless.
In the fruit fly: the innate responses of the lateral horn. Evolution wrote these rules, and a single fly can never change them in its lifetime.
No rules are written directly. Instead, the weights are adjusted by "how wrong the prediction was." Repeat this, and the rules appear inside the weights on their own. If the environment changes, it simply learns again.
In the fruit fly: the mushroom body. When punishment or reward arrives, dopamine neurons send a signal that changes the Kenyon cell → output neuron connections. Whether this signal actually computes a prediction error like "outcome − prediction" is still being researched; here we simplify it to a prediction-error rule to make it easier to understand.
Both flies start out liking fruit scent A. But in this room, there's an electric shock on the A side and sugar on the B side. The fly on the left only follows its rules; the fly on the right learns from outcomes. Use "Change environment" to switch which side is dangerous.
The right-hand fly's "rules" aren't written down as sentences anywhere. All there is are two approach values — that is, two weights. Deep learning models are exactly the same. Millions or billions of weights are the rules, so they perform well, but it's hard to pull out "why it decided that" in human words. Rule-based systems are easy to explain; learning-based systems are easy to adapt. The fruit fly uses both: it gets by on innate rules in unfamiliar situations, and corrects them with learned rules as experience builds up.
With each rung, one more ability seen in the fruit fly is added. On each rung you'll operate the model yourself, run into a problem it can't solve, and then move up to the next rung.
Model: y = w × xFruit fly: CO₂ avoidance
The fruit fly's antennae have dedicated sensory neurons that detect only carbon dioxide. Their signals converge on a single glomerulus in the antennal lobe, and the fly avoids carbon dioxide without having to learn it. Here we boil this path down to "one sensor → one connection → behavior."
This is the smallest possible model: it outputs 1 if the input x multiplied by the weight w exceeds the threshold θ, and 0 otherwise. The weight means "how loudly should I listen to this input," and the threshold means "how easily should I react."
In this model, "learning" means setting w and θ to the right values. The fruit fly is born with these values already tuned by evolution. Make w large and it flees even faint carbon dioxide; make it small and the CO₂ has to be strong before it flees.
Its limits are clear, too. This model looks at exactly one input. It can't solve the problems a fruit fly actually faces — ones that require weighing several signals together, like "There's a fruit scent and a vinegar scent at the same time. Is this worth eating?" So we add more inputs.
Model: y = σ(w₁x₁ + w₂x₂ + b)Fruit fly: judging food odors
Ripe fruit gives off both a fruity scent (esters) and a vinegar scent (acetic acid). Suppose one neuron receives signals from two glomeruli and judges "is this the smell of food?" It gives the two signals different weights, adds them up, and then decides.
Multiply each of several inputs by its weight, add them up, add a bias b, then use the sigmoid σ to turn the result into a probability between 0 and 1. The only boundary this model can draw is a single straight line on the plane at right.
Pick the "Hard" problem and train. Real fruit flies approach faint vinegar odors but avoid ones that are too strong. That makes the food region a band between two lines, and a single line can't cut out a band. No matter how long you train, accuracy stalls at some level. That's why we need the next rung.
Model: 2 inputs → H hidden → 1 outputFruit fly: mushroom body circuit
Signals from the antennal lobe fan out to thousands of Kenyon cells in the mushroom body. Each Kenyon cell picks up input from a few glomeruli and responds to its own "odor combination." Output neurons gather those responses and decide whether to approach or avoid. Learning happens mainly at the Kenyon cell → output neuron connections.
Insert a "hidden layer" between the input and the output. Each hidden neuron draws one line on the plane, and by combining those lines the output neuron can build boundaries that bend or form bands. This is the multilayer perceptron (MLP).
A student who saw the exam questions in advance can score 100 on that exam and still prove nothing about their real ability. Models are the same. So we split the data in two. We adjust the weights using only the training data (filled dots), and grade with validation data (hollow dots) that was never used for learning. The validation score is the true measure of skill.
Common ways to prevent overfitting are adding more data, stopping training when the validation loss starts rising again (early stopping), and not making the model bigger than it needs to be. Fruit flies face a similar problem: so that they don't over-generalize from a single chance experience, long-lasting memories form only after repeated training. In real deep learning, besides validation data, people often set aside separate test data that is used only once, at the very end.
It's a calculation that takes the error at the output and divides it backward according to "who's to blame." Hidden neurons that are strongly connected to the output neuron, and that were strongly active at the time, take more of the blame. Once blame is assigned, everything — right down to the input → hidden connections — is corrected at once.
Fruit flies don't do this backward division. The connections into the Kenyon cells are set almost at random and don't change; dopamine adjusts only the last connections (Kenyon cell → output neuron). Choose "Fly-style model" and you'll see it struggles with few hidden neurons, but once you raise the count to 30–60, random lines alone are enough to cut out the band. It hints at why the fruit fly keeps as many as ~2,000 Kenyon cells.
Model: layer upon layer, like a CNNFruit fly: compound eye → lamina → medulla → lobula → giant fiber
When a fly swatter approaches, a fruit fly takes off in an instant. The ommatidia of the compound eye measure brightness, the lamina splits signals into brightening and darkening, T4 and T5 neurons in the medulla and lobula plate compute the direction of motion, and LPLC2 neurons in the lobula detect "motion spreading outward in all directions" — that is, an approaching object. This signal passes through the giant fiber neuron and becomes a jump.
It's built just like a convolutional neural network (CNN). Each layer repeats the same calculation over a small area at every position (weight sharing), and as you go up the layers the field of view widens and the features become more complex: brightness → change in brightness → direction of motion → looming. Each layer on its own is simple, but stacked together they make a hard judgment.
This is a computational model simplified for explanation. The ommatidia are reduced from about 800 to 169, and the direction of motion is computed directly from the speed of the object's edges. Real T4 and T5 neurons work out direction by comparing signals from neighboring ommatidia with a time delay.
It's hard to write a rule that detects an "approaching object" straight from the brightness values of the ommatidia in one step. The object might be dark or bright, on the right or on the left. Instead, we break the problem into easy pieces and give one to each layer.
With an "object passing by," one edge moves outward while the opposite edge moves inward, so it doesn't satisfy all four directions. That's why the fly doesn't jump even if the object is large and fast. A CNN that recognizes a cat in a photo stacks its layers the same way: lines → edges → parts → whole shape.
Press the buttons to switch between diagrams of six architectures. Green lines are learned connections, dashed lines are fixed connections, and orange arrows are memory carried across time. All diagrams are schematics showing the principle.
Gray bar = all connections, colored bar = learned connections. Deep learning models learn everything, while most connections in the fruit fly model are fixed. The Trainer below and Code 2 in Common section A count the same numbers.
Level of evidence in the last row: Real circuit · measured the model transcribes a real circuit · Similar structure the wiring looks alike, but this is not evidence they compute the same thing · Loose analogy · Pure analogy just a figure of speech to aid explanation, no biological basis.
The ladder on page ① (ultra-simple → multilayer) was the MLP and CNN side of the story. Alongside it, the fly-style model offers a different answer: "even without training the hidden layer, making it wide and sparse works quite well." In machine learning, random features, extreme learning machines (ELM) and reservoir computing share the same idea. The fruit fly brain also has circuits that handle time, like RNNs and LSTMs (the central complex), but the models on this page make one-shot judgments.
Like Teachable Machine, we walk through an example of ① collecting example drawings for each class, ② training, and ③ checking with drawings the model has never seen. On the same drawing data, we trained the fly-style model (only the output layer learns) and a deep learning MLP (all layers learn) side by side. The drawings are 16×16 images jittered to look hand-drawn.
We made 30 drawings per class: 24 for training and 6 (18 in total) for validation. The validation drawings are never shown during training.
Green = fly-style model · Blue = MLP · dashed = training accuracy, solid = validation accuracy
| Circle | X | Line | |
|---|---|---|---|
| Circle | 4 | 2 | 0 |
| X | 0 | 6 | 0 |
| Line | 0 | 1 | 5 |
| Circle | X | Line | |
|---|---|---|---|
| Circle | 4 | 2 | 0 |
| X | 0 | 6 | 0 |
| Line | 0 | 0 | 6 |
Both models got 100% of the training drawings right, but on the validation drawings the fly-style model scored 83% and the MLP 89%. This difference (the gap between training and validation) is the degree of overfitting. Even though the fly-style model has only about 36% as many learned connections as the MLP, its validation accuracy doesn't lag far behind. Both models mistook 2 of the 6 validation circles for X's (see the confusion matrix below). With only 24 training drawings per class, mistakes like this happen. To try it with your own drawings, run Code 2 in Common section A in Colab.
The flow is the same: make classes → collect examples → train → judge new inputs.
Teachable Machine trains only a small classifier on top of features already learned by a large image model (MobileNet) — this is transfer learning. In this example, two models learn 16×16 drawings from scratch. That makes it well suited to simple shapes, but not to complex inputs like photos.
The higher the rung, the more connections the model has, the more complex the boundaries it can draw, and the deeper the meaning it can extract. The fruit fly's senses → nerves → brain → behavior hold all of these stages in a single body.
| Rung | Model structure | Fruit fly example | New ability | Remaining limit |
|---|---|---|---|---|
| ① Ultra-simple | 1 input → 1 output y = threshold(w·x) | Carbon dioxide → avoid | Reacts when the signal is strong | Sees only one input |
| ② Simple | Several inputs → 1 neuron Perceptron | Fruit scent + vinegar scent → is it food? | Weighs several signals, learns from errors | Only one straight boundary line |
| ③ Standard | Input → hidden layer → output Multilayer perceptron | Antennal lobe → mushroom body → output neuron | Curved and band-shaped boundaries, recognizing combinations | Large, complex inputs need a huge number of hidden neurons |
| ④ Many layers | Stacks many layers like a convolutional neural network | Compound eye → lamina → medulla → lobula → giant fiber | Builds up simple features to recognize meanings like "approaching" | The deeper the network, the more data and computation training takes |
A value changed by learning. Inhibitory synapses are negative weights.
A signal is sent only when the threshold is crossed. This bend is what makes stacking layers meaningful.
Tells what went wrong. The fruit fly doesn't pass it back through the layers; it delivers it directly to specific connections.
The wiring diagram of the entire brain. Who connects to whom, and how strongly, is the model's structure.
Next page: a paper revealing where signals from the mushroom body (learning) and the lateral horn (instinct) actually meet — an illustrated guide to Dolan et al. (2018), Neuron.
Third page: a project that runs an entire real fruit fly wiring diagram to move a Minecraft mob, compared with the previous two pages. A Fruit Fly Brain in Minecraft — a nervous system driven by its wiring diagram alone.
Both programs use only libraries preinstalled in Colab. Click "Download notebook (.ipynb)" and open it in Colab with File → Upload notebook, or copy the code and paste it into a new notebook cell.
Builds fixed connections for 1,000 Kenyon cells and, on top of a sparse code where only the top 8% are switched on, trains just one output layer with the delta rule. To use your own data, replace X (samples × 256) and Y (label indices).
Trains MLP, CNN, RNN, GRU, LSTM and three fruit fly models on the same drawing data with the same split, then compares connection counts and accuracy. It runs the "Trainer example" calculation yourself on a larger dataset (4 classes, 160 images).
| Item | Code 1 (fly-style) | Standard deep-learning code |
|---|---|---|
| What gets trained | Just the output layer (3,000) | All layers (16,643) |
| Gradient computation | Not needed: error × input | loss.backward() computes it layer by layer via the chain rule |
| Hidden representation | Randomly fixed at birth | Learned to fit the data |
| Hidden layer shape | Wide and sparse (only 8% of 1,000 active) | Narrow and dense (all 64 have values) |
| Key line | W_out += lr * np.outer(y − p, k) | opt.step() |
| Tools needed | NumPy only | PyTorch (autograd) |
| Name in machine learning | Random features, extreme learning machine, reservoir computing | Multilayer perceptron (MLP) |
Prompts to paste into an AI assistant such as ChatGPT, Qwen or Claude. Clicking "Copy" appends the code you choose after the prompt. Replace the parts in 〔 〕 with your own situation.
An AI's answer is only a starting point. Always check any suggested papers, numbers and library functions against the original sources and official documentation. If you used AI help for a competition entry or paper, disclose that you did and to what extent, following the rules of the organizers and the journal.
This is the same dictionary as the yellow dotted underlines in the text. Hover over or tap an underline to see the same explanation.
Analogies are a first step toward understanding, but they can also plant misconceptions. Fruit fly/brain analogies are marked by strength: Direct evidence that it really does the same thing · Partial only some properties are similar · None no known counterpart
| Concept | Everyday analogy | Fruit fly/brain analogy | Where the analogy breaks down |
|---|---|---|---|
| Perceptron | Scoring several people's opinions, adding them up, and deciding once the total passes a bar | Partial A neuron gathers inputs and fires when they cross a threshold | In a real neuron, inputs build up and leak away over time. A perceptron has no time (see leaky integrate-and-fire in Special 3) |
| Hidden layer | A company's middle managers: they gather reports from the floor and pass a summary up to the CEO | Partial Kenyon cells in the mushroom body re-represent odor signals broadly | Kenyon cells' input connections are set randomly and are not learned. Hidden layers in deep learning are learned |
| Weight learning | Writing missed problems in a mistake notebook and fixing them next time | Direct Dopamine changes the strength of mushroom body output connections, pairing odors with outcomes | Whether the fruit fly's dopamine signal computes a "prediction error" is still being studied. The learning rule in this special is simplified for explanation |
| Backpropagation | When the result is bad, assigning blame backward from the end of the production line | None | There is no known evidence that the brain passes exact gradients backward layer by layer |
| Multilayer visual pathway | A factory assembly line: each stage builds slightly more complex parts | Partial Going from compound eye → lamina → medulla → lobula, increasingly complex motion is detected | The filters in ④ were set by hand for explanation. A CNN learns its filters |
| Turning input into numbers | Exchanging every country's money into a single currency | Direct Sensory neurons turn light, smell and taste into electrical signals | Real signals are the rate and timing of spikes. The firing-rate numbers in this special are example values |
E-1 About the author · E-2 Academic references · E-3 Figure sources
| No. | Content | Value | Source |
|---|---|---|---|
| [1] | Total neurons and synapses in the fruit fly brain | About 140,000; about 50 million | FlyWire Consortium (2024) Nature — whole-brain connectome of the adult fly |
| [2] | Ommatidia per compound eye | About 750–800 | Textbook value for the fruit fly visual system (varies by individual and strain) |
| [3] | Types of olfactory receptor neurons / glomeruli in the antennal lobe | About 50 types / about 50 | Typical values from fruit fly olfaction research (e.g., Couto et al. 2005, Curr Biol) |
| [4] | Kenyon cells per mushroom body; types of output neurons | About 2,000 / 21 types | Aso et al. (2014) eLife — anatomy of the mushroom body circuit |
| [5] | Neurons in the human brain | About 86 billion | Azevedo et al. (2009) J Comp Neurol |
| [6] | Carbon dioxide avoidance; attraction/avoidance depending on vinegar concentration | — | Suh et al. (2004) Nature · Semmelhack & Wang (2009) Nature |
| [7] | T4·T5 motion-direction detection; LPLC2 looming detection | — | Maisak et al. (2013) Nature · Klapoetke et al. (2017) Nature |
A guide for instructors, on-the-job training (OJT) leads and tutors. Times are estimates; adjust them to your actual class.
| Audience | College students and working adults new to deep learning. No biology background needed |
|---|---|
| Prerequisites | Addition, multiplication and reading graphs. Python is needed only for the Colab exercises |
| Learning goals | ① Map senses → nerves → brain → behavior onto input → hidden layer → output ② Explain why a perceptron can't solve the band-shaped problem and why a hidden layer can ③ Spot overfitting by comparing training and validation scores |
| Estimated time | Reading 50–60 min · animation demos 25 min · Colab exercises 30 min (Code 1: 10 min; Code 2: 2 min to run + 15 min to interpret) |
Intro 5 min (why fruit flies) → senses→nerves→brain mapping table 10 min → rules vs. learning 10 min → ①②③ ladder 20 min → check questions 5 min.
Rules vs. learning playground 20 min (compare with rule-based systems at work) → ②③ overfitting 20 min → reading the confusion matrix with the Trainer example 20 min → running and interpreting Code 2 30 min.
Beginners: only "Rules vs. learning" and ①②. Intermediate learners change the number of hidden neurons in ③ to create overfitting themselves, and compare the number of trained connections (3,003) in Code 1 and the Trainer example.
| Section | Question to pause and ask | Hands-on tip |
|---|---|---|
| Why fruit flies | "Is 140,000 neurons a lot or a little?" | Compare with the human brain's 86 billion |
| Electrical signals | "Why do smell and light have to be converted into the same unit?" | Change the stimulus strength and see whether the firing rate follows |
| Rules vs. learning | "When the environment changes, who adapts first?" | Click "Change environment" and compare the two flies' success rates |
| ② Perceptron | "Can a single straight line separate a band shape?" | Run training on the band problem and see where the accuracy stalls |
| ③ Hidden layer | "Is adding more hidden neurons always better?" | With little data + 40 hidden neurons, look at the gap between training and validation scores |
| ④ Many layers | "Why doesn't the fly jump at objects passing by?" | Click approaching, passing and receding in turn |
| Hands-on: Trainer example | "Why were both models confused by the same drawings?" | Click the test drawing buttons in turn and compare with the confusion matrix |
| Misconception | Correct explanation | Scene to show |
|---|---|---|
| The fruit fly brain works exactly like deep learning | Only the layered structure and learning of connection strengths are similar; backpropagation and timeless computation differ from the brain | The "Backpropagation" row in Analogies D |
| More hidden neurons are always better | With little data, the model memorizes the training data and the validation score drops (overfitting) | The low-data setting in ③ |
| With well-written rules, you don't need learning | When the environment changes, rules keep getting it wrong. Learning adjusts again | "Change environment" in "Rules vs. learning" |
| High accuracy means a good model | Accuracy measured on the training data is hard to trust. Measure it on validation data set aside separately | Training/validation curves in the Trainer example (training 100%, validation 83–89%) |
| The fly-style model is worse than deep learning | With only a quarter as many trained connections, it reached similar accuracy on the same drawing task (Code 2) | Results table of Code 2 |
Sum = 1×0.8 + 0×(−0.5) = 0.8. Since 0.8 ≥ 0.5, the output is 1.
A perceptron divides with only a single straight line (plane). A band needs two boundaries, one on each side, so one straight line can't separate it. A hidden layer creates several boundaries and combines them.
Overfitting. The model memorized the training data. Remedies: any two of collecting more data, using fewer hidden neurons, and stopping training early.
Fixed: projection neurons → Kenyon cells (random sparse connections). Learned: Kenyon cells → output neurons (changed by dopamine).
Even with just a wide, sparse, fixed representation, simple drawing problems can be solved well enough by training the output layer alone. However, since the representation itself can't improve, it has limits on harder problems.
In Code 1, change TOP (the fraction switched on) from 0.08 to 0.5, report how the training accuracy and the number of active Kenyon cells change, and explain in two sentences why sparsity is useful.
Change the MLP hidden size in Code 2 to 8, 64 and 512 and compare validation accuracy across two seeds. Interpret whether overfitting appears, together with the learning curves (cell 7).
| Beginners | Section ④ and the GRU/LSTM parts of "Comparing structures" can be skipped without breaking the flow. Make sure "Rules vs. learning" and ②③ are solid |
|---|---|
| Advanced | Have learners present a comparison of the fly-style model with random features and extreme learning machines (ELM) in machine learning. Check any papers they find against the originals |
| Learn more | Sangsun Ahn, "Data Science for Business" lecture notes (data science overview, in Korean) · STEP [K-Digital] Artificial Intelligence: Natural Language Processing · STEP [K-Digital] Fundamentals of Fintech Data Analysis |
| Instructor materials | Grading criteria for the check questions and sample answers for the assignments are on the Answer Key for Educators page (Special 1) |
You've read all of "Special 1: Exploring the Fruit Fly Brain." The lab crew will each sum it up for you.