# The lightest character recognizer: capital letters (Sep 7 2026)

How small the single-character (drawn input) library can be while still
reading A–Z, measured rather than guessed. Three levers, each measured on its
own: **which drill cells become templates**, **how many points a template
keeps**, and **what the fixed part of the bundle weighs** (wasm + worker +
runtime). Everything below is reproducible with `npm run score:caps` (writes
`server/public/sizelab-data.json`; the CNN rows with `node tuning/caps-cnn.cjs --dump`,
`python3 cnnlab/caps.py`, `node tuning/caps-cnn.cjs --score`; the combinations with
`node tuning/caps-lite.cjs --dumpScores <ids>` then `node tuning/caps-combo.cjs`) and read at `/sizelab.html`.

## The data and the protocol

323 capital-letter cells from the writer's stylus drills
(`training/pen/char-<A-Z>-*`, 9–16 per letter, row/slot tags recorded at
capture time), one writer. Scored through the **char library's own stroke
path** — `resampleStrokes` → `orientedPointsFromPolyline` → the wasm matcher's
`identifyBatch`, which is what `core/worker/tail.js` runs in the browser (not
`identify()`, whose continuity denominator the tuning harness scores through).
Templates carry the integer rounding of the shipped delta encoding; queries do
not, as in production.

**3-fold cross-validation**, folds round-robin within each class in capture
order. A version's templates are chosen from the two non-fold thirds only —
the data-driven strategies never see the query — and every cell is scored
exactly once. The shipped template list is the same strategy over all cells.
The one row this misrepresents is `all`: it measures ~215 templates and ships
323. One error is 0.31%, so rows within two errors of each other are ties.

Selection strategies pick from a proxy cost matrix (`getTestScore`,
denom = dim) computed once per point count; the reported accuracy is always
the production scorer on the chosen set, so a mis-pick shows up as a worse row
rather than a wrong number.

## Where it stands

| version | templates | pts | top-1 | top-3 | ms | training.js raw / gz | lite bundle gz |
|---|---|---|---|---|---|---|---|
| **now**: `all@50` (every cell) | 323 | 50 | **99.07%** | 99.69% | 2.79 | 77.9 / 14.6 KB | 38.5 KB |
| `all@20` | 323 | 20 | 99.69% | 99.69% | 0.42 | 39.6 / 10.6 KB | 34.5 KB |
| `spread-8@20` | 208 | 20 | 99.69% | 99.69% | 0.41 | 25.8 / 7.1 KB | 31.0 KB |
| **`medoid-4@25`** (shipped in `library/templates/char-lite/training.js`) | 104 | 25 | **99.07%** | 99.69% | 0.46 | 15.5 / 4.2 KB | 28.0 KB |
| `budget-3@20` | 78 | 20 | 98.14% | 99.38% | 0.27 | 10.3 / 3.0 KB | 26.9 KB |
| `medoid-2@25` | 52 | 25 | 97.21% | 99.69% | 0.37 | 8.2 / 2.3 KB | 26.2 KB |
| `medoid-1@25` | 26 | 25 | 92.26% | 97.21% | 0.31 | 4.6 / 1.3 KB | 25.2 KB |

Speed is one query in node's wasm build, comparable to the browser worker
(the page's live pad measures ~2.6 ms round trip including the message hop).

What the table says:

- **Points per template is the speed lever and it is free.** 50 → 20 points
  is 6.6× faster with no accuracy cost on this set (every 20-point row ties
  or beats its 50-point twin). The library reads `pointsPerShape` off
  `training.js`, so a version ships as data — no runtime change.
- **A fifth of the templates match the full set.** 104 medoids at 25 points
  read 99.07%, the same as all 323 at 50 points, at 1/5 the training bytes and
  6× the speed. Below ~3 per class accuracy falls off quickly (1 per class:
  ~92%).
- **Strategy matters only at the small end.** At 1–3 per class, medoids
  (unsupervised, the matcher's own within-class distances) and the greedy
  budget pick beat "first n" by 2–5 points; at 4+ per class every strategy
  lands within two errors. `mnist-prune.cjs` found the same on digits.
- **What did NOT matter**: uneven allocation (`budget`) over uniform
  (`greedy`/`medoid`) at equal totals — the drills are accurate and no letter
  is starved; 35 points over 25 or 20 — never better than the cheaper row.

## The fixed part of the bundle

The matcher had grown to 103 KB because `cpp/match.cpp` binds the whole
batch/cascade/GPU-bounds surface. A stroke-only library calls
`firstCall/addPoint*/identify/identifyBatch/getTestScore` and the setters, so
`-DMILLIREC_LITE` leaves the rest unbound (`EMSCRIPTEN_BINDINGS` guard) and
the linker drops it; `-Oz`, `FILESYSTEM=0`, `ASSERTIONS=0` do the rest.
`emmalloc` + LTO + `-fno-exceptions` measured *larger* (31.4 KB) and are not
used.

| | full `char` | `char-lite` |
|---|---|---|
| `millirec.wasm` | 100.5 KB (42.8 gz) | **29.2 KB (13.5 gz)** |
| worker | 20.4 KB (8.6 gz) | 14.8 KB (6.4 gz) |
| runtime | 26.1 KB (9.7 gz) | **9.6 KB (4.0 gz)** — `library/src/char-lite.js`, stroke only |
| fixed total | 146.9 KB (61.1 gz) | **53.6 KB (23.9 gz)** |

**Same arithmetic, gated**: `node tuning/caps-lite.cjs --only spread:3:25
--wasm dist/lite/millirec.js` prints the same top-1/top-3/sse/error list as
the full build (only the timing field differs). Run it after any change to
`scripts/build-wasm-lite.sh`. Build: `npm run build:lite` (emsdk) →
`dist/lite/` → `library/templates/char-lite/`. The full `char` product and
its artifacts are untouched — the guard is inert without the define.

So the smallest useful A–Z recognizer is **~26 KB gzipped end to end**
(`medoid-2@25`: 97.2%), and the one that matches today's accuracy is
**28 KB gzipped / 69 KB raw** (`medoid-4@25`).

## Writing over the cell (Sep 10 2026)

A pad that reads ONE character has a problem no accuracy number shows: what
happens when the writer wants to write a different one. Without help, the
second character lands on top of the first and the reading is neither of them,
so every attempt costs a trip to the clear button. `widget/canvas.js` — the one
drawing surface behind every char pad, the builder and the widget — now has two
answers, and `attach()` turns both on by default (pass `idleOverwrite: 0` /
`scribbleClear: false` to get the old behaviour back).

**`idleOverwrite`, in seconds (default 2).** After that much pen-up the NEXT
stroke starts a fresh drawing instead of adding to this one. It fires on the pen
coming DOWN, not on the timer, so the ink stays there while the writer looks at
it; at the threshold the ink goes faint, which is the warning that the next
stroke replaces it, given *before* the pen lands rather than after.

Two seconds is measured, not chosen. The drill sheets carry a shared clock, so
this writer's real within-character pen-up gaps are recoverable — 443 stroke
pairs inside a single character:

| | ms |
|---|---|
| median | 192 |
| p90 | 367 |
| p99 | **1121** |
| over 1.5 s | 2 pairs (2.8 s and 8.9 s — both interruptions) |

so 2 s costs 0.45% of real within-character pauses, and the faint ink shows the
writer even those two. (The between-character gaps on a drill SHEET are no
guide: median 612 ms, because the writer is moving one slot right, not deciding
what to write next.)

**`scribbleClear` (default on).** Scribble over the cell and it is thrown away.
Geometry only, never the recognizer's confidence — `docs/strikeout.md` has the
full argument, the four signals and the measurement (0 false positives on the
10,701 strokes this writer has ever drawn, and it fires on the one real
scribbled-out word the corpus turns out to contain). `npm run verify:scribble`
is the gate, and it is in `npm test`.

Either way the pad keeps what it dropped: `undoClear()` puts it back, and
`attach()` reports both as a `millirec:clear` event carrying `{reason, undo}`.
That offer deliberately outlives the next stroke on the home page — the wipe
worth undoing is the one that ate the stem of an E you were still drawing, and
by then you are drawing the bars, so restoring merges them.

An empty pad now REPORTS: `attach()` fires `millirec:result` with no results
when the cell is cleared, because a caller left holding the last reading shows
a letter that is gone.

### A grid of cells — `/gridlab.html`

The shape most handwritten forms take is one box per character, and it is the
case a single pad cannot serve: every cell needs its own ink, its own settle
timer and its own reading. `/gridlab.html` is a 5x5 of them, capitals only.

It is `attach()` called once per cell against **ONE** recognizer. A recognizer
*per* cell would be 25 workers and 25 copies of the same templates for no gain,
and the pads are what needs to be independent, not the matcher — `recognize()`
resolves per call, so five cells recognizing at once come back with five
separate readings (measured: five pads written in parallel through the worker
engine read `H O T I V`, one each, no cross-talk).

The colour is the rule, not decoration: a cell's ink is **red while it is still
being written** and **black once the delay has passed**, which is the same edge
that decides whether the next stroke adds to this character or replaces it, and
the prediction grid beside it uses the same two colours. That needed two things
from the pad, both now options on `createDrawCanvas` and forwarded by
`attach()`:

* **`onStale(stale)`** — every transition of the settled state, so a caller can
  restyle a cell rather than only watch it fade. All the pad's own transitions
  now go through one `setStale()`, or the callback would miss an edge (the
  drop-on-pen-down path set the flag directly).
* **`staleAlpha`** (default 0.3) — 1 keeps the settled ink solid, for a caller
  that would rather say "settled" with a colour than with a fade.

Two CSS notes worth keeping, both found by looking at the rendered page:
`nth-child` cannot take a custom property, so a "no border on the last column"
rule written against `var(--cols)` silently does nothing — the rules between
cells are the grid GAP showing the container's colour instead. And a `.note`
with a wide `max-width` inside a flex pane makes that pane demand the width,
which pushed the prediction grid below the fold.

## Does a CNN do better? (Sep 7 2026)

The char library does not use one — it is the point-cloud matcher. The page
path's CNN (`docs/cnn.md`, `cnnlab/`) was tried on the same 323 cells under
the same 3-fold protocol: `cnnlab/caps.py` trains a model PER FOLD on the two
non-fold thirds only (embed.py's recipe and architectures, imported), on
rasters node produced with the page's own `cnnjs.drawStrokes` +
`cnnprep.normalizeInk`; `tuning/caps-cnn.cjs --score` scores every arm
through the real wasm kernel (`server/public/cnnbank/cnn-web.wasm`) and
through `server/public/wordgpu/cnnjs.mjs`, a plain-JS forward of the same
int8 file, gated to agree with the kernel (worst cosine 1.000000 on every
cell). A fourth model per architecture, trained on all cells, drives the
page's live pad and never a reported number.

| arm | top-1 | top-3 | ms | data (raw) | fixed part beyond the runtime | lite bundle gz / raw |
|---|---|---|---|---|---|---|
| **matcher** `spread-8@20` | 99.69% | 99.69% | 0.42 | 25.8 KB training.js | wasm + worker 44.0 KB | 31.0 / 79.4 KB |
| matcher `medoid-4@25` | 99.07% | 99.69% | 0.46 | 15.5 KB | 44.0 KB | 28.0 / 69.1 KB |
| matcher `budget-3@20` | 98.14% | 99.38% | 0.27 | 10.3 KB | 44.0 KB | 26.9 / 63.9 KB |
| **CNN `base` + kNN, 4 medoids/class** | **99.69%** | **100%** | 0.91 | 39.7 KB model + 6.5 KB int8 embeddings | kernel wasm + glue 18.9 KB | 55.7 / 74.7 KB |
| CNN `base` + kNN, all 323 | 99.38% | 100% | 0.92 | 39.7 + 20.2 KB | 18.9 KB | 69.3 / 88.4 KB |
| **CNN `tiny` + kNN, all 323** | **99.07%** | 100% | **0.12** | 8.7 + 20.2 KB | 18.9 KB | 40.3 / 57.4 KB |
| CNN `tiny` + kNN, 4 medoids/class | 98.14% | 100% | 0.11 | 8.7 + 6.5 KB | 18.9 KB | 26.6 / 43.7 KB |
| **CNN `tiny` softmax head, plain JS** | 98.14% | 100% | 0.87 | 8.7 KB model + 1.8 KB head | cnnjs.mjs 8.2 KB, **no wasm** | **17.4 / 28.3 KB** |
| CNN `small` softmax, plain JS | 98.45% | 100% | 3.1 | 17.0 + 1.8 KB | 8.2 KB | 25.1 / 36.6 KB |
| shipped pen model + kNN (no training) | 98.45% | 100% | 0.91 | 39.7 + 20.2 KB | 18.9 KB | 69.3 / 88.4 KB |

Timing is one query after warm-up (best of three passes) — raster
normalisation + embedding + class scoring; the `base` kernel's 0.84 ms is the
number `cnnlab/README.md` measured. Embedding tables are counted as int8
(64 bytes per template) and not compressed; the matcher's training.js
compresses about 4x, which is why its gzipped bundles read smaller than the
raw sizes suggest.

- **Accuracy: a tie at the top.** `base` + 4 medoids reads 99.69%, the same as
  the best matcher row, with a perfect top-3; every difference here is 1-2
  errors on 323 cells and inside the noise. The CNN's top-3 is 100% on every
  arm, the matcher's 99.69%.
- **Speed: the CNN wins once the model is small.** `tiny` + kNN through the
  kernel is 0.12 ms at 99.07% — 4x faster than the equal-accuracy matcher row
  (0.46 ms) — because a 24x24 conv net is 0.38 MMAC and the kernel is not an
  assignment solve. `base` is 0.9 ms, twice the matcher. The plain-JS forward
  is 15 ms for `base` and 0.8 ms for `tiny`: fine for a pad, not for a page.
- **Size: the CNN sets the floor.** The smallest working recognizer measured
  is `tiny` + softmax head in plain JavaScript: 10.5 KB of model, 8 KB of JS,
  no wasm, 98.1% — 17 KB gzipped end to end against the matcher's 27 KB at the
  same accuracy. The CNN's fixed part (kernel 12.7 KB + glue 6.6 KB) is under
  half the lite matcher's (29.9 + 15.2 KB).
- **The shipped pen model works without any training** (98.45% by kNN over
  the writer's own drills) — enrollment-style use of the page path's model.
- **What the softmax head costs**: ~1 point against kNN on the same model, and
  it cannot be enrolled with a new template. It is the right arm only when
  size is the whole question.

Caveats as before: one writer, 323 drill cells, 250 epochs at one seed —
`cnnlab/README.md` measured a +-0.5 seed spread on a 675-cell set, so treat
the CNN rows as +-1 point. The matcher was swept over 124 versions and the CNN
over 13, so the matcher frontier is the better-explored one.

## Combining them: fusion and cascades (Sep 7 2026)

Two follow-ups, both from the score dumps of the runs above (`caps-lite.cjs
--dumpScores`, `caps-cnn.cjs --score`) through `tuning/caps-combo.cjs`, so
every cell is still scored by models and templates that never saw it. Each
arm's vector goes into nats above its own best; a FUSION adds two vectors
with a matcher weight `a`; a CASCADE runs a tiny first pass and escalates to
a second only when the first pass's runner-up is within `theta` nats. Both
`a` and `theta` are chosen on the other two folds' held-out predictions and
applied to the third — a weight swept on the cells it is scored on would
report the sweep. 116 rows, all on `/sizelab.html` in green.

| combination | top-1 | top-3 | ms | escalated | data raw | fixed beyond runtime | lite bundle gz / raw |
|---|---|---|---|---|---|---|---|
| fuse(medoid-1@20, tiny+kNN) — 26 templates + 8.7 KB model | 99.38% | 100% | 0.32 | – | 33.0 KB | both wasms 62.9 KB | 61.4 / 105.5 KB |
| fuse(budget-3@20, tiny softmax) — no CNN wasm | 99.38% | 100% | 1.43 | – | 20.8 KB | 52.2 KB | 40.3 / 82.6 KB |
| fuse(medoid-4@25, tiny+kNN) | 99.69% | 100% | 1.29 | – | 44.4 KB | 62.9 KB | 64.3 / 116.9 KB |
| fuse(medoid-1@20, shipped pen model) | **100%** (0/323) | 100% | 1.11 | – | 64.0 KB | 62.9 KB | 90.4 / 136.5 KB |
| fuse(spread-8@20, base+kNN-m4) — the two best alone | 99.38% | 100% | 2.38 | – | 72.1 KB | 62.9 KB | 82.6 / 144.6 KB |
| casc(tiny+kNN → base+kNN-m4)@10 — one kernel | 99.69% | 100% | **0.21** | 10% | 75.1 KB | 18.9 KB | 84.3 / 103.6 KB |
| casc(tiny+kNN → spread-8@20)@10 | 99.69% | 99.69% | **0.16** | 10% | 54.7 KB | 62.9 KB | 67.2 / 127.2 KB |
| casc(medoid-2@20 → spread-8@20)@35 — matcher only | 99.69% | 99.69% | 0.38 | 35% | 33.1 KB | 44.0 KB | 33.2 / 86.7 KB |
| casc(tiny softmax → spread-8@20)@10 | 99.69% | 99.69% | 0.90 | 10% | 36.4 KB | 52.2 KB | 44.3 / 98.2 KB |
| casc(tiny softmax → small softmax)@10 — no wasm at all | 98.76% | 100% | 1.17 | 10% | 30.4 KB | 8.2 KB | 37.8 / 48.4 KB |

Cascade time is the mean (first pass + escalated fraction × second pass);
the worst case is the sum. Fusion pays the matcher's FULL score vector
(rawScores, every template solved), which is 3-4x its pruned top-3 time.

What the rows say:

- **Two tiny arms do fuse into an accurate one.** 26 matcher templates
  (89.8% alone) plus the 8.7 KB tiny CNN (99.07%) read 99.38%; 78 templates
  plus the tiny softmax head, no CNN wasm, 99.38%; 26 templates plus the
  shipped pen model read every cell right. The errors of the two families
  are different errors — 5 of the tiny CNN's 6 fall to the matcher and vice
  versa — which is exactly the condition fusion needs.
- **There is no headroom at the top.** Fusing the two best single arms
  (99.69% each) gives 99.38%: one more error, and inside the noise. Fusion
  buys accuracy for SMALL arms, not for good ones.
- **Cascades recover the big model's accuracy at a tenth of its cost.** Tiny
  CNN first, the base CNN on the 10% of cells whose runner-up is within ~2.4
  nats: 99.69% at 0.21 ms mean against 0.91 ms for base alone — and with the
  matcher as the second pass, 0.16 ms, the fastest 99.69% measured. The
  threshold generalises: chosen on two folds, it escalates 9.9% of the third.
- **Fusing the second pass with the first buys nothing** (same or one worse
  on every cascade): once a cell is escalated, the big arm alone is the
  better judge of it.
- **The matcher-only cascade is a wash** (0.38 vs 0.42 ms): the pruned
  identifyBatch path is already cheap, so there is little to skip.
- **The price is the bundle.** A matcher+CNN combination ships both fixed
  parts (63 KB raw beyond the runtime), so the smallest accurate
  combinations are single-family: tiny→base on one kernel, or the all-JS
  softmax cascade at 98.8% with no wasm at all.

Caveats as before, plus: 0/323 is not "perfect", it is one seed on one
writer's drills with a ±1-point spread, and 116 combinations were looked at
— the frontier is the honest object, not any single row.

## At scale: EMNIST uppercase, hundreds of writers per letter (Sep 7 2026)

Everything above is one writer's 323 drill cells. To test against hundreds of
samples per letter the benchmark moved to **EMNIST byclass, uppercase only**
(NIST's `gzip.zip`, now in `tuning/emnist-data/`; the repo's older `letters`
split merges upper and lower case into one class and cannot test capitals).
`tuning/emnist-caps.cjs --dump` takes 600 train images per letter from the
train split (seeded) as the template / training pool and 300 per letter from
the test split — **7,800 tests**, nothing in the test split ever a template,
a training image or a selection input. `cnnlab/caps.py --dir cnnlab/emnist`
trains one model per architecture on the pool (25 epochs); `--score` runs
every arm; `caps-combo.cjs --set emnist` fuses and cascades exactly as on the
drills, with the weight/threshold chosen on two thirds of the test rows and
applied to the third. `/sizelab.html?set=emnist` shows it all, with the
misread images.

**What this can and cannot measure.** EMNIST is raster data — there is no pen
trajectory — so the matcher here is the library's PHOTO path (Otsu →
farthest-point cloud → structure-tensor tangents and curvature, alpha 5 /
gamma 3, `identifyBatch`), not the stroke path the drills measured; and its
templates are cloud samples (50 × {x,y,s,c,k}, ~2.6 KB of JSON each), ten
times a stroke template. The CNN runs unchanged.

| arm | top-1 | top-3 | ms | data | lite bundle gz / raw |
|---|---|---|---|---|---|
| matcher, 300 random templates/class, 50 pts | 94.27% | 99.22% | 50 | 20.2 MB JSON (~0.86 MB quantised) | 4.4 / 20.3 MB |
| matcher, 100 medoids/class, 50 pts | 93.10% | 98.96% | 20 | 6.7 MB (~0.29 MB) | 1.5 / 6.8 MB |
| matcher, 100 medoids/class, 25 pts | 90.18% | 98.09% | 4.4 | 3.4 MB (~0.14 MB) | 0.76 / 3.4 MB |
| matcher, 30 medoids/class, 25 pts | 86.74% | 96.85% | 1.8 | 1.0 MB (~43 KB) | 248 KB / 1.1 MB |
| **CNN base, softmax (plain JS)** | **97.99%** | 99.67% | 17.3 | 41.6 KB | **46 / 59 KB** |
| CNN base + kNN, 100 medoids/class | 97.64% | 99.69% | 1.07 | 202 KB | 211 / 231 KB |
| CNN base + kNN, all 15,600 | 97.77% | 99.71% | 2.07 | 1.0 MB | 1.0 / 1.0 MB |
| CNN small, softmax | 96.69% | 99.46% | 3.4 | 18.8 KB | 25 / 37 KB |
| **CNN tiny, softmax** | 96.03% | 99.28% | 0.92 | 10.5 KB | **17 / 28 KB** |
| CNN tiny + kNN, 100 medoids/class | 95.29% | 99.27% | 0.28 | 171 KB | 183 / 200 KB |
| shipped photo model + kNN, no EMNIST training | 91.95% | 98.40% | 1.06 | 202 KB | 212 / 231 KB |

- **On many writers the learned metric wins outright**: the smallest CNN
  (10.5 KB, plain JS) beats the largest matcher row (20 MB, 51 ms) by 1.8
  points at 55x the speed, and the base CNN is 3.7 points ahead of it. The
  matcher's photo path was tuned on MNIST digits and the writer's own
  photos; across 26 letters and hundreds of hands its top-1 saturates around
  94% while its top-3 stays at 99%, i.e. the ranking is right and the fine
  decision is not.
- **Template count matters a lot for the matcher here** (10 → 100 medoids
  per class: 88 → 93%), unlike the drills, where 4 per class was enough —
  one hand needs few exemplars, hundreds of hands need many.
- **The shipped photo model transfers**: 92% by kNN over EMNIST medoids with
  no EMNIST training at all, roughly the matcher's 100-medoid row at 1/6 the
  size and 20x the speed.

Combinations, nested exactly as on the drills (99 rows):

| combination | top-1 | top-3 | ms | escalated | lite bundle gz / raw |
|---|---|---|---|---|---|
| fuse(matcher 300/class, CNN base + kNN) | **98.10%** | **99.81%** | 52 | – | 5.4 / 21.3 MB |
| fuse(matcher 30 medoids @25, CNN base softmax) | 98.01% | 99.67% | 19 | – | 290 KB / 1.1 MB |
| fuse(matcher 100 medoids @50, CNN small softmax) | 97.27% | 99.59% | 23 | – | 1.5 / 6.8 MB |
| fuse(matcher 30 medoids @50, CNN tiny softmax) | 96.42% | 99.44% | 9.0 | – | 481 KB / 2.1 MB |
| **casc(tiny softmax → base softmax)@20**, plain JS | 97.97% | 99.64% | **4.4** | 20% | **56 / 70 KB** |
| casc(tiny softmax → base softmax)@35 | 98.01% | 99.67% | 7.0 | 35% | 56 / 70 KB |
| casc+fuse(tiny softmax → base + kNN all)@35 | 97.90% | 99.71% | 1.6 | 35% | 1.0 / 1.1 MB |
| casc(tiny + kNN m100 → base + kNN all)@35 | 97.74% | 99.68% | 1.0 | 35% | 1.2 / 1.2 MB |
| casc(small softmax → base softmax)@20 | 97.99% | 99.69% | 6.9 | 20% | 64 / 78 KB |
| casc(matcher 30 medoids @25 → base softmax)@35 | 96.67% | 99.13% | 7.8 | 35% | 290 KB / 1.1 MB |

- **Fusion buys 0.1–0.6 points here, never more.** The drills' "two tiny arms
  make an accurate one" does not repeat: with hundreds of hands the two
  families' errors overlap, and the matcher is too far behind for its vote to
  move the CNN (best fused 98.10% vs 97.77% alone, at 25x the time and 20 MB
  of templates). A fusion never beats the base CNN by more than the seed
  spread.
- **Cascades again recover the big model at a fraction of its cost.** Tiny
  softmax first, base softmax on the 20% of images whose runner-up is within
  ~2.2 nats: 97.97% against 97.99% for base alone, at 4.4 ms instead of 17.3
  — all plain JS, 56 KB gzipped. With kNN arms through the kernel the same
  shape reaches 97.9% at 1.6 ms.
- **Fusing the second pass with the first now helps slightly** (+0.1–0.15
  on the kNN cascades) where it never did on the drills — the softmax first
  pass carries information the kNN second pass lacks.
- **A matcher first pass is the wrong order**: escalating 35% of images from
  the 30-medoid matcher to the base CNN reads 96.7%, below the tiny CNN alone.

So for capital letters from an unknown hand the answer changes: the CNN, not
the matcher, and a two-model cascade of it. For one enrolled hand (the
drills) the two are tied and the matcher's stroke templates are the smaller
bundle. Seeds: one per model, ±0.3 on 7,800 tests; the matcher's photo-path
parameters were not re-swept for EMNIST.

## All-CNN: a tiny softmax first, a larger softmax on close calls — the sweep (Sep 7 2026)

The decision after the rounds above: no matcher, no templates — a softmax
CNN cascade. This section is the sweep of that design on EMNIST uppercase
(the many-writer benchmark; 7,800 test images, 2,400 train images per letter
available). Tools: `cnnlab/caps.py` grew architectures, `--per-class`,
`--headNorm`, `--distill` and a 4-bit export; `tuning/emnist-cascade.cjs`
scores every model through both runtimes and builds every two-stage pair at
seven escalation rates plus six three-stage ladders, thresholds nested on the
other two test folds as before; `/sizelab.html?set=emnist` (all-CNN filter on
by default, runtime toggle, a threshold-curve chart per cascade, the live pad
walking the real stages).

### Three things that changed the runtime picture before any sweep

- **The softmax head can be served by the wasm kernel.** The kernel returns
  only the L2-normalised embedding; a head trained on `relu(e)` cannot use
  it (its bias does not scale). Training the head on `relu(e/‖e‖)`
  (`--headNorm`) costs nothing measurable (tiny 95.90 vs 96.03, base 98.08
  vs 97.99 on the raw head) and lets the kernel embed while a 64×26 linear
  runs in JS: **18–20× faster than the plain-JS forward** at identical
  accuracy (tiny 0.047 vs 0.88 ms, base 0.84 vs 17.2 ms). Price: the kernel
  (12.7 KB wasm + 6.6 KB glue) instead of 8 KB of JS.
- **The kernel needs channel widths in fours** (it packs four output
  channels per pass and rejects the file otherwise). `nano`/`micro`
  (6/12/24) are JS-only; `pico` (4/8/16 at 20 px, 3.2 KB) and `nano4`
  (4/12/24 at 24 px, 5.4 KB) were added as kernel-friendly small stages.
- **4-bit weights** (per-channel scale chosen to minimise squared error,
  `cnnlab/requant4.py`; the naive max/7 scale lost 2.3 points on tiny)
  halve a file at a cost that depends on the model's redundancy: base
  98.37 → 98.19, small 97.33 → 97.06, tiny 96.46 → 93.19, nano4 94.9 → 89.1.
  A second-stage lever only, and JS-only (the kernel reads int8).

### Single models (EMNIST uppercase, kernel ms / JS ms)

| model | int8 | 4-bit | top-1 | top-3 | kernel | JS |
|---|---|---|---|---|---|---|
| pico 20 px, 2400/letter | 3.2 KB | 2.0 | 90.71% | 98.55% | 0.011 ms | 0.18 |
| nano4 24 px, 2400 | 5.4 KB | 3.1 | 94.92% | 99.14% | 0.024 | 0.42 |
| tiny 24 px, 300 / 600 / 1200 / 2400 | 8.7 KB | 4.9 | 94.32 / 95.90 / 96.50 / 96.46% | 99.5% | 0.047 | 0.88 |
| tiny 2400, distilled from base | 8.7 KB | | 96.46% | 99.41% | 0.047 | 0.88 |
| tiny32 (32 px input), 600 | 8.7 KB | | 95.67% | 99.26% | 0.086 | 1.60 |
| small 32 px, 600 / 2400 / 2400 distilled | 17.0 KB | 9.1 | 97.14 / 97.33 / **97.54%** | 99.5–99.7% | 0.18 | 3.4 |
| mid 32 px, 600 / 2400 | 28.1 KB | 14.8 | 97.47 / 97.79% | 99.7% | 0.30 | 5.9 |
| base 32 px, 600 / 2400 | 39.7 KB | 20.8 | 98.08 / **98.37%** | 99.73% | 0.84 | 17.2 |
| large 32 px, 600 | 84.6 KB | | 98.18% | 99.79% | 2.0 | 38.5 |

- **More data beats more width.** base 600 → 2400 per letter: +0.3; large
  at 600 (twice the weights) does not beat base at 2400. tiny saturates at
  ~1200 per letter (96.5%); pico/nano4 have no headroom at any pool size.
- **Distillation is not worth it here**: tiny unchanged, small +0.2, the
  smallest models slightly worse. One seed each, ±0.3.
- **Input resolution**: tiny at 24 px matches tiny at 32 px at half the cost.

### The cascades (kernel timing unless noted; 1,867 rows)

Escalate when the first stage's runner-up logit is within θ nats of its best;
θ is the target quantile of first-stage margins on the other two folds.

| cascade | top-1 | top-3 | escalated | mean ms | worst ms | bundle gz / raw |
|---|---|---|---|---|---|---|
| base alone | 98.37% | 99.73% | – | 0.88 | 0.88 | 50.4 / 70.0 KB |
| **tiny-kd → base, 20%** | **98.40%** | 99.71% | 20% | **0.27** | 0.96 | 60.6 / 80.6 KB |
| tiny-kd → base, 15% | 98.36% | | 15% | 0.23 | | 60.6 / 80.6 |
| tiny-kd → base, 10% | 98.23% | | 10% | 0.19 | | 60.6 / 80.6 |
| tiny-1200 → base, 5% | 97.95% | | 5% | 0.15 | | 60.6 / 80.6 |
| nano4 → base, 30% | 98.26% | | 30% | 0.33 | | 57.5 / 77.3 |
| pico → base, 50% | 98.18% | | 50% | 0.49 | | 55 / 75 |
| tiny-1200 → mid, 20% | 97.81% | | 20% | 0.16 | | 50.0 / 68.9 |
| tiny → small-kd, 15% | 97.60% | | 15% | 0.13 | | 39.8 / 57.8 |
| nano4 → small-kd, 10% | 97.21% | | 10% | 0.10 | | 36.7 / 54.5 |
| tiny-1200 → small-kd → base, 30%/30% | 98.37% | | 30% then 30% | 0.24 | | 78.6 / 99.4 |
| nano4 → tiny → base, 30%/30% | 98.10% | | | 0.18 | | 67.7 / 87.8 |
| **JS only**: tiny → base-q4, 20% | 98.17% | | 20% | 4.4 | 18 | 37.5 / 51.0 KB |
| JS only: nano → small-kd, 20% | 97.56% | | 20% | 1.1 | | 32.4 / 44.1 KB |
| JS only: tiny-1200 → base, 5% | 97.95% | | 5% | 1.8 | | 56.2 / 69.9 KB |

What the sweep says:

- **The answer is tiny → base at 15–20% escalation.** It matches or beats
  the base model alone (98.36–98.40% vs 98.37%) at 0.23–0.27 ms mean — 3.4×
  faster — for 10 KB of extra bundle (the tiny model and its head). The
  worst case is one base pass plus one tiny pass, 0.96 ms.
- **The first stage should be tiny, not smaller.** pico (90.7%) and nano4
  (94.9%) must escalate 30–50% of images to reach base's accuracy, which
  erases the speed win (0.33–0.49 ms); tiny at 96.5% escalates 15–20%. The
  first stage's own accuracy sets the escalation rate, and the curve shows
  no cheaper point on any pair.
- **The second stage should be base at 2400 per letter.** mid as second
  stage caps at 97.8%, large is no better than base and twice its time; a
  4-bit base costs 0.2 points and forces the JS runtime.
- **Three stages buy nothing.** tiny → small → base at 30%/30% reads
  98.37% at 0.24 ms — the same point as the two-stage row.
- **Distilled tiny is the marginally better first stage** (98.40 vs 98.32
  at 20%) though not a better classifier alone; its margins are better
  ordered, which is what escalation consumes.
- **Without wasm** the same design is 4.4 ms (tiny → base-q4, 98.2%) or,
  for the smallest bundle, 1.1 ms at 97.6% (nano → small, 44 KB raw).

Caveats: one seed per model (±0.3 on 7,800 tests); 1,867 rows were looked at,
so read the frontier, not a single cell; the escalation rate is honest
(nested) but the CHOICE of "20%" was made looking at the frontier. Timings
are node's wasm/JS on an idle machine after warm-up; the page's pad numbers
include canvas rasterisation and are several ms higher.

## Compressing the all-CNN bundle, and the options menu (Sep 7 2026, evening)

Four questions from Rob — smarter compression, one model instead of two, an
arrangement that compresses better, and a menu of options with the sizes of
the smallest models — answered by measuring. Everything is in
`library/templates/char-cnn/` (the CNN-only product: runtime, kernels,
models, `config.js`), and the menu is on `/sizelab.html?set=emnist` as
"Bundle options", built by `tuning/bundle-menu.cjs` from the real files.

### Where the bytes were

For the small models the weights were NOT the file. pico's 3.3 KB int8 file
held 1.5 KB of conv weights and 1.8 KB of 64-wide embedding linear plus
f32 scale/bias, and its head was another 1.9 KB — the 64-d embedding is a
kNN feature, useless to a softmax-only stage. **`--dim 16`** shrinks the
embedding and head to a sixth:

| model | 64-d: model + head | 16-d: model + head | top-1 64-d → 16-d |
|---|---|---|---|
| pico | 3.3 + 1.9 KB | **2.1 + 0.6 KB** | 90.71 → 90.00 |
| nano4 | 5.4 + 1.9 | 3.9 + 0.6 | 94.92 → 93.51 |
| tiny | 8.7 + 1.9 | **6.8 + 0.6** | 96.46 → 96.33 |
| small | 17.0 + 1.9 | 14.4 + 0.6 | 97.33 → 97.12 |
| base | 39.7 + 1.9 | 36.4 + 0.6 | 98.37 → 98.01 |

Free on pico and tiny, a third of a point on small, worth avoiding on base.
The kernel and its glue were the other overhead: the shipped glue (6.6 KB)
halves to **3.0 KB** with closure compilation at identical speed, and an
`-Oz -msimd128` build of the kernel is 9.4 KB instead of 12.7 at ~20%
slower (plain `-Oz` without SIMD is 4× slower — never ship that). The
CNN-only runtime is 8.8 KB minified (4.1 gz): 3.6 KB of forward pass, 2.5 KB
of runtime, 1.7 KB of drawing pad, 1.0 KB of rasteriser.

### What does not compress

int8 weights are near-incompressible: gzip and brotli take 8–12% off a model
file and nothing more, whether the models are packed into one file or served
separately (`gzWhole` vs `gzFiles` in the menu differ by under 1%). Arranging
the file differently cannot change that; only fewer or narrower weights
can. The two real levers are 4-bit weights (a per-channel scale chosen to
minimise squared error — the naive max/7 rule lost 2.3 points on tiny) and
the 16-d embedding above. 4-bit: base −0.2 (98.19%), small −0.3, tiny −1.2
(with 16-d: 95.29%), pico/nano4 unusable (−10 to −15). JS-only: the kernel
reads int8.

### One model instead of two? Measured: no

A single base network with an auxiliary early-exit head
(`cnnlab/caps.py --auxAfter k`, `cnnjs.embedPartial`): run the prefix, exit
if the runner-up is far behind, else finish the remaining layers with no
recomputation. After pool 1 the exit reads 65.9% — useless. After pool 2 it
reads 97.2%, but the prefix costs **85% of the forward pass**, because this
architecture spends its compute in the wide early stages (stage 1 of base
is 2.5 MMAC of 7.2), so the cascade over it reaches 98.27% at 15.6 ms
against the full model's 17.6 — a 12% saving. The separate tiny model at
24 px is 0.38 MMAC: that is why two files beat one, and it costs 7.5 KB
(16-d tiny) on top of base. A width-nested ("slimmable") single file would
share weights but needs BatchNorm-free training to fold; not attempted.

### The menu (from the actual files; raw / gzip / brotli of the whole bundle)

| option | top-1 | ms | bundle raw / gz / br |
|---|---|---|---|
| **pico alone**, plain JS (2.1 KB model, 16-d) | 90.0% | 0.21 | **11.4 / 7.2 / 6.2 KB** |
| pico alone, kernel | 90.0% | 0.05 | 26.7 / 14.4 / 12.1 |
| **nano4 alone**, plain JS (3.9 KB, 16-d) | 93.5% | 0.46 | **13.1 / 9.0 / 8.0** |
| nano alone, plain JS (widths 6/12/24 — JS only) | 95.2% | 0.39 | 16.1 / 12.1 / 10.8 |
| tiny alone, plain JS (6.8 KB, 16-d) | 96.3% | 0.93 | 16.1 / 12.0 / 10.7 |
| tiny alone, 4-bit, plain JS | 95.3% | 0.93 | 13.0 / 8.7 / 7.6 |
| tiny alone, kernel | 96.3% | 0.09 | 31.4 / 19.3 / 16.5 |
| small alone, kernel | 97.1% | 0.22 | 38.9 / 26.4 / 23.4 |
| nano4 → small @10%, plain JS | 96.7% | 0.82 | 32.0 / 27.3 / 25.7 |
| tiny → small @15%, plain JS / kernel | 97.6% | 1.45 / 0.12 | 38.0 / 33.0 / 31.3 · 53.3 / 40.2 / 37.2 |
| tiny → base 4-bit @20%, plain JS | 98.2% | 4.5 | 41.8 / 35.3 / 33.4 |
| base alone, 4-bit, plain JS | 98.2% | 17.6 | 31.3 / 25.3 / 23.4 |
| tiny(16-d) → base @20%, kernel | 98.38% | 0.26 | 73.0 / 58.1 / 54.9 |
| **tiny → base @20%, kernel** (shipped `config.js`) | **98.40%** | **0.26** | 76.1 / 61.2 / 57.8 |
| base alone, kernel | 98.37% | 0.88 | 65.5 / 51.0 / 47.9 |
| base with early exit after pool 2 @20%, plain JS | 98.26% | 15.6 | 51.2 / 45.0 / 43.0 |

So: **just pico is 11 KB raw (6 KB brotli) at 90%; just nano is 13–16 KB
(8–11 KB brotli) at 93.5–95%**; the smallest thing that clears 98% is 31 KB
(4-bit base, plain JS, 18 ms); the fast and accurate one is 76 KB with the
kernel at 0.26 ms. The runtime's drawing pad is 1.7 KB of that; callers that
bring their own strokes could drop it.

## The pruning / quantisation frontier, and four targets (Sep 8 2026)

Levers added to `cnnlab/caps.py`: `--qat N` (quantisation-aware training:
per-channel n-bit fake quantisation with a straight-through gradient after 40%
of the epochs; the export reproduces the exact levels), `--sparsity p`
(unstructured magnitude pruning, mask fixed after 40%), `--prune-from TAG
--prune f` (channel pruning of a trained model to widths in fours, then
fine-tuning), `--export-bits 3,4,5,6` (n-bit files, `MRCNN3..6`, read by
`cnnjs.mjs` and expanded to int8 in memory for the kernel, so a small file
now serves both runtimes). 17 more models, 140 single-model rows, 1,722
cascades, all on the full 7,800 (the single-model pass is cheap through the
kernel, so subsampling was not needed). `tuning/bundle-menu.cjs` answers the
targets over every row and both runtimes, with or without the drawing pad
(`millirec-char-cnn-core.min.js`, 7.9 KB / 3.6 gz, no pad).

### What each lever is worth

| lever | result |
|---|---|
| QAT 4-bit, base | **98.47%** in a 20.8 KB file — better than int8 base (98.37%); the regulariser helps. Free. |
| QAT 4-bit, tiny (16-d) | 96.28% at 4.4 KB against 95.29% post-training — recovers 1 of the 1.1 points lost |
| QAT 3-bit, tiny | 95.47% at 3.6 KB; 3-bit post-training is 81–86% — QAT is mandatory at 3 bits |
| 50% sparsity, base | 98.27% int8; with QAT-4 **98.33%** in a 20.8 KB file that gzips to 14 KB |
| 70% sparsity + QAT-4, small | 95.10% — too far |
| channel pruning, base −25% | 98.15% at 23.6 KB and **0.48 ms** (was 0.84) — the best mid-size single model |
| channel pruning, base −50% | 97.27% at 11.7 KB / 0.22 ms — no better than small trained from scratch |
| pruning small −50% | 93.97% — fine-tuning from a pruned small model does not recover |
| large at 2,400/letter | 98.45% (85 KB, 2.0 ms); xlarge (291 KB, 5 ms) 98.44% |
| ensembles | base+base(seed 1) 98.46%, base+large+xlarge 98.64%, five models 98.65% |

### The four targets (every row, both runtimes, pad or no pad)

| question | answer | top-1 | ms | bundle gz / raw |
|---|---|---|---|---|
| most accurate averaging ≤ 0.10 ms | tiny → base pruned 25% at 5% escalation, kernel | 97.77% | 0.095 | 45 / 61 KB |
| … relaxed to 0.12 ms | the same at 10% | 98.05% | 0.118 | 45 / 61 KB |
| most accurate at ≤ 10 KB gzipped | tiny 16-d QAT-4 (int8 file), plain JS, no pad | 96.36% | 0.89 | **8.0 / 15 KB** |
| … at ≤ 12 KB | small 16-d QAT-4 at 4 bits, plain JS, no pad | 97.00% | 3.4 | 10.7 / 16 KB |
| fastest with > 98% | tiny → base pruned 25% at 10%, kernel | 98.05% | **0.118** | 45 / 61 KB |
| smallest with > 98% | base 50% sparse + QAT-4, 4-bit file, plain JS, no pad | 98.33% | 17.3 | **20.6 / 30 KB** |
| … fast and small | tiny 16-d → base QAT-4 (4-bit) at 20%, kernel | **98.49%** | 0.24 | 37 / 50 KB |
| anything > 99% | **none**. Best measured: five-model ensemble | 98.65% | 9.0 | 454 / 518 KB |

The 99% question is answered by the ceiling, not by size: base 98.4, large
98.45, xlarge 98.44, and a five-model ensemble 98.65 — twelve times the bytes
for a quarter of a point. The residual is the test set's own ambiguity (V/U
and U/V alone are 28 of the ~120 errors of the best rows, then O/D, C/L, Y/V);
this recipe on this split saturates about 98.5–98.7.

`config.js` now ships tiny (16-d, int8) → base QAT-4 (4-bit file) at 20%:
98.49% at 0.24 ms via the kernel, 50 KB raw / 37 KB gzipped with the pad; the
4-bit base is expanded to int8 in memory. Every other option's files are in
the same directory; `/sizelab.html?set=emnist` has the 85-row menu and the
targets table at the top.

## The three shipped options, and the builder question (Sep 8 2026)

`library/templates/char-cnn/options/{fast,small,accurate}/` — each a complete
servable directory (runtime, kernel where used, model files, `config.js`,
`index.html`, and a README carrying the exact commands that made it), built by
`npm run build:cnn-options` (`scripts/build-cnn-options.mjs`) from the
trained models in `cnnlab/emnist/`. Every number below was re-checked in
Chrome on the shipped files.

| option | what | top-1 | ms (node kernel) | bundle raw / gz / br |
|---|---|---|---|---|
| `fast` — most accurate under 0.10 ms | tiny (1200/letter, 64-d) → base channel-pruned 25%, θ 0.89 (5% escalate), kernel | 97.77% | 0.095 | 61.6 / 45.7 / 43.9 KB |
| `small` — most accurate under 10 KB gz | tiny 16-d, quantisation-aware 4-bit, int8 file, pad-less runtime, plain JS | 96.36% | 0.89 (JS) | 15.5 / 8.2 / 7.3 KB |
| `accurate` — fast and small above 98% | tiny 16-d → base QAT-4 (4-bit file), θ 2.03 (20%), kernel | 98.49% | 0.24 | 55.6 / 37.8 / 35.7 KB |

**Since then (Nov 21 2026)** — the table above is the round that chose these options; their
numbers today: every head refitted on its shipped, quantised weights (`cnnlab/calibrate_head.py`,
chosen on held-out training rows), a 2.3x faster kernel, strokes rasterised in software, and `small`
shipping its 4-bit file. `fast` 97.92% at 0.056 ms, `small` 96.79% at 0.144 ms (plain JS, 9.8 KB
gzipped with its runtime), `accurate` 98.51% at 0.155 ms — Chrome, recognition only. The live
numbers for every option are `library/templates/char-cnn/options/index.json`
(`npm run build:cnn-options`).

### How to generate them

```sh
node tuning/emnist-caps.cjs --dump --train 2400 --no-clouds        # EMNIST byclass uppercase -> cnnlab/emnist/
# fast
python3 cnnlab/caps.py --dir cnnlab/emnist --folds all --headNorm --archs tiny --per-class 1200 --epochs 25 --tag '{arch}-n1200-hn'
python3 cnnlab/caps.py --dir cnnlab/emnist --folds all --headNorm --archs base --per-class 2400 --epochs 15 --batch 128 --tag '{arch}-n2400-hn'
python3 cnnlab/caps.py --dir cnnlab/emnist --folds all --headNorm --archs base --per-class 2400 --epochs 8 --batch 128 --lr 1e-3 --prune-from base-n2400-hn --prune 0.25 --tag base-p25
# small
python3 cnnlab/caps.py --dir cnnlab/emnist --folds all --headNorm --archs tiny --per-class 2400 --epochs 15 --batch 128 --dim 16 --qat 4 --export-bits 4 --tag '{arch}-d16-qat4'
# accurate
python3 cnnlab/caps.py --dir cnnlab/emnist --folds all --headNorm --archs tiny --per-class 2400 --epochs 15 --batch 128 --dim 16 --tag '{arch}-n2400-hn-d16'
python3 cnnlab/caps.py --dir cnnlab/emnist --folds all --headNorm --archs base --per-class 2400 --epochs 15 --batch 128 --qat 4 --export-bits 4 --tag '{arch}-qat4'
# refit each shipped head on its shipped weights' embeddings (train rows only; added Nov 21 2026, after the table above)
python3 cnnlab/calibrate_head.py --dir cnnlab/emnist --tags tiny-n1200-hn,tiny-n2400-hn-d16,base-p25
python3 cnnlab/calibrate_head.py --dir cnnlab/emnist --tags tiny-d16-qat4,base-qat4 --file .q4.bin
# thresholds (the 5% / 20% quantiles of the first stage's margins, nested) and every number:
node tuning/emnist-cascade.cjs --skip-legacy
# runtime + kernels, then the option directories
node scripts/build-lite.mjs && node scripts/build-cnn-options.mjs
```

The kernel (`cnn-web.js` + `.wasm`) is `cnnlab/cnn.cpp` built with
`em++ -O3 -msimd128 --closure 1 -s EXPORT_ES6=1 -s ENVIRONMENT=web,worker
-s FILESYSTEM=0 -s ASSERTIONS=0 -s MODULARIZE -s ALLOW_MEMORY_GROWTH ...`
(the exact line is in the round above); `--headNorm` is what makes a head
kernel-servable, `--export-bits 4` writes the 4-bit file the runtime expands
in memory. Retraining with another seed moves each number by about ±0.3.

### Could a user edit the bank and build one of these in the browser?

Measured (`tuning/head-probe.cjs`), not guessed. The backbone stays as
shipped; the kernel embeds the user's images in the browser (0.06 ms each for
tiny, 0.85 for base); a new softmax head is fitted on the frozen embedding by
multinomial logistic regression in JavaScript (300 steps: 0.1–2.5 s for 26
classes × 100 images); the zip is assembled client-side from the static
files plus the generated `head.bin` and `config.js`, exactly as the matcher
builder already does. What that path is worth, on 100 held-out EMNIST images
per class:

| what the user does | tiny 16-d | base QAT-4 | verdict |
|---|---|---|---|
| shipped head (reference) | 96.15% | 98.88% | |
| **choose a subset** of letters (10 of 26): slice the shipped head | 97.20% | 99.70% | exact, instant, better than the full head — no training at all |
| **their own images**, refit the head from 10 / 30 / 100 per letter | 95.65 / 95.96 / 96.00% | 98.58 / 98.58 / 98.65% | −0.2 to −0.5 vs shipped; 10 per letter is enough |
| **new characters** the backbone never saw (26 letters + 10 digits), 30 per class | letters 90.0%, digits 73.1% | letters 93.4%, digits 78.0% | the frozen embedding does not separate what it was not trained on |

So: **yes for choosing characters and for adapting to a hand** — subsetting
is head slicing, and a user's own samples refit a head in seconds at a
fraction of a point; the cascade's threshold is re-derived from the user's
own margins with the same quantile rule, or kept. **Not yet for adding
characters**: head-only training on top of an A–Z backbone reads new classes
at 73–78% (and O/0, I/1, S/5, Z/2 are also genuinely ambiguous), and
fine-tuning the backbone in the browser is a training loop this repo does not
have. The way to make "add characters" real is to ship a backbone trained on
a superset (EMNIST byclass has digits and lowercase too — 62 classes; the
matcher's symbol set could be rasterised in) and let the builder slice to any
subset of it; that is one `caps.py` run per backbone, the same pipeline. The
builder page itself — pick an option, tick characters, draw or upload
samples, fit, see held-out accuracy on the user's own samples, download —
reuses `cnnlab/cnnjs.mjs`'s kernel path for embeddings and the drawing pad
already in the runtime; the pieces exist, the page does not yet.

## The public site: what millirec offers now (Sep 8 2026)

Rob asked for the copy to be cleaned up so millirec offers two things — the
widgets and character recognition — mentions jatijm, and says that the page
cleaner and the sentence recognizer are not available yet.

- `server/public/index.html`: rewritten around **Widgets** and **Character
  recognition**. The character tile carries the three-option table (accurate /
  fast / small) with `download` links to
  `/templates/char-cnn/options/<name>.zip` and `try` links to each option's
  `index.html`, plus the builder for your own symbols. jatijm has its own tile
  ("sentence recognition in your own handwriting lives there, and is not
  offered from this site yet"), and a "Not available yet" tile names the page
  cleaner and the word/sentence recognizers. The enroll/penlive links are gone
  from the nav (both pages are still served — they belong to the sentence
  product).
- `server/public/help.html`: rewritten — Quick start, Widgets (the embed
  snippet: `data-millirec="reactions|ratings|reactions-count|rating-average"`,
  `data-widget`, `data-target`), Capital letters ready-made (the table, the
  `MillirecCharCnn.create()` / `recognize()` / `.stage` snippet, kernel vs
  plain-JS notes, the small option having no pad), Your own symbols (the
  builder, ~80 KB), jatijm, Not available yet, Your data, Devices,
  Troubleshooting, How it works.
- `server/public/builder/index.html`: the page-cleaner download button and
  its hint are `gated` like the word/sentence/split products (shown only with
  `?all=1`); the "coming later" note and the character hint point at the
  ready-made recognizers for plain capitals.
- `scripts/build-cnn-options.mjs` now also writes `options/<name>.zip`
  (inline store+deflate zip writer; round-trip verified with `unzip` + `cmp`):
  accurate 41.5 KB, fast 49.6 KB, small 11.2 KB.
- `server/README.md`'s page list describes the new offering.

Same day, Rob's layout notes on the home page: seams between cards are 6 px
on a darker ground (`--well`, page-local token), cards are square (the
`--radius` override is page-local so the shared bento is untouched), the
footer is gone, the Widgets tile embeds the REAL widget script
(`/embed/millirec-widget.js`, `data-target="millirec-home-demo"` — the same
target the widget page's demo counts into) and the Character tile carries a
live pad running the accurate option: its `config.js` and runtime are loaded
from `/templates/char-cnn/options/accurate/`, because the runtime resolves
model files relative to its own script URL. The widgets tile spans two rows so
both widgets show without scrolling the tile.

Later the same day: the nav is **Widgets · Character recognition · Help** on
every page, with Character recognition pointing at `/builder/` (the "Library
builder" link is gone). The builder wears the home page's skin — it links
`millirec.css`, aliases its old tokens (`--accent/--ink/--muted/--line`) onto
the shared ones, stacks square cards on the darker `--well` ground with 6 px
seams, and carries the brandbar. Its intro names it "Character recognition:
build your own library", the lone product button is hidden while only
characters are offered (it returns with `?all=1` or a saved library naming a
gated product), and the section heading plus the "coming later" note mention
the future libraries.

Then the rest of the public site took the same skin: `widget.html` is a
12-column card grid (intro c4 + live demo c8 with both widgets in a row, then
the embed builder c8 + a sticky live preview c4), the builder's sections sit
on the same grid (intro c5 + library type c7, classes c12, test c6 + save c6),
`help.html` got the brandbar and kept its own reading style, and the home
page lost the "Your data" and "Measured, not guessed" tiles (widgets c6 r2,
jatijm c6, not-yet c6 fill the bottom rows).

**Launch pass (Sep 8, afternoon).** Phone widths stack every page into one
column (checked at 390 px through same-origin iframes — the Chrome harness
cannot resize a maximised window); a public-mode server (`MILLIREC_PUBLIC=1`
on a spare port) serves every asset the four pages and the option zips need
and 404s the labs and `/app/`; the builder's default symbol set, the widget
page's three tabs and the option example pages all work; every gate in `npm
test` passes. The one real defect class found was stylus/touch capture, and
it lived in ONE file — `widget/canvas.js` is the drawing surface for the
widget, every char pad and the builder, and none of `pensurface.mjs`'s
iPadOS fixes had ever reached it (see CLAUDE.md for the list). The help page
now names the Character recognition page, the home pad and phones; all four
pages carry description + Open Graph meta.

Later that day: `terms.html` and `privacy.html` (help's skin, in every nav
and in `PUBLIC_PAGES`; operator name, jurisdiction and contact email are
`[placeholders]` for Rob to fill — the privacy page lists exactly what the
server stores: vote + voter hash (sha256 of a browser token and the IP,
truncated), the optional drawing thumbnail when "show visitors' drawings" is
on, widget/library config + samples + edit token, donated pen samples, server
logs). The builder's and widget page's sample thumbnails drew a training
sample as ONE polyline, so a multi-stroke glyph showed its pen-up jump as a
line: a resampled sample has uniform steps, so a step over 2.5x the median is
the jump and the pen is lifted there. Display only — the recognizer never saw
a segment along the jump (arc-length resampling gives pen-ups zero length),
though the ONE point after each pen-up carries the jump's direction as its
tangent (`orientedPointsFromPolyline`), 1 of 50 points per stroke boundary,
in templates and queries alike; unmeasured, and fixing it means moving the
matcher's golden.

The home pad now runs all THREE shipped options on every drawing and shows
each one's top-3 and time (one recognition in that browser, drawing raster
included — which is why accurate and fast tie at ~0.5 ms on a desktop). One
runtime does it: the accurate option's `millirec-char-cnn.min.js` is loaded
from its folder and `MillirecCharCnn.create(cfg)` is called twice more with
the fast and small `config.js` objects (fetched and parsed from the files in
each zip) plus `assetBase`, with `kernel` forced to null for the small option
so it runs the plain-JS path its zip ships. Every stage is warmed twice
before the first drawing so the times are steady state.

(The option was called "balanced" until Sep 8 2026; it is "accurate" everywhere now — folder, zip, page copy and this doc's earlier sections, which were rewritten rather than left inconsistent.)

Verified in the browser: every link on the landing resolves (the three zips
serve as `application/zip` at the sizes above), the accurate example page
boots the recognizer, and the builder shows only the character library
without `?all=1`.

## The page

`/sizelab.html` (dev server) reads `sizelab-data.json`: a scatter of held-out
top-1 against bundle size (gzipped or raw; lite or full runtime; or against ms
per character), a Pareto step line, filters by strategy and point count, the
full table, and for the selected version its per-class template counts,
confusion pairs and **every error with the query's ink drawn** (truth, what
it read as, the top-3 with the stroke softmax). The live pad loads the
selected version's exact templates — the JSON carries each cell's delta sample
at every point count — through `millirec-char-lite.min.js` against either
wasm, so a row can be tried by hand.

## What this does not say

- One writer, drill letters. Prose letters are connected and hurried
  (`docs/pen.md` records the drill-vs-prose gap on the page path); another
  hand will read worse than these numbers, and a per-hand
  `medoid-4`-style pick from that hand's own drills is the remedy
  (`docs/personalize.md`).
- Photo input was not measured here. The char library derives image
  templates from the same stroke samples (`IMAGE_TRAIN_VARIANTS`), so the
  template selection carries over, but the image path's accuracy at 20–25
  points is a separate question — `tuning/points-study.csv` puts the image
  knee at 50.
- Case: capitals only. Adding a–z brings the shape-only c/C, o/O, s/S pairs
  that only baseline geometry resolves (`docs/quickstart-char.md`).
