Paper · 2021-09-27 · cs.NE, cs.ET, cs.LG
Training Spiking Neural Networks Using Lessons From Deep Learning
Tutorial and perspective on training spiking neural networks with deep-learning tools. Derives the discrete leaky integrate-and-fire neuron, compares input and output spike codes, loss functions and credit-assignment rules, and explains surrogate-gradient backpropagation through time and its link to STDP. Presents no new method and no experiments of its own.
Spiking neural networksSurrogate gradientBackpropagation through timeQuantization-aware trainingspiking-neural-networksneuromorphicsurrogate-gradientsbackpropagation-through-timeonline-learningquantizationtutorial
arXivPDFCodeMarkdown14 min read
AI-compiled by claude-haiku-5-5 on 2026-10-18, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Biological neurons talk to each other with short electrical pulses called spikes. A neuron keeps a running charge, leaks a little of it every moment, and fires only when the charge crosses a threshold. Spiking neural networks copy this behaviour. Their signals are simply on or off, and they are sparse, so most of the network is silent at any moment. That makes them attractive for low-power chips and for sensors that only report changes, such as event cameras.
The difficulty is training. Learning in ordinary networks relies on smooth changes in the output, but a spike is a sudden jump, so tiny weight changes often do nothing at all. The paper explains this problem and the common fixes. The most widely used fix is to pretend, only during the backward pass, that the spike function is smooth, and then to train through time as one would train a recurrent network. The authors also show that this procedure behaves like a known biological learning rule, spike-timing dependent plasticity, when the timing of spikes is taken into account.
The paper is written as a tutorial and a perspective, not as a new method. It walks through how to turn data into spikes and back, which output losses to use, which learning rules exist (including forward-in-time ones that avoid storing history), and what remains open.
TL;DR
A tutorial and perspective, not a method paper. It derives the discrete leaky integrate-and-fire (LIF) neuron §2.1 eq. 4 eq. 5, and it describes rate and latency codes for inputs and outputs §3.1 §3.2. For training, the central recipe is backpropagation through time with a surrogate gradient that replaces the zero or infinite derivative of the threshold §4.3 eq. 6 eq. 8. Online alternatives derived from real-time recurrent learning are surveyed in §5. The paper reports no benchmark numbers of its own. Its code is the snnTorch library, MIT-licensed and owned by the first author.
Problem
Deep learning models consume a great deal of energy, while the brain runs within roughly 12 to 20 W §1. Spiking neural networks (SNNs) are proposed as a more efficient alternative, because a spike is a single bit, activity is sparse, and event-driven sensors need little power §1 §2. Training them with gradients is hard because the spike is a step function. Its derivative is zero away from the threshold and unbounded at it, so standard backpropagation gives no useful learning signal to neurons that have not fired §4.3 fig. 9. Biologically plausible learning adds the further constraint that updates should depend only on local information in space and time §5.1 §5.3.
Method
The paper contains no single algorithm to reproduce. The parts an implementer needs are the neuron update, the encoding and decoding choices, the loss, and the surrogate-gradient backward pass.
Neuron model §2.1. The membrane behaves like an RC circuit with time constant τ = RC eq. 1. Discretising it with the forward Euler method gives a decay factor β and an input term eq. 3. The paper then decouples the input scale into a learnable weight W, adds a reset term that subtracts the threshold after each spike, and applies a threshold on the membrane to produce the output spike eq. 4 eq. 5. The reset term uses the spike from the previous step, which is the delayed-reset form used by the library.
# Discrete leaky integrate-and-fire step [§2.1] [eq. 4] [eq. 5]
# Shapes: input_current (B, N); membrane, spikes (B, N)
def lif_step(input_current, membrane, spikes_prev, beta, theta):
# Decay the membrane, add the input, subtract last step's reset [eq. 4]
membrane = beta * membrane + input_current - spikes_prev * theta
# Emit a spike where the membrane is strictly above threshold [eq. 5]
spikes = (membrane > theta).float()
return spikes, membraneVariants §2.2. The paper lists integrate-and-fire (β = 1, no leak), current-based neurons (second-order synaptic filter, finite rise time), recurrent neurons (explicit feedback of spikes, either one-to-one or all-to-all), kernel-based spike-response models, deep-learning-inspired neurons such as spiking LSTMs, and detailed biophysical models §2.2. For gradient-based training it recommends LIF as the default, with recurrent or deep-learning-derived neurons when more capacity is needed §2.2 [box in §2.2]. Reset-by-subtraction is the soft reset; a reset-to-zero (hard reset) variant also exists app. A.
Input encoding §3.1 app. B. Three schemes are described. Rate coding turns an intensity into a spike probability per step, so a pixel value p gives a Bernoulli spike with probability p at each step app. B. Latency coding turns intensity into the time of a single spike, with a logarithmic dependence derived from the RC model app. B. Delta modulation emits a spike only when the input changes by more than a threshold, as an event camera does §3.1 fig. 4. Pre-encoded event datasets are listed in tab. 1. The paper's practical note says that encoding a non-spiking dataset almost always loses information, and that rate codes hurt accuracy less than latency codes §3.1 box.
Output decoding §3.2. Rate decoding picks the output neuron with the largest spike count app. B. Latency decoding picks the neuron that fires first §3.2. Population coding assigns several neurons per class §3.2.
Objective functions §3.3 tab. 2 tab. 3. For rate codes the paper tabulates four losses: cross-entropy on spike counts, mean-squared error on spike counts, cross-entropy on the maximum membrane potential, and mean-squared error on the membrane potential over time tab. 2 app. B. For spike-time codes it tabulates cross-entropy on negated or inverted first-spike times, mean-squared error on spike times, a relative spike-time loss with a margin γ, and mean-squared error on latency-coded membrane targets tab. 3 app. B. The authors state that the best choice is unsettled and depends on the network and the task §3.3.
Learning rules §3.4 fig. 8. Backpropagation solves spatial credit assignment with a backward pass, which biology is unlikely to implement exactly. The paper surveys alternatives: perturbation learning (random weight changes accepted when the error falls), random feedback (replacing backward weights with random matrices), local losses per layer, and forward-forward style learning. It notes that these methods are effective on simple tasks but struggle to scale to harder ones, and that gradient backpropagation remains the most accurate §3.4 fig. 8.
Activity regularisation §3.5 app. B. A population penalty can limit the total spike count of a layer, either as an L1 penalty on output spikes or as a penalty above an upper limit. A neuron-level penalty can push each neuron above a lower firing limit, to avoid dead neurons app. B. The paper's practical note recommends lowering the threshold of a layer where activity dies out §3.5 box.
Shadow training §4.1. Train a non-spiking network and convert its activations to rates or latencies. This sidesteps the zero derivative, but the conversion is an approximation and usually needs many time steps. The paper says it currently leads on static-image tasks such as CIFAR-10 and ImageNet, and notes that the benchmarks it is usually tested on rarely use temporal dynamics §4.1.
Spike-time backpropagation §4.2 app. C. SpikeProp, from 2002, differentiates the spike time instead of the spike. This yields an unbiased gradient in multi-layer networks, but a neuron must fire for the gradient to exist, and inactive neurons freeze §4.2.
Backpropagation through time with surrogate gradients §4.3 fig. 10. The network is unrolled over time steps, and the total loss is the sum over time of instantaneous losses eq. 6 eq. 7. The weight is shared across steps, so its gradient is the sum over all immediate and prior influences eq. 7. On the forward pass the spike is the Heaviside step of the membrane minus threshold. On the backward pass the step is replaced by a smooth function σ̃ with derivative σ̃′ eq. 8 eq. 9. The paper describes a sigmoid form and an arctan form, and identifies the arctan derivative as the default choice §4.3.1 box. Because the reset term is not differentiated through, it is detached §4.3.3.
# Surrogate derivative used only on the backward pass [§4.3.1] [code]
# Form matches snnTorch's arctan surrogate with alpha = 2 [code]
def surrogate_derivative(membrane, theta, alpha=2.0):
# Position relative to the threshold, as in the forward Heaviside
shifted = membrane - theta
# Derivative of an arctan curve; peaks at 1 when shifted = 0
return (alpha / 2) / (1 + (pi / 2 * alpha * shifted) ** 2)# Surrogate-gradient BPTT for one mini-batch [§4.3] [eq. 6] [eq. 8]
# inputs: (T, B, N_in); targets: whatever the chosen loss expects
def bptt_step(inputs, targets, weights, T, beta, theta):
# Start every neuron at rest with no spikes [§2.1]
membrane = zeros(B, N)
spikes = zeros(B, N)
# Keep each step's spikes and membrane for the backward pass [§4.3]
spike_record = []
membrane_record = []
for t in range(T):
# Forward pass uses the hard threshold [eq. 5]
spikes, membrane = lif_step(
inputs[t] @ weights, membrane, spikes, beta, theta
)
spike_record.append(spikes)
membrane_record.append(membrane)
# Output loss over the whole sequence [§3.3]
loss = output_loss(spike_record, membrane_record, targets)
# Backward through time; the Heaviside derivative is replaced by the
# surrogate above, and the reset term is not differentiated [§4.3.1]
return backprop_through_time(loss, surrogate_derivative)The output_loss and backprop_through_time calls stand for the choices in §3.3 and any autodiff engine. A weight update still needs a spike: the surrogate lets error reach earlier layers, but if a neuron never fires, the weights attached to its output receive no update §4.3.1.
Quantisation §4.3.2. The paper relates surrogate gradients to the straight-through estimator used for binary and quantised networks. It reports that SNNs are robust to quantisation-aware training, and gives code examples for quantising weights and membrane states to 8 and 4 bits respectively §4.3.2.
Bag of tricks §4.3.3. Residual connections, learnable decay, graded spikes, pooling choices and optimiser choice are discussed as ported or SNN-specific tricks. Learnable thresholds are reported as not helping, while normalising inputs to the threshold does help §4.3.3.
Long-term dependencies §4.4. Adaptive thresholds, axonal delays, and other slow dynamics are proposed to extend the memory of SNNs beyond the membrane time constant §4.4.
Online learning §5. BPTT needs stored history, so the paper turns to real-time recurrent learning (RTRL). It tracks the influence of a weight on the membrane forward in time: the influence is decayed by β and the immediate input is added eq. 10 eq. 11 eq. 12. The gradient of the instantaneous loss is then the credit at time t times that influence §5.2. For one neuron and one weight, the update is a one-line recurrence.
# Online influence of one weight on one membrane potential [§5.2] [eq. 12]
# Scalar case: one neuron, one weight
def influence_step(influence, input_t, beta):
# Decay the past influence and add the immediate influence [eq. 12]
return beta * influence + input_tWith the credit c[t] = dL[t]/dU[t], the gradient increment is c[t] times the influence §5.2. The paper assumes this credit comes from a surrogate gradient. The paper lists RTRL variants for SNNs: e-prop, decolle, OSTL, ETLP, OSTTP and FPTT §5.2.1. Spatial locality is addressed by local losses, random feedback and STDP-like rules §5.3.
STDP link §5.3 fig. 10 §4.3. The paper argues that the BPTT update for a pair of spikes decays exponentially with their time difference, so its shape resembles STDP learning curves. It concludes that STDP-like timing effects arise from BPTT without modification §4.3 §5.3.
Outlook §6. The authors list possible reasons to prefer spikes: hybrid dynamics, precise discrete functions, multiplexing, message packets, coincidence detection and noise robustness. They reiterate the energy case as reported by others §6.
Hyperparameters
Most training hyperparameters are not stated, because the paper is a tutorial. The values below are the ones the text, the figures or the code snippets state.
| Name | Value | Where | Notes |
|---|---|---|---|
| time constant τ | 1 to 100 ms, typical | §2.1 | physical range; the discrete model uses steps |
| time step Δt | 1 | app. A | normalised, so τ is in steps |
| resistance R | 1 | app. A | set to 1 to reduce hyperparameters |
| decay β | e^(−Δt/τ) | app. A eq. 3 | appendix prefers this over 1 − Δt/τ |
| decay β in listings | 0.9 | §2.1 listings | example value only |
| threshold θ | 1 | §2.1 listings; leaky.py | default in the library |
| threshold in figure | 0.5 V | fig. 5 | illustration, not a training value |
| input weight W | 0.5 | §2.1 listing | example value only |
| reset | subtract θ times previous spike | eq. 4 | soft reset; reset-to-zero also available app. A |
| β-scaled reset | not stated as default | §2.1 practical note | paper recommends it; see Paper vs code |
| surrogate α | 2 | surrogate.py | arctan slope default |
| surrogate peak | 1 in code; 1/π in printed formula | §4.3.1 surrogate.py | see Paper vs code |
| time steps T | 100 | §3.1 listings | example in spike-generation code |
| input video batch | 128 samples, 100 frames | §3.1 listing | example shape only |
| quantised weight bits | 8 | §4.3.2 listing | example |
| quantised state bits | 4 | §4.3.2 listing | example |
| output targets | correct class 80%, incorrect 20% of steps | §3.3 text | given as an example, not a default |
| library target defaults | correct 1, incorrect 0 | loss.py | differs from the text example |
| latency margin γ | not stated | app. B | treated as a hyperparameter |
| regularisation λ_1, λ_U, λ_L, θ_U, θ_L | not stated | app. B | no numbers given |
| regularisation exponent L | 1 or 2 | app. B | typical choice |
| learning rate, batch size, epochs | not stated | — | no training recipe in the paper |
| optimiser | Adam common; SGD with momentum for deeper SNNs | §4.3.3 | author's observation |
Results
Author-reported. The paper has no experiments of its own, so there is no benchmark result to reproduce. The numbers it does give are cited from other work or appear as illustrations.
| Setting | Metric | Baseline | This paper | Source |
|---|---|---|---|---|
| Neuromorphic hardware on embedded tasks | energy reduction | conventional ANN accelerators | up to 2 to 3 orders of magnitude, as reported by cited works | §6 |
| Static image classification (CIFAR-10, ImageNet) | which approach leads | native SNN training | ANN-to-SNN conversion, stated without a number | §4.1 |
| Brain power budget | power | — | roughly 12 to 20 W | §1 |
| Training energy of a large language model | energy estimate | — | cited estimate of about 190,000 kWh, not checked here | §1 |
Paper vs code
The official code is the snnTorch library at code_commit, MIT-licensed, owned by the first author (Jason K. Eshraghian). The paper links only its tutorial documentation, not the repository, so the repository was taken as official on that basis. Code paths are relative to the snnTorch repository root. Checked: the LIF update and reset, the surrogate, and the loss functions.
- Surrogate scale. The paper's practical note gives the arctan derivative as (1/π)·1/(1+(πU)²) §4.3.1. Its own integral (1/π)·arctan(πU) has derivative 1/(1+(πU)²), without the 1/π. The library's backward pass computes (α/2)/(1+(π/2·α·x)²), which at α = 2 equals 1/(1+(πx)²) surrogate.py. The library therefore matches the paper's integral and not its printed derivative, and its peak is 1 rather than 1/π. If you port the printed formula, expect surrogate gradients about π times smaller than the library's.
- Cross-entropy on spike rates. The paper's table and its code snippet call
ce_rate_lossthe cross-entropy on spike counts, with counts used as logits §3.3 tab. 2 §3.3 listing. The library'sce_rate_lossinstead applies a log-softmax at each time step, sums the negative log-likelihood over steps and divides by the number of steps loss.py. The count-based version isce_count_loss, which matches the paper's text loss.py. - Target defaults. The paper's rate-target example uses 80% and 20%. The library's
mse_count_lossdefaults to 1 and 0 loss.py. Pass the targets explicitly. - Soft reset. The paper's practical note recommends a reset scaled by β §2.1 box. The library's subtraction reset uses the unscaled threshold leaky.py, and no β-scaled option was found in the
Leakyclass. - Delayed reset. The library applies last step's spike as the reset by default, matching Eq. 4 leaky.py leaky.py. The paper's own listing does not match this (see Pitfalls).
- Decay range. The library clamps β to [0, 1] in the forward pass leaky.py. The paper does not mention clamping, and it allows learnable decay §4.3.3.
- Reset is detached. The reset term is computed with a clone and detach, which agrees with the paper's statement that the reset is excluded from the backward pass neurons.py §4.3.3.
- Default surrogate. The paper says arctan is the snnTorch default §4.3.1 box. The library uses it when no surrogate is given neurons.py.
Pitfalls
- The printed reset listing does not reset. The Python listing in §2.1 sets
S = 0inside the function on every call, so the reset termS*thetais always zero. Carry the previous step's spikes into the next call, as the library does by keeping its reset as neuron state. - Two forms of β. The main text gives β = e^(−1/τ) §2.1. Appendix A also gives 1 − Δt/τ and then says the exponential form is more precise app. A. Use the exponential form.
- Units of τ. With Δt = 1 and R = 1 app. A, τ is in time steps, not milliseconds. The physical range in §2.1 does not carry over to the discrete model without that conversion.
- The (1 − β) factor is absorbed into W. The input term is W·X[t] eq. 4, so the scale of W differs from a physically normalised model. The paper calls this a non-physiological simplification app. A.
- No gradient without a spike. The surrogate lets error travel backward through a silent neuron, but the weight update on the neuron's output still needs a spike §4.3.1. Dead neurons need threshold adjustments or regularisation, not only a surrogate §3.5 box.
- Threshold equality. The paper says the threshold case depends on the implementation §4.3.1 footnote. The library fires on strictly greater than zero after subtracting the threshold, which matches Eq. 5.
- Cross-entropy sign. The printed cross-entropy in app. B is written as the sum of y·log p without the leading minus. Use the negative log-likelihood, as the library does.
- Inverted first-spike time. Taking the reciprocal of spike times app. B fails at t = 0, where the spike time is zero. The paper warns about this app. B. The library's default negates the time.
- Spike-time losses assume a spike. The default spike-time loss assumes every output neuron fires at least once. The paper suggests forcing a spike at the last step as a workaround §3.3.2.
- Practical notes are the authors' experience. Several claims, such as which surrogate works best and the benefit of normalising inputs to the threshold, are the authors' observations and are not tested in the paper §4.3.1 box §4.3.3.
- Memory cost of online learning. The paper gives BPTT memory as growing with the number of neurons times time, and RTRL's influence matrix as growing faster in the neuron count §5.2. These are scaling statements; no measured numbers are given.
- Quantisation of states. Clipping negative membrane values to zero is suggested for state quantisation, but it is based on early experiments and applies only where inhibitory spikes are not used §4.3.2 box.
Lineage
- Builds on: backpropagation §4 (Rumelhart et al., Linnainmaa, Werbos, as cited); SpikeProp, the first multi-layer SNN backpropagation method §4.2; SLAYER and SpyTorch for surrogate-gradient SNN training §4.3 §4.3.1 box; the straight-through estimator for binary networks §4.3.2; RTRL §5.2.
- Related methods surveyed: e-prop, decolle, OSTL, ETLP, OSTTP and FPTT §5.2.1.
- Compared against: shadow training (ANN-to-SNN conversion) §4.1; spike-time backpropagation §4.2; local learning rules §3.4.
- Superseded by: not known from this wiki's content.
Source and license
Adapted from “Training Spiking Neural Networks Using Lessons From Deep Learning” by Jason K. Eshraghian, Max Ward, Emre Neftci, Xinxin Wang, Gregor Lenz, Girish Dwivedi, Mohammed Bennamoun, Doo Seok Jeong, Wei D. Lu (arXiv:2109.12894), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/jeshraghian/snntorch at commit 37c56ccd0c8e (MIT). Any quoted code is shown under that license.