mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-25 01:30:06 +08:00
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.
This commit is contained in:
@@ -919,9 +919,21 @@ final class AutocorrectEngine {
|
||||
|| properNoun(for: token) != nil
|
||||
let previous = Self.previousWord(before, token: token)
|
||||
var decision = decoder.decide(taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: keys)
|
||||
if let baseline = decoderBaselineKeys, let replacement = decision?.replacement,
|
||||
decoder.replaces(with: replacement, taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: baseline) != true {
|
||||
decision?.replacement = decoder.decide(taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: baseline)?.replacement
|
||||
if let baseline = decoderBaselineKeys, let replacement = decision?.replacement {
|
||||
func clears(_ reading: String) -> Bool? {
|
||||
decoder.replaces(with: reading, taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: baseline)
|
||||
}
|
||||
switch clears(replacement) {
|
||||
case true?:
|
||||
break
|
||||
case false?:
|
||||
// The next reading the baseline would also put in, if any: never a new rewrite,
|
||||
// and no second search on the letter.
|
||||
let readings = decision?.readings ?? []
|
||||
decision?.replacement = readings.lazy.map(\.text).first { $0 != replacement && clears($0) == true }
|
||||
case nil:
|
||||
decision?.replacement = decoder.decide(taps: taps, typed: lower, previous: previous, literalIsValid: valid, keys: baseline)?.replacement
|
||||
}
|
||||
}
|
||||
decoderCache = (before, taps, decision)
|
||||
return decision
|
||||
|
||||
Reference in New Issue
Block a user