Dead Neuron Grid Inline
DeadNeuronGridInline is the inline sibling of DeadNeuronAutopsy. Same diagnostic — which neurons in a layer have died under ReLU? — but reduced to a single coloured cell per neuron so the whole population fits inline beside body text. Alive cells fill with cb-accent; dead cells fill with cb-fg-subtle and overlay a diagonal stripe so state never depends on colour alone.
Dead neuron gridDead neuron grid. 38 of 60 neurons alive (63%).
Customize
Population
60
35%
11
Geometry
12
20
Installation
npx shadcn@latest add https://craftbits.dev/r/dead-neuron-grid-inline.jsonUsage
import { DeadNeuronGridInline } from "@craft-bits/core";
<DeadNeuronGridInline
neurons={[
{ id: "n0", alive: true },
{ id: "n1", alive: false },
{ id: "n2", alive: true },
]}
/>Force a fixed column count and shrink the cells to 8px for use inside a sentence:
<DeadNeuronGridInline neurons={neurons} cols={20} cellSize={8} />Hide the readout when the surrounding prose already names the count:
<DeadNeuronGridInline neurons={neurons} hideReadout />Anatomy
- Two states, two visual treatments. Each cell is either alive (
bg-cb-accent) or dead (bg-cb-fg-subtleplus a 2px-pitch 45-degree stripe drawn with the page background colour). Both states also exposedata-state="alive"ordata-state="dead"so callers can hook custom styles. - Pure declarative. No threshold, no activations array, no sampling. The caller does the dead/alive classification upstream (using e.g.
DeadNeuronAutopsy'sdeadThresholdrule) and hands the component a boolean per neuron. That keeps the inline variant tiny and zero-allocation per render. - Cell size is the only geometry knob.
cellSize(default 12px) drives the grid track width and the cell width/height.colseither forces a column count or, when unset, letsgrid-template-columns: repeat(auto-fit, ${cellSize}px)fill whatever container width the caller gives it. - Inline by default. The root is
inline-flexso the component composes inside a paragraph: drop it next to a number, between words, beside a chip. PassclassName="block"if you want it on its own line. - Readout uses tabular numerals. The
N/M alive (P%)trailing label usesfont-cb-monoplustabular-numsso the digits don't reflow as the count changes. - No motion budget. This is a sparkline-class component — every render is instant. If you need animated reveals, use
DeadNeuronAutopsyinstead.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
neurons | readonly DeadNeuronGridInlineNeuron[] | — | Neurons to plot. id doubles as React key and accessible label. |
cellSize | number | 12 | Edge length of every cell in pixels. |
cols | number | auto-fit | Force a fixed column count. When unset, the grid auto-fits using cellSize as the minimum track width. |
hideReadout | boolean | false | Hide the trailing N/M alive (P%) label. The aria-live summary still announces the same numbers. |
className | string | — | Merged onto the root via cn(). |
Accessibility
- The root is
role="figure"witharia-labelledbypointing at a visually-hidden "Dead neuron grid" heading andaria-describedbyat anaria-live="polite"summary. - The summary announces alive-count, total, and percentage whenever the input changes.
- Each cell carries
data-state="alive"ordata-state="dead"and anaria-labelof the form<id> aliveor<id> deadso screen readers can name each neuron individually. - Dead cells overlay a diagonal stripe pattern so state never depends on colour alone (contrast-safe under any theme).
- The trailing readout is
aria-hiddenbecause thearia-livesummary already speaks the same numbers — this avoids duplicate announcements.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/viz/DeadNeuronGridInline.tsx). The source coupled a ReLU/Leaky-ReLU toggle, aLabeledSliderfor weight-perturbation, a per-cell motion spring, and project-specific palette vars into one monolithic primitive. Re-architected as a pure declarative inline grid: callers pass{ id, alive }[]and the component handles only the dead-vs-alive rendering, readout, and accessibility — no mode toggle, no slider, no animation, no simulation.