hex/ios/HEXShared/FullKeyboard
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ryan Vogel 3302fb4c0b
iOS: Adaptive touch, personal key centres learned on device (Experiment, off by default) (#2146)
* iOS keyboard: Adaptive touch learns personal key centres for the decoder (Experiments, off)

Adds Adaptive touch, stages 1 and 2 of the adaptive-touch design: the keyboard learns
where you land on each physical letter key, on this device, and Spatial autocorrect's
decoder (TypingDecoder.Keys) and the suggestion strip read your taps with those
personal centres. Hit rectangles, keycaps, key(at:) and Swipe typing are unchanged.

- AdaptiveTouch.swift: fixed-size sums (4 rotating bins of 200 labelled taps) per
  physical key and context (letters, posture, orientation, split, Hex key side,
  width bin, plus one of two grip regimes); offsets in keycaps, hierarchically
  shrunk (key 20, row 50, keyboard 40), bounded to 0.3 keycap, 0.05 per promotion,
  fixed sigma. The decoder reads a context only after 400 labelled taps over 3
  sessions, while the profile fits recent taps better than the stock centres; once it
  fits worse it falls back to stock at once and labels go to the other regime (a
  returning grip is taken back). The model serializes to 23,588 bytes: a protected
  file in the keyboard's own container, excluded from backup, never in the App
  Group, written off the main thread; without Full Access, memory only. Reset
  generation in the App Group drops RAM and file, and stale writes can't resurrect.
- AdaptiveTouchLabels.swift: RAM-only spans. A tap teaches only with evidence of
  intent, and only once the next word shows its word stood: a word left as typed
  (only letters the key under the finger typed), a same-length picked suggestion,
  a word kept over an autocorrection (undo or tapping it), and an erased letter
  retyped as a neighbour. Never autocorrections left in place, swipes, slides,
  strip touches, accent picks, or secure, code, email, URL or no-autocorrect fields.
- No new automatic rewrites: AutocorrectEngine.decoderStockKeys; space applies a
  personal reading only if the stock centres also clear it by the margin
  (TypingDecoder.replaces), else the stock decision. Experiment on replaces Learn how
  I type's per-letter offsets for decoding (its word-level learning stays). Off, the
  engine has no AdaptiveTouch and behaves exactly as before.
- Hooks: FullKeyboardEngine (touch-down point, letter commit, delete, undo, word
  ends, picks, swipes, cursor, field), FullKeyboardView.syncSettings, the keyboard
  saving on hide. KeyboardTextTarget gains isSecureTextEntry.

Verified: xcodebuild test on an iPhone 17 simulator (iOS 27.2), 440 tests, 0
failures (1 skipped, existing); new cases in FullKeyboardEngineTests and
AutocorrectEngineTests cover label admission, excluded fields and swipes, no
hit-rectangle change, contexts, grip fallback, evidence floor, untrained equals off,
the file cap, backup exclusion, damage and reset, and the no-new-rewrite guard.

* iOS: Settings › Experiments › Adaptive touch, with its status and Reset touch learning

The switch (off by default, App Group key experiments.adaptiveTouch) reads "Learns
where you land on the keys on this device. Stores averages, not what you type." While
on, a status line says Session only (Full Access not confirmed: the keyboard keeps its
averages in memory until it closes), Learning: n of 400 taps, or Active, from the
counts the keyboard reports (adaptiveTouch.summary.*); and Reset touch learning,
after a confirmation, bumps the reset generation every keyboard honours. Delete what
Hex learned (Typing insights) resets it too. Strings have zh-Hans. The
settings-experiments-on fixture shows it on, partway through learning.

Verified: built and tested with the previous commit (440 tests, 0 failures).

* iOS keyboard: Adaptive touch's guard follows the Experiment-off decoder, and its grip check reads each axis

Three refinements found while replaying the public benchmark:

- No new automatic rewrites now means none the keyboard wouldn't make with the
  Experiment off: AutocorrectEngine.decoderStockKeys becomes decoderBaselineKeys,
  the centres Spatial autocorrect reads without Adaptive touch (stock, or moved by
  Learn how I type's per-letter offsets). Those offsets still never move the
  centres the decoder reads while the Experiment is on (no stacking), so journal
  users keep its correction authority as the ceiling. Before, the baseline was
  always the stock centres, which let a journal user's rewrites change on enabling.
- The fit monitor keeps separate x and y log-likelihood gains. A grip that shifts
  taps sideways while the learned up/down offsets still fit used to average out:
  in the right-to-left grip replay the profile flapped in and out ~80 times and kept
  breaking words. Now a profile falls back once either axis fits worse than the
  stock centres (-0.06 nats per tap over 32 labels) and is only taken back when
  neither axis misfits.
- TypingDecoder.replaces first scores the reading letter for letter (or with one
  untyped letter), an alignment the search also tries, and skips the one-word
  search when that already clears the margin: the guard runs on most letters.

Verified: xcodebuild test on the iPhone 17 simulator (iOS 27.2), 446 tests, 0
failures (1 skipped, existing), including a new case for the journal baseline.

* iOS keyboard: Adaptive touch switches grip profiles only once one had the evidence to be used

The public replay showed a false switch while learning the steady base typist: the
early, thin profile (368 taps) misfit one axis by noise and labels moved to a fresh
second profile, throwing that evidence away. Before the activation floor nothing
is in use, so a new grip now just mixes into what is learned; the per-axis
fallback and switching apply once the profile is eligible (400 taps, 3 sessions).

Also skips the accent comparison in TypingDecoder.replaces when it can't lower the
margin (it allocates), the guard's remaining per-letter cost on the simulator.

Adds AutocorrectEngineTests.testPersonalCentresKeepNamesYourWordsAndWordsTypedRight:
with every centre pushed to the bound, words typed right, lowercase names and days,
Contacts-style terms and shorthand come out exactly as with the Experiment off.

Verified: xcodebuild test on the iPhone 17 simulator (iOS 27.2), rebased on
d65f5f76: 452 tests, 0 failures (1 skipped, existing).

* iOS keyboard: test that Adaptive touch never joins words its own way

Rebased onto the autocorrect fixes (#2144). Their new automatic rewrites go
through finishWord, so Adaptive touch hooks in there: a word space or a closing
mark autocorrects teaches nothing, a revised word before it ("well" to "we'll")
teaches nothing either, and two words joined at the space bar's edge drop
everything pending. AutocorrectEngine.merge reads the centres the keyboard reads
without Adaptive touch, so personal centres never decide a join (folded into the
first two commits while resolving the rebase).

Adds AutocorrectEngineTests.testPersonalCentresNeverJoinWordsTheirOwnWay: with a
strong personal profile in use, "the deli" + a space at the bar's edge + "ate"
still becomes "the delicate", as with the Experiment off.

Verified: xcodebuild test on the iPhone 17 simulator (iOS 27.2) on 8c93f6f5: 461
tests, 0 failures (1 skipped, existing).

* iOS keyboard: Adaptive touch's guard takes the next reading the baseline clears, not a second search

When a personal reading doesn't clear the baseline margin, the guard used to run a
whole second decode with the baseline centres to find their own decision. On the
public benchmark that happened on ~5% of checked letters and cost ~0.13 ms each,
pushing the simulator's English per-letter p95 up to +0.1-0.16 ms. Now it takes the
next of the personal readings that the baseline centres also clear by the margin
(TypingDecoder.replaces, mostly without a search), or none: still never a rewrite
the keyboard wouldn't make with the Experiment off. Only a two-word reading, which
replaces can't score, still asks the baseline decode.

Verified: xcodebuild test on the iPhone 17 simulator (iOS 27.2) on 8c93f6f5: 461
tests, 0 failures (1 skipped, existing). Held-out benchmark on the same simulator,
profile learned on the 300 dev sentences: WER unchanged by this (EN 5.24% -> 5.16%,
ES 8.34% -> 8.26%); per-letter engine p95 against Experiment off, two runs each:
EN -0.09 / +0.02 ms, ES -0.01 / +0.04 ms; peak footprint -0.11 / +0.00 MB.

* iOS: README documents Adaptive touch and what verified it

Adds Settings › Experiments › Adaptive touch to the capabilities (what it learns
from, what it keeps and where, when the decoder uses it, the no-new-rewrite guard)
and to the Experiments page list, and a verification entry: the unit tests, the
held-out benchmark on the simulator (Experiment off and on without evidence match the
keyboard without it on all 2,000 items in English and Spanish; with a learned profile
EN 5.24% -> 5.16%, ES 8.34% -> 8.26% WER, none typed right broken), the grip-change
replay (38 broken words without the fallback, none with it), latency and footprint, and
what remains unverified without a physical iPhone.

Verified: the numbers are from this branch at 17af3357 on 8c93f6f5 (replay tables in
the experiment folder, not committed).
2026-11-21 06:13:04 +00:00
..
Emoji iOS: emoji panel memory, category taps, an eight-column Frequently used, and the system's look (#2142) 2026-11-21 04:31:34 +00:00
AccentPicker.swift iOS: emoji panel memory, category taps, an eight-column Frequently used, and the system's look (#2142) 2026-11-21 04:31:34 +00:00
AdaptiveTouch.swift iOS: Adaptive touch, personal key centres learned on device (Experiment, off by default) (#2146) 2026-11-21 06:13:04 +00:00
AdaptiveTouchLabels.swift iOS: Adaptive touch, personal key centres learned on device (Experiment, off by default) (#2146) 2026-11-21 06:13:04 +00:00
AutocorrectEngine.swift iOS: Adaptive touch, personal key centres learned on device (Experiment, off by default) (#2146) 2026-11-21 06:13:04 +00:00
DeleteWordSwipe.swift iOS: keep key haptics while dictating, and slide left on delete to delete words (#2080) 2026-11-20 17:55:51 +00:00
FullKeyboardEngine.swift iOS: Adaptive touch, personal key centres learned on device (Experiment, off by default) (#2146) 2026-11-21 06:13:04 +00:00
FullKeyboardPalette.swift iOS: the full keyboard's top bar matches the system keyboard (#2135) 2026-11-21 03:26:34 +00:00
FullKeyboardSettings.swift iOS: Emoji and Swipe typing are on by default, under Settings › Keyboard (#2129) 2026-11-21 02:41:15 +00:00
FullKeyboardView+Emoji.swift iOS: emoji panel memory, category taps, an eight-column Frequently used, and the system's look (#2142) 2026-11-21 04:31:34 +00:00
FullKeyboardView.swift iOS: Adaptive touch, personal key centres learned on device (Experiment, off by default) (#2146) 2026-11-21 06:13:04 +00:00
HexKeyGesture.swift iOS: the keyboard starts listening on touch-down, with its capture page ready when it opens (#2089) 2026-11-20 20:04:35 +00:00
HexKeyViews.swift iOS: emoji panel memory, category taps, an eight-column Frequently used, and the system's look (#2142) 2026-11-21 04:31:34 +00:00
KeyboardBackdropView.swift iOS: opaque keyboard panel so stale system layers can't show through, and a nil-safe field ID (#2139) 2026-11-21 03:45:47 +00:00
KeyboardClipboard.swift iOS: fewer paste prompts, and a translate switch in the keyboard (#2134) 2026-11-21 03:24:58 +00:00
KeyboardKeyPlaneView.swift iOS: Emoji and Swipe typing are on by default, under Settings › Keyboard (#2129) 2026-11-21 02:41:15 +00:00
KeyboardLanguage.swift iOS: Polish keyboard, diacritic autocorrect, and a bilingual partner fix (#2143) 2026-11-21 04:43:47 +00:00
KeyboardLayout.swift iOS: the full keyboard's top bar matches the system keyboard (#2135) 2026-11-21 03:26:34 +00:00
KeyboardStripView.swift iOS: the full keyboard's top bar matches the system keyboard (#2135) 2026-11-21 03:26:34 +00:00
never-suggest.tsv iOS: never suggest slurs, and swear words only when asked (#2093) 2026-11-20 20:17:31 +00:00
OffensiveWords.swift iOS: never suggest slurs, and swear words only when asked (#2093) 2026-11-20 20:17:31 +00:00
ShiftStateMachine.swift iOS: full keyboard experiment flag, key layout and shift model (#910) 2026-11-01 12:43:35 -08:00
SwipeDecoder.swift iOS: autocorrect splits merged words, fixes missing apostrophes and homophones, and corrects before punctuation (#2144) 2026-11-21 05:24:20 +00:00
SwipeTyping.swift iOS: autocorrect splits merged words, fixes missing apostrophes and homophones, and corrects before punctuation (#2144) 2026-11-21 05:24:20 +00:00
TypingDecoder.swift iOS: Adaptive touch, personal key centres learned on device (Experiment, off by default) (#2146) 2026-11-21 06:13:04 +00:00
TypingJournal.swift iOS: Delete what Hex learned also forgets the words autocorrect learned to keep (#2101) 2026-11-20 21:28:27 +00:00
TypingJournalLearning.swift ios: learn dictation and typing fixes from edits (Learn how I type) (#2022) 2026-11-20 01:04:58 +00:00