Dropout Toggle
The simplest possible demonstration of what a dropout mask is. One row of activationCount neuron cells with a single on/off toggle: when off, every cell is active; when on, a deterministic mask drops ~dropoutRate of them. Sits alongside DropoutEnsembleViz, which surfaces the implicit-ensemble interpretation across many sub-networks — this component is the single-pass primitive that teaches the mask itself.
Dropout on, p=50 percent. 9 of 16 cells active.
Dropout toggle09 / 16 active
50%
Customize
Row
16
Dropout
0.50
Installation
npx shadcn@latest add https://craftbits.dev/r/dropout-toggle.jsonUsage
import { DropoutToggle } from "@craft-bits/core";
<DropoutToggle activationCount={16} defaultDropoutRate={0.5} />Drive the rate and enabled state from outside the component:
const [rate, setRate] = useState(0.5);
const [enabled, setEnabled] = useState(true);
<DropoutToggle
activationCount={16}
dropoutRate={rate}
onDropoutRateChange={setRate}
enabled={enabled}
onEnabledChange={setEnabled}
/>Pin a specific mask — (seed, dropoutRate, activationCount) is deterministic across renders:
<DropoutToggle seed={42} defaultDropoutRate={0.5} activationCount={20} />Understanding the component
- One row, one mask. Each cell is one neuron's activation; a kept cell paints
--cb-accent-mutedwith an--cb-accentborder; a dropped cell paints--cb-bgwith a--cb-border-strongoutline and a diagonal strike-through. The strike is a colour-independent signal — dropout reads even on a monochrome display. - Deterministic mask. A Mulberry32 PRNG is seeded with
(seed, activationCount, dropoutRate)so the same inputs always render the same picture. ThedropoutRateis bucketed to three decimals so floating-point jitter from the slider doesn't roll a fresh mask on every pixel. - Toggle disables the mask. When
enabledisfalse, the component short-circuits the mask and renders every cell active — the "no dropout" baseline. Whentrue, the mask is applied; flipping the toggle reads as a clean before/after. - Slider gates on enabled. The
dropoutRateslider is disabled when dropout is off — there's nothing to vary, so the control reads as inert rather than misleadingly live. SPRINGS.smoothon cell opacity. Cell opacity rides a smooth spring from@craft-bits/core/motionbetween active and dropped states.prefers-reduced-motion: reducecollapses every spring to an instant swap.- Controlled + uncontrolled. Both
dropoutRateandenabledfollow the Radixvalue/defaultValuepattern, so the component can be driven by your state or own its own.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
activationCount | number | 16 | Number of neuron cells in the row. Clamped to [2, 64]. |
dropoutRate | number | — | Controlled rate in [0, 1]. Pair with onDropoutRateChange. |
defaultDropoutRate | number | 0.5 | Uncontrolled initial dropout rate. |
onDropoutRateChange | (rate) => void | — | Fires when the rate changes. |
enabled | boolean | — | Controlled dropout on/off. Pair with onEnabledChange. |
defaultEnabled | boolean | true | Uncontrolled initial enabled state. |
onEnabledChange | (enabled) => void | — | Fires when the toggle flips. |
seed | number | 1 | PRNG seed; combined with rate + count to roll the mask. |
transition | Transition | SPRINGS.smooth | Spring for cell opacity transitions. |
className | string | — | Merged onto the root <div> via cn(). |
Accessibility
- The figure is
role="figure"witharia-labelledbynaming the chart "Dropout toggle." - An
aria-live="polite"summary above the row announces whether dropout is on, the current rate, and thekept / totalcount whenever any input changes. - The toggle button uses
aria-pressed; its label flips between "Turn dropout on" and "Turn dropout off" so screen readers narrate the action. - Dropped cells carry a diagonal strike — dropout is signalled by both colour and shape, never colour alone.
- The dropout-rate slider is a
LabeledSlider(a native<input type="range">underneath) with an explicit label; arrow keys nudge the value, screen readers narrate it. The slider isdisabledwhen dropout is off so the inert state is announced. prefers-reduced-motion: reducecollapses every cell transition to an instant swap.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/viz/DropoutToggle.tsx). The source was a 3-layer4 → 6 → 4neural-network visual driven by aModeStriptoggle between an "explore" mode (slider,Drop!/Redrawbuttons, training-to-inferenceTogglePill) and a 6-roundusePredictRoundsquiz, with a heuristic narration panel (ChallengeBtn,FeedbackBadge,ScoreDots,DoneCard), inlinexorshiftmask generator advanced by aseedRef,1/(1−p)scaling labels rendered withSvgLabel, and raw--color-accent-*/--color-ink-*/--color-fail-*CSS vars. The library version drops the quiz mode, the multi-layer architecture, the scaling-factor overlay, the heuristic narration, the inference toggle, and all source-project chrome (ModeStrip,ChallengeBtn,TogglePill,SvgLabel). Reframed as the single-pass primitive every dropout lesson actually needs: one row ofactivationCountcells, one on/off toggle for the mask, one slider for the rate. Replacedxorshiftwith the library-standard Mulberry32 seeded by(seed, rate, count)so the picture is hydration-safe; replaced the raw range input withLabeledSlider; switched all colour to--cb-*tokens; added a diagonal strike for colour-blind safety; and exposed Radix controlled / uncontrolled pairs fordropoutRateandenabled. Sits in ML Viz → Regularization as the before/after companion toDropoutEnsembleViz.