mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
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.
198 lines
8.5 KiB
Swift
198 lines
8.5 KiB
Swift
import SwiftUI
|
|
|
|
/// Unfinished features, off until turned on here. They live in the App Group so the
|
|
/// keyboard reads them too.
|
|
struct ExperimentsCard: View {
|
|
@State private var fullKeyboard = FullKeyboardSettings().isEnabled
|
|
@State private var cleanupTagger = CleanupTaggerSettings().isEnabled
|
|
@State private var appleIntelligenceCleanup = AppleIntelligenceCleanupSettings().isEnabled
|
|
@State private var customVocabulary = CustomVocabularySettings().isEnabled
|
|
@State private var cleanupAvailability = AppleIntelligenceCleanupAvailability.current
|
|
@State private var autocorrect = FullKeyboardSettings().autocorrect
|
|
@State private var learnTyping = TypingJournalSettings().isEnabled
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text("Experiments")
|
|
.font(.system(size: 13, weight: .medium))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
.padding(.leading, 16)
|
|
|
|
VStack(spacing: 0) {
|
|
Toggle(isOn: $fullKeyboard) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("Full keyboard")
|
|
.font(.system(size: 15, weight: .regular))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
Text("Type with Hex, with a Hex key to dictate")
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
}
|
|
}
|
|
.tint(HexTheme.success)
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 10)
|
|
.onChange(of: fullKeyboard) { _, enabled in
|
|
FullKeyboardSettings().isEnabled = enabled
|
|
}
|
|
|
|
if fullKeyboard {
|
|
Divider()
|
|
.overlay(HexTheme.borderWeak)
|
|
.padding(.leading, 16)
|
|
|
|
Toggle(isOn: $autocorrect) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("Autocorrect")
|
|
.font(.system(size: 15, weight: .regular))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
Text("Fix contractions, shortcuts, and one-edit typos on space")
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
}
|
|
}
|
|
.tint(HexTheme.success)
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 10)
|
|
.onChange(of: autocorrect) { _, enabled in
|
|
FullKeyboardSettings().autocorrect = enabled
|
|
}
|
|
}
|
|
|
|
Divider()
|
|
.overlay(HexTheme.borderWeak)
|
|
.padding(.leading, 16)
|
|
|
|
// Not only for the full keyboard: it also learns from dictations the
|
|
// dictation bar inserts.
|
|
Toggle(isOn: $learnTyping) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("Learn how I type")
|
|
.font(.system(size: 15, weight: .regular))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
Text("Keeps where you tap and the words you fix, typed or dictated, on this iPhone, never what you write")
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
}
|
|
}
|
|
.tint(HexTheme.success)
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 10)
|
|
.onChange(of: learnTyping) { _, enabled in
|
|
TypingJournalSettings().isEnabled = enabled
|
|
}
|
|
|
|
if learnTyping {
|
|
TypingInsightsView()
|
|
.padding(.horizontal, 16)
|
|
.padding(.bottom, 12)
|
|
}
|
|
}
|
|
.background(
|
|
HexTheme.bgBase,
|
|
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
|
|
)
|
|
.onChange(of: fullKeyboard) { _, enabled in
|
|
FullKeyboardSettings().isEnabled = enabled
|
|
}
|
|
|
|
Toggle(isOn: $cleanupTagger) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("Clean up what I say")
|
|
.font(.system(size: 15, weight: .regular))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
Text("Removes ums, repeats and things you corrected (3pm, actually 4pm), on this iPhone")
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
}
|
|
}
|
|
.tint(HexTheme.success)
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 10)
|
|
.background(
|
|
HexTheme.bgBase,
|
|
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
|
|
)
|
|
.onChange(of: cleanupTagger) { _, enabled in
|
|
CleanupTaggerSettings().isEnabled = enabled
|
|
}
|
|
|
|
Toggle(isOn: $appleIntelligenceCleanup) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("Clean up with Apple Intelligence")
|
|
.font(.system(size: 15, weight: .regular))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
Text("Fix misheard words and spoken corrections on device")
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
if let reason = cleanupAvailability.reason {
|
|
Text(reason)
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
}
|
|
}
|
|
}
|
|
.tint(HexTheme.success)
|
|
.disabled(!cleanupAvailability.isAvailable)
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 10)
|
|
.background(
|
|
HexTheme.bgBase,
|
|
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
|
|
)
|
|
.onChange(of: appleIntelligenceCleanup) { _, enabled in
|
|
AppleIntelligenceCleanupSettings().isEnabled = enabled
|
|
}
|
|
|
|
Toggle(isOn: $customVocabulary) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("Custom vocabulary")
|
|
.font(.system(size: 15, weight: .regular))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
Text("Spell names and terms your way")
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
}
|
|
}
|
|
.tint(HexTheme.success)
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 10)
|
|
.background(
|
|
HexTheme.bgBase,
|
|
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
|
|
)
|
|
.onChange(of: customVocabulary) { _, enabled in
|
|
CustomVocabularySettings().isEnabled = enabled
|
|
}
|
|
|
|
TranslateDictationRow()
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 10)
|
|
.background(
|
|
HexTheme.bgBase,
|
|
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
|
|
)
|
|
|
|
if customVocabulary {
|
|
CustomVocabularyEditor()
|
|
.padding(12)
|
|
.background(
|
|
HexTheme.bgBase,
|
|
in: RoundedRectangle(
|
|
cornerRadius: HexTheme.cardRadius,
|
|
style: .continuous
|
|
)
|
|
)
|
|
}
|
|
}
|
|
.onAppear {
|
|
fullKeyboard = FullKeyboardSettings().isEnabled
|
|
cleanupTagger = CleanupTaggerSettings().isEnabled
|
|
appleIntelligenceCleanup = AppleIntelligenceCleanupSettings().isEnabled
|
|
customVocabulary = CustomVocabularySettings().isEnabled
|
|
cleanupAvailability = AppleIntelligenceCleanupAvailability.current
|
|
autocorrect = FullKeyboardSettings().autocorrect
|
|
learnTyping = TypingJournalSettings().isEnabled
|
|
}
|
|
}
|
|
}
|