Brains and AIMiddleLesson 2995 min read

Spiking neurons vs artificial neurons

Real neurons talk in brief electrical spikes over time. Neurons in most AI models pass smooth numbers. Build a simple spiking neuron and see the difference.

Lesson in motion

In 60 seconds

Spiking neurons vs artificial neurons

Real neurons talk in brief electrical spikes over time. Neurons in most AI models pass smooth numbers. Build a simple spiking neuron and see the difference.

1/3
In simple words
Imagine a bucket with a small hole at the bottom. People pour water in. The water slowly leaks out. If they pour fast enough, the bucket fills to the top and tips over with a splash, then it is empty again. A real neuron works a bit like that bucket: it collects input, leaks some away, and "splashes" a spike when it gets full. An AI neuron is more like a calculator: numbers in, one number out, every time.

The artificial neuron

An artificial neuron in most AI models takes some input numbers, multiplies each by a weight, adds them up, and passes the total through a simple function, such as "keep it if positive, else zero". The output is a number. The whole network does this for every neuron, for every input, all at once.
Python: one artificial neuronpython
import numpy as np

x = np.array([0.5, 0.2, 0.9])      # inputs
w = np.array([0.8, -0.4, 0.3])     # weights (learned in training)
b = 0.1                            # bias
total = x @ w + b
output = max(0.0, total)           # "ReLU": keep positive values
print("total =", round(total, 3), "-> output =", round(output, 3))

The spiking neuron

A real neuron has a voltage across its skin, the cell membrane. Inputs push the voltage up or down. Without input it drifts back to a resting level. When it crosses a threshold, the neuron fires a short electrical pulse called a spike, and the voltage resets. Information is carried by when spikes happen and how often.
A popular simple model is the leaky integrate-and-fire (LIF) neuron:
  • Integrate: add up input over time, like water filling the bucket.
  • Leaky: the voltage slowly drifts back to rest, like the hole in the bucket.
  • Fire: when the voltage reaches the threshold, record a spike and reset.
Note
The LIF neuron is a big simplification of a real neuron, but it captures the key idea of spikes over time. The whole-fly-brain model in lesson 3 used simple spiking neurons of this general kind.

Side by side

Artificial neuron (most AI)Spiking neuron (brains, LIF model)
OutputA number, every timeSpikes at certain moments, often none
TimeUsually no built-in sense of timeVoltage changes over time; timing matters
ActivityEvery neuron computes for every inputMost neurons are quiet most of the time
LearningWeights trained with backpropagationBrains change synapses in many ways, still being studied
HardwareRuns very well on GPUsSuits event-driven neuromorphic chips (lesson 7)

A key behaviour: the firing threshold

Give an LIF neuron a small steady input and its voltage rises, then levels off below the threshold. It never fires. Give it a bigger input and it fires again and again. The bigger the input, the faster it fires. So a steady input strength becomes a firing rate. You will see this yourself in the lab.
Real example
Think of a pressure cooker. Heat builds up pressure; some steam leaks out. On a low flame, the whistle never blows. On a higher flame, it whistles, pressure drops, builds again, and whistles again. Turn the flame higher and the whistles come faster. That is a leaky integrate-and-fire neuron in your kitchen.
Think about it. An artificial neuron gives an output for every input. A spiking neuron often gives nothing. Why might "nothing, most of the time" be a big advantage for saving energy? Lesson 6 answers this.

Watch and read more

Lab

A working leaky integrate-and-fire neuron in numpy, its firing threshold behaviour, and the smallest steady input that makes it spike.

~25 min

The problem

This runs in your browser.

  1. Run the starter. It simulates the voltage of a neuron with a steady input I (in millivolts), but the "fire" part is missing, so it never spikes.
  2. In simulate_lif, add the fire rule: when V >= V_TH, record the time in spikes and reset V to V_RESET.
  3. Run it for inputs 10, 20 and 40. Note how many spikes each gives in 200 ms.
  4. Find the smallest steady input (to about 0.5) that gives at least one spike, and store it in rheobase. You can search with a loop.
  5. Write one sentence explaining why input 10 gives no spikes.

Practice lab

Edit the code and run it. Python runs in your browser — nothing is sent to our server.

Output

No output. Add print(...) to see values.

You are done when

Hard questions

Try to answer before you reveal. If you can answer these, you understood the lesson.

Q1Why is the smallest input that spikes close to 15 in this model? Use the numbers.Reveal

With a steady input I, the voltage settles where the leak cancels the input: at V_REST + I. The neuron can only fire if that level reaches the threshold, so -70 + I >= -55, which gives I >= 15. Just above 15 it takes a long time to get there, so in a 200 ms run the smallest input that spikes is a tiny bit above 15.

Q2Real neurons cannot fire again immediately after a spike. How would you add this "refractory period" to the model, and what would it change?Reveal

Keep a counter: after each spike, hold V at V_RESET and ignore input for a few milliseconds before integrating again. This puts a ceiling on the firing rate: even a huge input cannot make the neuron fire faster than once per refractory period plus the time to climb to threshold. Without it, the LIF model can fire unrealistically fast for very large inputs.

Please sign in to continue.

Questions people ask

Were artificial neurons copied from real ones?

They were inspired by real neurons many decades ago, but they are far simpler. Modern AI models are shaped much more by maths and computer hardware than by biology.

Can spiking networks learn like normal AI networks?

Researchers train spiking networks with several methods, including adapted versions of the methods used for normal networks. It is an active research area, and spiking networks are generally harder to train today.

Is the LIF model how real neurons really work?

It captures the main idea, but real neurons are much richer. They have branches that process input, many kinds of ion channels, and many types of synapses. Scientists choose simple or detailed models depending on the question.

What units are the numbers in the lab?

Voltages in millivolts and time in milliseconds, with values in a typical textbook range. The input is written directly in millivolts to keep the maths simple. It is a teaching model, not a measurement of a real neuron.

Lesson test

5 questions. Get 3 right (60%) to pass and complete this lesson.

Sign in to take the test and save your progress