Dead Neuron Autopsy
Activation functions like ReLU can silently kill neurons: once a pre-activation falls below zero and stays there, the gradient is permanently zero and the neuron never recovers. DeadNeuronAutopsy is a diagnostic primitive for spotting these casualties — you supply each neuron's recent activation history, and the component renders a grid of sparkline cards with dead neurons (peak |activation| < deadThreshold) flagged in cb-error.
Dead neuron autopsy. 2 of 6 neurons dead (max absolute activation below 0.000001).
Dead neuron autopsy2/6 dead
L1·N1alive
peak 4.4e-1L1·N2alive
peak 1.7e+0L2·N1alive
peak 1.5e+0L2·N2alive
peak 1.4e+0L3·N1dead
peak 0L3·N2dead
peak 0Customize
Population
6
24
35%
11
Threshold
1e-6
Installation
npx shadcn@latest add https://craftbits.dev/r/dead-neuron-autopsy.jsonUsage
import { DeadNeuronAutopsy } from "@craft-bits/core";
<DeadNeuronAutopsy
neurons={[
{ id: "L1·N1", activations: [0.4, 0.7, 0.6, 0.9] },
{ id: "L1·N2", activations: [0, 0, 0, 0] },
]}
/>Tighten the dead-neuron definition (treat anything below 1e-4 as dead, not just below floating-point noise):
<DeadNeuronAutopsy neurons={neurons} deadThreshold={1e-4} />Anatomy
- Two states, two visual treatments. Each neuron card is either alive (sparkline stroked with
cb-accent, bordercb-border-muted, badgecb-accent-muted) or dead (sparklinecb-errorat 65% opacity, bordercb-error/40, badgecb-error/15). Dead neurons also exposedata-state="dead"so callers can hook custom styles. - Per-card sparkline. Activations are rendered into a fixed 96 x 28 SVG and auto-scaled to the local min/max so even tiny twitches in a dimming neuron stay visible. A subtle dashed midline gives every spark a fixed visual baseline.
- Dead-by-threshold. A neuron is flagged dead when
max(|activations|) < deadThreshold. Empty activation arrays are dead by definition. The default threshold is1e-6— the standard "below floating-point noise" cutoff for ReLU autopsy. - Auto-fit responsive grid. Cards flow into a
repeat(auto-fill, minmax(7.5rem, 1fr))grid so the same component works at any width — single column on phones, four-up on tablets, six-up on desktop. - Spring transitions on sparkline updates. Path d and opacity animate with
SPRINGS.smoothfrom@craft-bits/core/motion.prefers-reduced-motion: reducecollapses transitions to instant. - Pure declarative. No sampling, no internal RNG, no timers. Callers supply the activation arrays — typically captured from a training loop or a forward-pass probe.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
neurons | readonly DeadNeuronAutopsyNeuron[] | — | Neurons to autopsy. id doubles as React key and accessible label. |
deadThreshold | number | 1e-6 | `max( |
transition | Transition | SPRINGS.smooth | Spring for sparkline path/opacity transitions. |
className | string | — | Merged onto the root via cn(). |
Accessibility
- The root is
role="figure"witharia-labelledbypointing at the "Dead neuron autopsy" heading andaria-describedbyat a visually-hiddenaria-live="polite"summary. - The summary announces dead-count, total, and active threshold whenever the input changes.
- Each card carries
data-state="alive"ordata-state="dead"so styling never depends on colour alone — the rounded badge spells the state in text. - Each sparkline is
role="img"with anaria-labelthat names the neuron, its state, and the peak absolute activation. - The grid is a
role="list"ofrole="listitem"cards so assistive tech can navigate one neuron at a time. prefers-reduced-motion: reducecollapses every sparkline transition to instant.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/viz/DeadNeuronAutopsy.tsx). The source coupled a Predict / Explore mode strip, an LR-driven cascade simulation, aGradientCascadeVizsibling, and project-specific palette + chrome (ModeStrip,LabeledSlider,TogglePill,usePredictRounds, project palette vars) into one monolithic lesson. Re-architected as a pure declarative primitive: callers supply each neuron's activation history; the component handles only the dead-vs-alive classification, sparkline rendering, and accessibility — no simulation, no RNG, no project chrome.