hex/android/benchmark/typing/replay.sh
Ryan Vogel f4bd1c6ca7
Android typing: real-word lists for Spanish, German, Bokmål, French and Italian (#2271)
* Android typing: your own word gets a strip slot after two letters

With "Zorbex" in Android's personal dictionary, typing "zor" showed
"zor" | or | sir (checked live by the keyboard helper): the fix and the
decoder's runner-up filled both slots before your own completions came.
strip() now adds your likeliest own completion right after the fix (and
English's suggest-only contraction) once two letters are typed, so "zor"
shows "zor" | or | Zorbex. One-letter words and the rest of your
completions keep their place after the dictionary's readings.

Verified: testDebugUnitTest passes, with the case ("zo", "zor" typed by
taps beside a fix) added to NeverSuggestTest's personal-words test.

* Android typing: real-word lists for Spanish, German, Bokmal, French, Italian

iOS asks Apple's spelling dictionary whether a spelling outside its model
is a real word; Android had that only for English (SCOWL en.valid). Rare
words and names were corrected or split ("cochecito" -> "coche cito",
"vanesa" -> "van es a", "caminad" -> "caminado", "maktspråk" -> "makt
språk").

Lists (build-valid-words.py, now with a language argument):
- es, de, fr, it: every spelling the Google Books v3 1-grams (CC BY 3.0,
  1980-2019, the counts build-capitals.py caches; German's counted the
  same way) use at least 3,000 times (German 10,000), outside the model.
- nb: Norsk ordbank bokmal 2005 standard full forms (2022-02-01 release,
  CC BY 4.0) outside the model that the NB N-gram 2026 books (CC0) use at
  least 1,000 times.
- Left out: two model words run together whose pair is ten times as
  common, French/Italian elisions without their apostrophe ("cest"), and
  model words with an accent changed or left out ("volvere", "brulant").
- Each line is word<TAB>cost (eighths of a nat from the count).
  en.valid is unchanged (no cost column).
Sizes, stored uncompressed: es 1.29 MB, de 2.14, nb 0.84, fr 1.45, it
1.11; 6.83 MB together.

Decoder: a listed word costs what its count says instead of 22 nats; a
one-word fix still needs only the 2-nat margin, splitting it into words
needs a known word's 7, and the missed-space fallback skips it. A list
without costs keeps the old flat known-word reading (15 nats, 7-nat
margin); a flat reading for these lists was measured and rejected
(Spanish 1,058 -> 1,227 errors). validLiteral now compares UTF-8 bytes;
TypingModel loads <lang>.valid for any language; replay.sh pushes them;
the gradle verify list and SHA256SUMS name them; credits.txt credits
them. Replay.java gains a memory mode (every language kept loaded in one
process, resident memory before and after).

Cut-offs were chosen on both rare words kept and typos wrongly kept, not
on word errors alone (README has the sweep).

Verified on the Studio (API 35 emulator, installed debug APK, 2,000
held-out sentences each), word errors: English 707 (unchanged), Spanish
1,058 -> 1,033, German 729 -> 714, Bokmal 631 -> 627, French 939 -> 935,
Italian 763 -> 753. Rare words typed exactly and kept: es 228 -> 242 of
262, de 83 -> 94 of 107, nb 35 -> 39 of 104, fr 201 -> 201 of 211, it
82 -> 89 of 99; typos wrongly kept: 3, 3, 1, 0, 0. Latency unchanged in
an A/B on the API 31 emulator. testDebugUnitTest: 54 tests pass; the new
NeverSuggestTest case fails without the lists (checked against a copy of
the models without them).
2026-11-21 17:27:04 -05:00

28 lines
1.6 KiB
Shell
Executable file

#!/bin/sh
# Run in the Android project on the Studio. The debug APK is already installed.
set -eu
: "${ANDROID_HOME:?}" "${JAVA_HOME:?}" "${T:?Studio phase scratch}" "${ANDROID_SERIAL:?}"
cd "$(dirname "$0")/../.."
lib="$ANDROID_HOME/platforms/android-35/android.jar"
bt="$ANDROID_HOME/build-tools/35.0.0"
work="$T/replay"; dev=/data/local/tmp/hex4
mkdir -p "$work/classes"; adb shell mkdir -p "$dev"
"$JAVA_HOME/bin/javac" --release 8 -cp "$lib:app/build/tmp/kotlin-classes/debug" -d "$work/classes" benchmark/typing/Replay.java
"$JAVA_HOME/bin/jar" cf "$work/replay-classes.jar" -C "$work/classes" .
"$bt/d8" --min-api 31 --lib "$lib" --output "$work/replay-dex.jar" "$work/replay-classes.jar"
adb push "$work/replay-dex.jar" "$dev/replay.jar" >/dev/null
adb shell chmod 444 "$dev/replay.jar"
apk=$(adb shell pm path ly.anoma.hex | tr -d '\r' | sed 's/^package://')
adb push app/src/main/assets/typing/never-suggest.tsv "$dev/never-suggest.tsv" >/dev/null
mkdir -p "$T/outputs"
for lang in en es de nb fr it; do
[ -f "$T/bench/$lang.jsonl" ] || continue
adb push "app/src/main/assets/typing/$lang.hextm" "$dev/$lang.hextm" >/dev/null
for side in capitals valid; do
adb shell rm -f "$dev/$lang.$side"
[ ! -f "app/src/main/assets/typing/$lang.$side" ] || adb push "app/src/main/assets/typing/$lang.$side" "$dev/$lang.$side" >/dev/null
done
adb push "$T/bench/$lang.jsonl" "$dev/$lang.jsonl" >/dev/null
adb shell "CLASSPATH=$dev/replay.jar:$apk app_process /system/bin local.hex.bench.Replay $dev/$lang.hextm $dev/$lang.jsonl $lang $dev/$lang.out"
adb pull "$dev/$lang.out" "$T/outputs/$lang.tsv" >/dev/null
done