Forward Pass Animator
A feed-forward neural-network visualisation tuned for teaching the forward pass on its own. One layer cursor drives a left → right wavefront: the active layer's neurons light up in --cb-accent, the edges feeding into them pulse on, past layers stay tinted, future layers stay dimmed. Where BackpropFlow shows the round trip (forward + backward), this is the forward-only sibling — use it in lessons that introduce the forward pass before the chain rule.
Forward pass. Layer 1 of 4 activation highlighted.
Forward passlayer 01 / 04
Customize
Architecture
3-4-4-2
Wavefront
0
Playback
Installation
npx shadcn@latest add https://craftbits.dev/r/forward-pass-animator.jsonUsage
import { ForwardPassAnimator } from "@craft-bits/core";
<ForwardPassAnimator layers={[3, 4, 4, 2]} />Pass your own activations from a real forward pass:
<ForwardPassAnimator
layers={[3, 4, 2]}
activations={[
[0.1, 0.5, 0.9],
[0.3, 0.7, 0.2, 0.8],
[0.6, 0.4],
]}
/>Drive playback from outside the component:
const [layer, setLayer] = useState(0);
<ForwardPassAnimator
layers={[3, 4, 2]}
currentLayer={layer}
onCurrentLayerChange={setLayer}
playing={false}
/>Understanding the component
- One cursor, one wavefront.
currentLayerindexes0 … layers.length - 1. The component lights the layer at that index, the edges feeding into it, and every layer to the left of it (already-computed activations). Past the active layer everything stays dimmed. - Edges are the wavefront. Active edges (those feeding the current layer) use the
boldstroke and--cb-accentcolour. Already-swept edges stay at a tinted opacity so the user can see the trail; not-yet-swept edges hold a low opacity so the diagram never goes blank. - Synthesised activations when shape-only. Pass
layers={[3, 4, 2]}withoutactivationsand the component renders deterministic placeholder values that trend up toward the output — the diagram never renders blank, but you should pass real values when you have them. SPRINGS.smoothon the active edge / node. Layer transitions use the smooth spring from@craft-bits/core/motionso the wavefront settles between layers rather than snapping.- Reduced-motion fallback. With
prefers-reduced-motion: reduce, the network renders fully lit on mount with no autoplay and no per-layer animation. - Auto layout from
layersalone. Node positions are derived from the layer-shape array — change the architecture and the diagram re-flows. No coordinates to maintain.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
layers | readonly number[] | — | Neuron count per layer (left → right). Required. |
activations | readonly (readonly number[])[] | — | Forward-pass values per layer. Synthesised if omitted. |
currentLayer | number | — | Controlled cursor in [0, layers.length - 1]. Pair with onCurrentLayerChange. |
defaultCurrentLayer | number | 0 | Uncontrolled initial cursor. |
onCurrentLayerChange | (layer) => void | — | Fires on tick and on manual scrub. |
playing | boolean | — | Controlled play state. Pair with onPlayingChange. |
defaultPlaying | boolean | true | Uncontrolled initial play state. |
onPlayingChange | (playing) => void | — | Fires when play / pause flips. |
playSpeed | number | 600 | Milliseconds between layer advances during autoplay. |
transition | Transition | SPRINGS.smooth | Spring for active-edge / node transitions. |
className | string | — | Merged onto the root <div> via cn(). |
Accessibility
- The figure is
role="figure"witharia-label="Forward pass visualization". - An
aria-live="polite"summary announces the active layer whenever the cursor advances. - The play / pause button is
aria-pressed; the label flips between "Play forward pass" and "Pause forward pass". - The scrubber is a native
<input type="range">with an explicitaria-label, so keyboard arrows nudge the cursor and screen readers narrate the value. - Colour is never the only signal — active-layer count and value labels are textual.
prefers-reduced-motion: reducerenders the network fully lit on mount and disables autoplay.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/viz/ForwardPassAnimator.tsx). The source was a single-neuronx → · M → + Bwidget hard-wired to a slider; this extraction generalises the concept to an arbitrarylayers: number[]feed-forward network so the same component covers the full forward-pass lesson family. Architecture mirrorsBackpropFlow(auto layout fromlayers, controlled / uncontrolled state pairs) so the two compose cleanly in side-by-side lessons.