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-1
L1·N2alive
peak 1.7e+0
L2·N1alive
peak 1.5e+0
L2·N2alive
peak 1.4e+0
L3·N1dead
peak 0
L3·N2dead
peak 0
Customize
Population
6
24
35%
11
Threshold
1e-6

Installation

npx shadcn@latest add https://craftbits.dev/r/dead-neuron-autopsy.json

Usage

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

  1. Two states, two visual treatments. Each neuron card is either alive (sparkline stroked with cb-accent, border cb-border-muted, badge cb-accent-muted) or dead (sparkline cb-error at 65% opacity, border cb-error/40, badge cb-error/15). Dead neurons also expose data-state="dead" so callers can hook custom styles.
  2. 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.
  3. Dead-by-threshold. A neuron is flagged dead when max(|activations|) < deadThreshold. Empty activation arrays are dead by definition. The default threshold is 1e-6 — the standard "below floating-point noise" cutoff for ReLU autopsy.
  4. 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.
  5. Spring transitions on sparkline updates. Path d and opacity animate with SPRINGS.smooth from @craft-bits/core/motion. prefers-reduced-motion: reduce collapses transitions to instant.
  6. 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

PropTypeDefaultDescription
neuronsreadonly DeadNeuronAutopsyNeuron[]Neurons to autopsy. id doubles as React key and accessible label.
deadThresholdnumber1e-6`max(
transitionTransitionSPRINGS.smoothSpring for sparkline path/opacity transitions.
classNamestringMerged onto the root via cn().

Accessibility

  • The root is role="figure" with aria-labelledby pointing at the "Dead neuron autopsy" heading and aria-describedby at a visually-hidden aria-live="polite" summary.
  • The summary announces dead-count, total, and active threshold whenever the input changes.
  • Each card carries data-state="alive" or data-state="dead" so styling never depends on colour alone — the rounded badge spells the state in text.
  • Each sparkline is role="img" with an aria-label that names the neuron, its state, and the peak absolute activation.
  • The grid is a role="list" of role="listitem" cards so assistive tech can navigate one neuron at a time.
  • prefers-reduced-motion: reduce collapses 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, a GradientCascadeViz sibling, 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.