* ios: clean up what I say with Hex's on-device dictation tagger (experiment)
What changed
- Experiments › Clean up what I say (off by default, App Group key
experiments.cleanupTagger): Hex's trained cleanup tagger removes ums,
repeats, and the words a spoken correction replaces ("3pm, actually 4pm"),
on the iPhone, in in-keyboard dictation and in app dictation. It runs after
transcription and learned fixes (in the app also after custom vocabulary),
before Apple Intelligence cleanup, translation, and formatting, and never
for Verbatim. When both cleanups are on, Apple Intelligence now receives the
tagged text instead of the raw transcript; nothing else changes while the
experiment is off.
- Model: the BERT L-4/H-512 token classifier (ckpt-1200k-l4h512) converted to
an int8 Core ML ML Program (coremltools 9, fp16 compute, enumerated lengths
16/32/64/128 plus a length input that masks the padding; the output is
logit(DELETE) - logit(KEEP)), 28.5 MB, with its WordPiece vocabulary. Both
ship once, in HEXKeyboard.appex (HEXKeyboard/CleanupTagger/), and the app
loads them from its embedded keyboard extension. Core ML codegen is off for
the keyboard target.
- HEXShared: CleanupTokenizer (Hugging Face BertTokenizer: special tokens,
BertNormalizer, BertPreTokenizer, WordPiece, byte-exact vocabulary keys,
HF's Unicode 8.0 character classes), CleanupReconstruction (a port of
js/reconstruct.js with JavaScript's UTF-16 casing), and CleanupTagger
(chunks of whole words within 128 tokens, P(DELETE) > 0.98, one serial
queue, 150 ms budget). A timeout, an error, or a result with no words left
keeps the transcript. The model loads when a dictation starts recording with
the experiment on, stays loaded, and is freed on a memory warning. It runs
on the Neural Engine or the CPU, never the GPU.
- Call sites: one each in KeyboardLocalDictation (after DictationCorrections,
before translation) and DictationController (after VocabularySpelling,
before the Apple Intelligence pass). prepareIfEnabled runs at recording
start, in KeyboardViewController and in DictationController.startRecording.
Why
- In the simulator the first load took 0.15 s on the CPU and 0.8 s on the GPU
path, both over the 150 ms budget. So loading starts when recording starts,
and the GPU isn't used (it also added 30 MB of footprint, against 3 MB on the
CPU, which keeps the int8 weights memory-mapped).
- Threshold 0.98, not the exported 0.95: 1/45 false deletes on hand-written
clean sentences against 3/45, with the same self-correction accuracy.
Verified
- xcodebuild test on the iPhone 18 Pro simulator: 168 tests, 0 failures,
including the new CleanupTaggerTests and DictationControllerTests
testCleanupTaggerRunsAfterLearnedFixesAndSkipsVerbatim. After the fixtures
were rewritten one case per line (same content), CleanupTaggerTests and
DictationControllerTests passed again (28 tests).
- Parity on the 137 hand-written sentences at 0.98: labels match the fp32
checkpoint on all 1,128 words, and 136/137 outputs match the ONNX int8
pipeline. #120 ("The cat keeps trying to scratch that chair.") differs on
two words that ONNX keeps (P 0.9725/0.9794) and Core ML deletes (0.984).
The fp32 checkpoint also deletes them (0.9879/0.9853), so the difference
comes from ONNX's int8 activations. 128/137 outputs match the hand-written
targets. The tokenizer matches HF on 1,891 words, and reconstruction matches
reconstruct.js on 670 cases.
- Simulator, CPU path: load 140-161 ms, first sentence after load about 8 ms,
then 3.3 ms median and 7.5 ms p95 per sentence; phys_footprint +2.9 MB.
- The Release generic iOS build with CODE_SIGNING_ALLOWED=NO succeeds.
HEXKeyboard.appex is 30.2 MB (model 27.8 MB, vocabulary 0.2 MB).
- Not verified on a physical iPhone: Neural Engine load time, latency, and the
keyboard extension's footprint next to Apple Speech.
Note: this adds a 28.4 MB binary (weight.bin) to git; the repo has no LFS.
* Fetch the cleanup tagger's Core ML model at build time instead of committing it
The 27 MB mlpackage would have been ~30x the largest file in the repo, kept in history forever. It is now the ios-model-cleanup-tagger-1 release asset; ios/scripts/fetch-cleanup-model.sh downloads it, checks its SHA-256, and skips when the pinned copy is already in place. Xcode Cloud runs it in ci_post_clone.sh before xcodegen; the folder is gitignored.
Verified the fetched package is byte-identical to the one the tests ran against (diff -r), and a second run is a no-op.
16 KiB
Hex for iPhone
Status: Internal TestFlight app (HEXMobile), custom keyboard extension
(HEXKeyboard), and Live Activity + Control Center widget extension
(HEXWidgets). The containing app records a generation-scoped temporary WAV,
transcribes on-device with Apple Speech (SpeechTranscriber on iOS 26+) or
FluidAudio Parakeet V2 (iOS 18+), and removes each capture's file after
inference, cancellation, or failure. During a warm session the keyboard
extension sends commands and inserts completed text over the shared App Group
(group.anomaly.hex.mobile). Otherwise it dictates by itself (in-keyboard
dictation, iOS 26+): iOS refuses to record from a keyboard extension
directly, so it captures through getUserMedia in a hidden WKWebView
under Hex's microphone permission, writes a temporary WAV, and transcribes
it on-device with Apple Speech, downloading the speech assets on first use
(HEXKeyboard/KeyboardLocalDictation.swift). Audio never leaves the iPhone.
Capabilities
- One-tap keyboard dictation (
HEXKeyboard):- Setup: The keyboard needs Full Access to reach Hex through the App
Group. Without it, the keyboard shows the Settings path and an Open Hex
setup button (
hex-dictation://keyboard/setup). The app's setup card shows live status for the keyboard, Full Access, the microphone, and the speech model, and opens Hex's page in Settings. Full Access shows as on once the keyboard has run with it (keyboard.fullAccessSeenAt). - Opening Hex: SwiftUI
Link,openURL, andextensionContext.opendo nothing in a keyboard extension, so the keyboard opens Hex through theUIApplicationat the end of its responder chain (ContainingAppOpener). - Cold start (before iOS 26): Tapping Dictate opens the containing app
(
hex-dictation://keyboard/record?...) with a 10-second handoff window, starts recording, and opens the selected host app's URL scheme (messages://,slack://,claude://,chatgpt://,mobilenotes://,discord://,mail://,x-web-search://, etc.) using publicUIApplication.shared.open(_:). Because iOS keyboard extensions cannot inspect the host app's bundle ID without private APIs, you pick your usual return app once on the↩chip (or jump bar), and apps without a registered URL scheme fall back cleanly within ~1s to the bottom-edge swipe bar and quick-jump chips. Edit apps… in the app's return menu picks and orders the apps the keyboard tray and jump bar offer. - GPU Dot Scope (
HEXShared/DotScope.swift,DotScopeShader.metal): BothHEXMobileandHEXKeyboardrender Hex's desktop menu-bar braided oscilloscope (src/dot_scope.rs,src/rune_hud.wgsl) at native display refresh viaCAMetalLayer+CADisplayLink, pausing at 0% CPU/GPU once settled in idle. The keyboard extension mounts it only while a capture or transcription is active and shows a staticCanvasdot row at rest, so a fresh keyboard process builds no Metal device, pipeline, layer, display link, or idle pre-roll before its first frame; the app's docked keyboard preview keeps the live scope. The home-indicator swipe cue's pipeline is compiled on first use, which only the app shows. Lock Screen / Dynamic Island Live Activities render a matchingCanvasdot-matrix badge (HexDotMatrixBadge) because WidgetKit archives static view snapshots rather than hosting liveCAMetalLayers. Meter polling stays alive through a temporary non-recording state of the same capture; it resumes app levels and keyboard snapshots when the recorder is ready again. Capture completion, interruption, and Stop end polling. - Warm session (
Off,5m,15m,1h): Picking a duration on Keep mic warm starts anAVAudioEngineinput session immediately (default15m) so subsequent taps on Dictate record directly inside the keyboard with zero app switches; pickingOffor tapping the header timer ends it. - Styles:
Polished(sentence case + punctuation + filler trim),Casual(lowercase chat without trailing period),Notes(spoken"bullet"/"next line"markers), andVerbatim, with cursor-aware insertion spacing and repeating backspace. - Full keyboard Hex key (Experiments › Full keyboard): A tap, or a
still hold of 0.35 s, starts dictation: in a warm session, else inside
the keyboard (in-keyboard dictation, iOS 26+), else by opening Hex. Moving
more than 10 pt first opens the style and Return to menu; releasing over a row picks it, and releasing elsewhere leaves
the menu open for taps (
HexKeyGesture). VoiceOver activation dictates, and the Dictation styles action opens the menu. - Apple Intelligence cleanup (Experiments › Clean up with Apple
Intelligence, iOS 26+): Off by default. For every style but
Verbatim, one on-device FoundationModels pass before formatting fixes clearly misheard words and spoken self-corrections, within a 2 s budget. A timeout, error, empty or implausible output keeps the raw transcript, and the toggle is disabled with a reason when Apple Intelligence is unusable. - Clean up what I say (Experiments › Clean up what I say): Off by
default. For every style but
Verbatim, Hex's dictation cleanup tagger labels each spoken word KEEP or DELETE on the iPhone and drops ums, repeats, and the words a spoken correction replaces ("3pm, actually 4pm" becomes "4pm"); a word goes only above P(DELETE) 0.98.CleanupReconstruction, a port of the tagger'sreconstruct.js, then repairs the commas and capitals next to a deletion. It never adds, reorders, or changes words. It runs after transcription and learned fixes (in the app also after custom vocabulary), before Apple Intelligence cleanup, translation, and formatting, in in-keyboard dictation and in the app. The tagger is a BERT L-4/H-512 token classifier fine-tuned from Google's Apache-2.0bert_uncased_L-4_H-512_A-8on generated examples, shipped as an int8 Core ML model (28.5 MB) with its WordPiece vocabulary once, inHEXKeyboard.appex(HEXKeyboard/CleanupTagger/). The app loads it from there.CleanupTokenizermatches Hugging Face'sBertTokenizer, including its Unicode 8.0 character classes. The model loads on the Neural Engine or CPU when a dictation starts recording with the experiment on, stays loaded, and is freed on a memory warning. Cleanup gets 150 ms; a timeout, an error, or a result with no words left keeps the transcript as heard. - Custom vocabulary (Experiments › Custom vocabulary): Off by default. A local list of up to 100 names and phrases, applied to every engine. After transcription, matching words are rewritten to the listed spelling across case, spaces, tabs, a single hyphen, and possessive apostrophes, before cleanup and again after formatting, so a style cannot undo a spelling. The listed spelling is kept exactly, even at a sentence start (an all-lowercase term stays lowercase), and a term that spells its own boundaries ("iPhone 7", "X-ray") matches those boundaries exactly. A word that carries its own apostrophe only matches a term that has one, several transcript words are joined only when the term reads as a compound, and compound terms like "WeChat" can also match the plain phrase ("we chat"). On iOS 26 Apple Speech the list is also sent as a best-effort recognition hint; Parakeet's batch path gets no hint.
- Learn how I type (Experiments › Learn how I type): Off by default, and
shown whether or not the full keyboard is on. A private journal in the App
Group (
typing-journal.json) that never stores what you write: per-key tap offsets, and word-level pairs with counts and at most one word of context on each side. Only plain text fields that allow autocorrect count (TypingJournal.allows). Nothing leaves the iPhone.- Typing: words you erase and retype, autocorrect fixes you undo with one
backspace, suggestions you pick, and autocorrections you turn down by
tapping what you typed. A typo you fixed the same way twice (never a
completion, never fixed two ways) becomes a fix on space, only a suggestion
when what you typed is a real word; an autocorrection you turned down twice
never applies again (
TypingLearning, read byAutocorrectEngine). - Dictation: from the full keyboard and the dictation bar alike, the
keyboard remembers each dictation by the text around it
(
DictationEditTracker), finds it again after edits through Hex's keys and ontextDidChange, and diffs it word by word against what Hex inserted and the raw transcript the app or in-keyboard dictation sends with it (DictationEditInference.swift). It settles after 60 s, when the keyboard goes away or the field changes, on a Send return key, or when the host clears the field (a send). Each dictation gets an outcome (kept, edited, rewritten when more than half changed, undone, deleted, or redictated when deleted and dictated again within 20 s) and its pairs: substitutions, insertions, deletions, words cleanup dropped that you added back, and fillers Hex left that you deleted, each as heard, inserted, and final words. New writing before or after a dictation, changes that aren't plausibly the same words, edges the host's cut-short context can't show, and translated dictations teach nothing. - Applied: a substitution seen twice and never contradicted (you kept the heard words in a dictation you corrected, changed the fix back, or fixed the same words another way) is applied right after transcription, in in-keyboard dictation and in the app before custom vocabulary and cleanup, whole words only (never inside a longer, hyphenated, dotted, or slashed word) and following the original's case unless the fix has capitals. Its meant words join the Apple Speech hints after custom vocabulary's. Typing insights lists these fixes with a switch each and the share of dictations kept and edited; Delete what Hex learned erases everything, including what a running keyboard still holds.
- Typing: words you erase and retype, autocorrect fixes you undo with one
backspace, suggestions you pick, and autocorrections you turn down by
tapping what you typed. A typo you fixed the same way twice (never a
completion, never fixed two ways) becomes a fix on space, only a suggestion
when what you typed is a real word; an autocorrection you turned down twice
never applies again (
- Setup: The keyboard needs Full Access to reach Hex through the App
Group. Without it, the keyboard shows the Settings path and an Open Hex
setup button (
- Resilient capture & expiry contract (
DictationController):- Monotonic
jobGeneration, retainedtranscriptionTask, and unique per-capture WAV filenames ensure an expiring warm session never drops an already-accepted transcription (deliverable for 30s), while a stale winding-down inference can never overwrite a newer capture or delete its audio file. - Phone/FaceTime/Siri audio interruptions finalize captures
>= 300 msso spoken words are not lost, cancel shorter taps cleanly out ofListening, and resume warm keepalive when iOS signals.shouldResume. Always use iPhone microphone (on by default) records from the built-in microphone inplayAndRecordwithmixWithOthersand A2DP output, in the app and in in-keyboard dictation, so music in a car or headphones keeps playing and the route never drops into call audio. Turning it off allows Bluetooth HFP microphones, which pause other audio.
- Monotonic
- Action Button, Control Center, Back Tap & Live Activity:
DictateWithHexIntent(AudioRecordingIntent+LiveActivityIntent) andHexDictationControl(ControlWidget) start recording on first press with a Dynamic Island / Lock Screen Live Activity (StopandCancelbuttons) and transcribe + copy to the clipboard on second press.
Build & Test
Prerequisites: Xcode 26+ and XcodeGen 2.46.0+.
cd ios
scripts/fetch-cleanup-model.sh # the cleanup tagger's Core ML model, kept out of git
xcodegen generate
xcodebuild test -project HEXMobile.xcodeproj -scheme HEXMobile -destination "id=<SIM_UDID>"
The cleanup tagger's model (HEXKeyboard/CleanupTagger/HexCleanupTagger.mlpackage,
25 MB) is a GitHub release asset (ios-model-cleanup-tagger-1), not a git file.
fetch-cleanup-model.sh downloads it and checks its SHA-256; Xcode Cloud runs it
from ci_scripts/ci_post_clone.sh. A new model gets a new release tag and hash.
Simulator vs. Physical iPhone Proof Limits
- Verified in Simulator (
HEXMobileTests+--snap-statescenes): Compilation acrossHEXMobile,HEXKeyboard, andHEXWidgets; App Group command/snapshot framing; theDictationControllergeneration/expiry race and 30s post-close transcript delivery; 10s handoff window + URL-scheme auto-return fallback; interruption handling; meter recovery after injected startup and mid-capture recorder unavailability (including keyboard levels and heartbeat); deterministic style formatting; and UI layouts. - Requires a physical iPhone: Real
AVAudioSessionbackground keepalive survival across lock/app switches, live orange indicator behavior, on-deviceSpeechTranscriber/ Neural Engine Parakeet latency, URL-scheme return into installed third-party apps (Messages, Slack, Claude, ChatGPT), Dynamic Island Live Activity interaction, and hardware Action Button invocation. TransientAVAudioRecorder.isRecordingchanges during warm handoff or Bluetooth route changes have not been reproduced on hardware; the meter recovery tests inject that condition throughActiveAudioCapture. - Apple Speech hint: Custom vocabulary's contextual strings are best effort
and unverified on a physical iPhone. Apple documents contextual strings only
for
DictationTranscriber, Hex sets them onSpeechTranscriber, and Parakeet's batch path gets no hint. - Learn how I type: Dictation edit inference (span location, word diff,
outcomes, the learning threshold, and applying fixes) is covered by unit
tests only. How much
documentContextBeforeInputanddocumentContextAfterInputeach host app shows, and whether it callstextDidChangeafter the keyboard's own edits, varies by app and is unverified on a physical iPhone; when the context is cut short or missing, the dictation is settled on where it was last seen or not learned from. - Clean up what I say:
CleanupTaggerTestscheck, in the simulator (CPU only), the tokenizer against Hugging Face on 1,891 words, reconstruction againstreconstruct.json 670 cases, and the model on the 137 hand-written sentences at 0.98. Its labels match the fp32 checkpoint's on all 1,128 words, and 136 of 137 outputs match the ONNX int8 pipeline. The other sentence differs on two words within 0.01 of the threshold, which ONNX's int8 activations keep and the checkpoint deletes. In the simulator the model loads in about 150 ms, cleans a sentence in about 3 ms (p95 under 8 ms), and adds about 3 MB to the process footprint, because the CPU leaves the int8 weights memory-mapped from the bundle. The simulator's GPU path took 0.8 s to load and added 30 MB, so Hex doesn't use the GPU. Neural Engine load time, latency, and the keyboard extension's footprint next to Apple Speech are unmeasured on an iPhone;keyboard-capture-probe.logrecords the footprint around each in-keyboard dictation. - No iOS CI: Custom vocabulary is covered by unit tests only. No CI job
compiles or tests the iOS targets, so these checks run only in a local
xcodebuild test.
Internal TestFlight releases
Hex Mobile in App Store Connect
uses Anomaly's signing team. The GitHub Release Hex Mobile workflow checks
dev at noon and 6 p.m. Chicago time, or on manual dispatch, and cuts an
ios-beta-* prerelease when iOS inputs have changed. These tags are separate
from desktop releases. The marketing version stays fixed across beta builds.
The Xcode Cloud workflow needs a tag start condition with prefix ios-beta-,
container ios/HEXMobile.xcodeproj, shared scheme HEXMobile, an iOS Archive
action, and a TestFlight post-action for Hex Internal. Cloud owns the build
number. Verify the run's source tag and the processed build in that group.