Skip to content

Dictation: the rules that decide which spoken words to clean up, matching iOS word for word (pure and tested; nothing runs them yet) - #2937

Merged
kitlangton merged 1 commit into
devfrom
cleanup-core-rust
Nov 27, 2026
Merged

kitlangton merged 1 commit into
devfrom
cleanup-core-rust

Conversation

@kitlangton

Copy link
Copy Markdown
Collaborator

Dictation gets the rules for cleaning up what was said (ums, repeats, false starts, spoken corrections), as pure Rust that matches the iOS app word for word.
Nothing runs it yet: no model, no setting, no change to what Hex pastes. This is the part that decides which words may go and writes what is left, so the next step only has to add the model.

💡 Why
The iOS app already cleans up dictation with a small tagger and a guard that keeps names, numbers and content words. Desktop needs the same decisions, and they have to stay the same on both. They are also the part worth testing hardest, and they need no model to test.

🆕 What is here (all in src/dictation/cleanup/)

  • The transcript is split into words once and never changed. A proposer says "I would remove these words, this sure". The guard admits or refuses each word and says why. The cleaned text is always written from the words as heard plus the admitted edits.
  • No edit carries text, so cleanup can drop a word and never write one.
  • The guard and the renderer are ports of the iOS Swift, and the tokenizer matches Hugging Face's ids.
  • On desktop the guard keeps four more things than iOS does: a content word said three times in a row ("No, no, no"), a filler that is being talked about ("Um is a filler word, and so is uh."), a negation inside a false start, and the whole transcript when the edits would leave no word. Each only ever keeps more, and the iOS behaviour stays available as its own policy so the two can be compared exactly.
- each stage rewrites the text in place; a guard compares two finished texts
+ words   = split(transcript)                 // kept as heard
+ plan    = guard.admit(words, proposals)     // each word: admitted as filler/repeat/false start/correction, or refused with a reason
+ text    = render(words, plan)               // an empty plan gives the transcript back exactly

🚦 How it ships: it doesn't yet. The module is unused outside its tests, and the build expects that.

📊 Proof

Checked against Cases Match
Hugging Face tokenizer ids (iOS fixture) 1,891 words 1,891 ✅
JavaScript reference renderer (iOS fixture) 670 670 ✅
Hand-written sentences, model labels rebuilt (iOS fixture) 137 sentences, 1,128 words 137 ✅
What the iOS Swift guard decides, and what iOS then rebuilds 726 726 ✅
Hand-written sentences through guard and renderer, against the ideal answer 137 129, the same 129 as iOS, under both policies

The fourth row is new: the reference pipeline has no guard, so fixtures/guard_reference.swift compiles the real iOS guard and writes its decisions for the 137 sentences at both recorded probability sets, for seeded random markings, and for 45 sentences picked to reach every rule.

Seeded property tests: rendering deletions never adds a word (4,000 random plans, including emoji, ellipses and letters whose capital is two letters); nothing to delete gives the transcript back byte for byte; the guard removes only words still proposed above the threshold; undoing one edit puts back its words and no others; the desktop policy never removes a word iOS keeps.

39 tests, all new.

👀 Read: guard.rs, the Policy struct and its four desktop switches, since those are the only rules that are not a port. Two things to know: a word said only twice ("Never, ever, ever") is still cut to one, and taking a proposal away can change what happens to its neighbours (the guard judges runs of words), so the property proved is "only proposed words go", not "fewer proposals means fewer deletions". nix/package.nix gains four lines so the Nix check can read the iOS fixtures. The rest is routine.

Step 3 of the dictation cleanup plan · no user reports · the guard reference is regenerated with the two commands at the top of guard_reference.swift whenever the iOS guard changes

Checks run
  • python3 scripts/code-shape.py --check: passes
  • cargo clippy --locked --bin hex -- -D warnings: clean
  • scripts/check dictation::cleanup: 39 passed
  • scripts/check (fmt, code-shape, Nix pins, clippy on all targets, every test): 4,027 run, 4,022 passed. The 5 that failed are outside this change (audio effect holds, local API timestamps and processing, onboarding motion, router timing), failed on timing while the machine was busy, and all 5 pass when rerun on their own.

…hing iOS word for word (pure and tested; nothing runs them yet)
@kitlangton
kitlangton merged commit a0f0a85 into dev Nov 27, 2026
4 checks passed
@kitlangton
kitlangton deleted the cleanup-core-rust branch November 27, 2026 07:36
kitlangton added a commit that referenced this pull request Nov 27, 2026
A new Lab, off by default, takes ums, repeats, false starts, and spoken
corrections out of English dictations on a Mac with the cleanup tagger the
iPhone app ships. The model can only remove words that were heard, and the
guard from #2937 refuses any removal that is not a known disfluency.

- The stage runs after the corrections and before the Apple Intelligence
  pass or the mode's rewrite, never for another language, the Verbatim
  style, numbers alone, or typed text.
- The 26 MB model downloads through Hex's own HTTPS the first time a
  dictation starts with the Lab on, and is unpacked only when its size and
  SHA-256 match the pin, by a zip reader that refuses paths outside the
  package.
- Core ML runs it on the CPU, one warm copy on its own thread, with a
  150 ms budget. A missing, late, or failing model pastes the words as
  heard and History says why.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant