English typing model: contractions as common as their words, and Hex's chat and tech words (#2408)

What changed: en.hextm (iOS and Android, one file) is rebuilt by build-typing-model.py from
the same Google Books shards and SCOWL, with two additions:
- Each contraction in the builder's CONTRACTIONS counts as often as its expansion's word pair
  ("do not") when that is commoner, and "i'm", "i'll", "i've", "i'd", "here's", "where's",
  "mustn't" and "needn't" are added in lowercase.
- en-extra-words.tsv (new, beside both copies of the builder): 166 chat and tech words written
  for Hex ("app", "lol", "csv"), each at its tier's cost (10, 12 or 13.5 nats); a word the
  books already have only gets commoner.
Both join the vocabulary before pairs are counted, so their pairs are counted too. en.valid and
en.capitals (Android) are rebuilt from the new model, and build-capitals.py holds Hex's own
words at 94% like SCOWL's lowercase words ("plz" and "okie" are capitalised in books, never by
the keys). SHA256SUMS and the benchmark and iOS READMEs follow.

Why: Google Books splits "don't" into "do" + "n't", so the model priced "don't" at 14.4 nats
and "it's" at 16.2, and lacked "i'm"; a rarer reading beat them. Recorded typing logs had
everyday words the model lacked ("app", "csv", "gpus"), and the next-letter odds moved
correct taps off them.

Reproduced: with the earlier rules the same counts rebuild the earlier en.hextm byte for byte
(14370569...4028), and the valid and capitals builders rebuild the earlier en.valid and
en.capitals from it. New en.hextm c23e9c54...df30: 86,247 words, 417,182 pairs, 3,599,995
bytes (inside the 3.6 MB budget).

Verified:
- iOS gate (scripts/typing-gate.py, SWIFT_DETERMINISTIC_HASHING=1): English 773 -> 734 word
  errors (5.57% -> 5.29%, 83.5% -> 84.4% fewer than raw taps), correct words changed 0.27% ->
  0.26%, critical 2/2, PASS. Spanish and German outputs identical.
- Android gate (quality-gate.py): English 718 -> 680 (5.18% -> 4.90%, 84.7% -> 85.5%), correct
  words changed 0.32% both, critical 2/2, PASS; es, de, fr, it, nb identical.
- Per letter on the iOS engine (held-out inputs, p50/p95): 0.189/2.18 -> 0.181/2.08 ms.
- Swipes, every word of the English held-out sentences through the key plane and SwipeTyping:
  92.38% -> 92.46% clean, 89.83% -> 89.89% with finger noise; one word lost in each ("weed"
  now "we'd"). Existing swipe tests unchanged and passing.
- A tester's recorded taps, single words: 37 -> 34 errors, correctly tapped words changed 12 -> 8.
- xcodebuild test (Studio, own simulator): 882 tests, 0 failures, 4 opt-in skips. Android
  testDebugUnitTest (66, incl. NeverSuggestTest on every shipped model): pass. code-shape.py: pass.
This commit is contained in:
Ryan Vogel
2026-11-22 13:40:28 -05:00
committed by GitHub
parent 130835701d
commit 3f35348581
12 changed files with 493 additions and 36 deletions
@@ -1,9 +1,9 @@
14370569c747a7efb5cd2f8e75b70d2899937c12e149671fe7a0929c5e0c4028 en.hextm
c23e9c546d620fa6d8d395b9dae72cb7825b39050fc1782b548b829729a6df30 en.hextm
02ffcac185eb832d766b300a7454ba069d0b26251469ea7cdc6eda36926ad5ad es.hextm
7854e9a3c6788f9ff568a476d84c9f9a0f7b6b2c794df4375424252860998355 de.hextm
badc2e919a0238926d2935c750b9a21047e264edeb8987a85967133ed1350067 nb.hextm
d2b7c27ddd7da701cab7bffd1468f51061bf569d7dc81bfcaacf29beeea0d6cf en.valid
4e14038216fdfd43b71627c247ea5d032ec2aa28d82d30e10694bcb16c350f6e en.capitals
538383ecde556bfa17717694f01d83c3e6efca038cda64a792de6461e94c3e2c en.valid
aeb1068b671ede1a786b704b622abd10647a59b2b2d55831e004a361015c15b5 en.capitals
90f2e774d0bcf02b1e0667a4e4d207adf7e0d5291aee45203fbe8b7dd8282e98 es.capitals
7b1b24ff18868fb32e049502806ef3737ad91bde685239a4cc28ae38185f3ef9 de.capitals
11315e5087befcb598274a6fb5a05a6ff281db29be97a7999d5f3d6cd544f436 fr.hextm
@@ -457,9 +457,11 @@ aphrodisia 59
aphrodite 99
apian 67
apicultural 74
apis 93
apocalypse 65
apocrypha 81
apollo 94
app 83
appalachian 100
appaloosa 90
appaloosas 89
@@ -714,6 +716,7 @@ avocet 73
avon 100
avos 73
aweigh 75
aww 91
axel 97
ayah 63
ayatollah 92
@@ -1464,6 +1467,7 @@ britons 100
brits 94
brittany 100
britton 100
bro 53
broads 54
broadway 100
broch 70
@@ -1485,6 +1489,7 @@ brooking 76
brookings 100
brooklyn 100
brooks 94
bros 94
brose 86
brotherhood 61
brougham 81
@@ -2888,6 +2893,7 @@ deutsch 96
deutschemark 73
deutschland 99
deutzia 73
dev 84
deva 71
devastator 70
devi 93
@@ -3568,6 +3574,7 @@ faller 79
fallon 100
fallows 55
falsettos 68
fam 79
fane 75
fang 85
fannie 100
@@ -3695,6 +3702,7 @@ finn 97
finney 100
finnish 100
finny 74
fintech 51
fiona 100
firebird 90
firebirds 85
@@ -4113,6 +4121,7 @@ gibson 100
gid 63
giddens 100
gideon 100
gif 66
gifford 100
gigabit 64
gigot 69
@@ -4459,6 +4468,8 @@ haematology 67
hafiz 94
hagen 99
hague 100
haha 67
hahaha 73
hahn 99
haifa 100
haig 100
@@ -4625,6 +4636,7 @@ hays 94
hayward 94
hazan 94
hazel 67
hbu 52
healey 100
healy 100
hearst 100
@@ -5019,6 +5031,7 @@ immunochemistry 53
immunogenetics 73
immunol 99
immunology 68
imo 70
impala 69
impaler 94
impatiens 60
@@ -5109,6 +5122,7 @@ irene 100
iris 60
irish 100
irishman 100
irl 55
ironically 56
ironsides 94
ironweed 63
@@ -6036,6 +6050,7 @@ lizzie 100
llano 89
llanos 72
lloyd 100
lmk 62
loach 70
lobelia 64
lobo 92
@@ -6629,6 +6644,7 @@ mexicans 100
mexico 100
meyer 100
meyers 100
mhm 53
miami 100
micah 100
michael 100
@@ -7308,9 +7324,11 @@ oho 80
oidium 73
oilers 70
oilman 55
ok 56
oka 86
okapi 53
oke 81
okie 94
okinawa 100
oklahoma 100
olaf 99
@@ -7337,6 +7355,7 @@ ombudsman 65
omega 58
omegas 59
omer 88
omg 54
omicron 92
omnibus 59
oncol 100
@@ -7928,6 +7947,7 @@ plummer 99
plutarch 100
pluto 99
plymouth 100
plz 94
pochard 72
podiatric 54
poe 94
@@ -8532,6 +8552,7 @@ rives 87
riveter 75
riviera 94
riyadh 100
rn 65
roach 75
roadrunner 67
roadrunners 52
@@ -8729,6 +8750,7 @@ rwanda 100
rya 64
ryan 100
ryder 100
saas 81
sabah 99
sabbath 84
sabbaths 65
@@ -10019,6 +10041,7 @@ thurs 98
thursday 100
thurston 100
thuya 71
thx 55
ti 57
tianjin 100
tiberius 100
@@ -10807,6 +10830,7 @@ woodruffs 94
woodsia 83
woodstock 99
woodward 100
woohoo 81
woolf 100
woolsack 76
woomera 90
@@ -10824,6 +10848,7 @@ wroth 55
wryneck 51
wurst 74
wyatt 100
wyd 66
wylie 100
wynd 72
wynn 99
@@ -10861,6 +10886,7 @@ yardmasters 60
yare 69
yarrow 74
yates 100
yay 71
yeah 82
yearbook 78
yeats 98
Binary file not shown.
@@ -2188,14 +2188,12 @@ aphorizes
aphorizing
aphrodite
aphyllous
api
apia
apiarian
apiarists
apicultures
apiculturist
apiculturists
apis
apishly
apivorous
aplacental
@@ -2263,7 +2261,6 @@ apotheosising
apotheosize
apotheosizes
apotheosizing
app
appalachia
appalachian
appalachians
@@ -2682,7 +2679,6 @@ asa
asafetidas
asafoetidas
asama
asap
asben
asbestoses
ascanius
@@ -5673,7 +5669,6 @@ brittlest
brittney
britzka
brno
bro
broacher
broadax
broadaxes
@@ -5737,7 +5732,6 @@ brooklynese
brookweed
brookweeds
broomcorns
bros
broughams
brouhahas
browband
@@ -5808,7 +5802,6 @@ bt
btl
btry
btu
btw
bu
bubal
bubaline
@@ -7279,7 +7272,6 @@ centrums
centuple
centuplicate
centurial
ceo
cephalisation
cephalochordate
cephalometer
@@ -9747,7 +9739,6 @@ cpl
cpo
cpr
cps
cpu
cq
cr
craal
@@ -12145,7 +12136,6 @@ djokjakarta
dk
dlr
dlvy
dm
dmca
dmd
dmitri
@@ -14682,7 +14672,6 @@ faltboat
falterer
falterings
falwell
fam
famagusta
familiarises
familist
@@ -14713,7 +14702,6 @@ fantasying
fanti
fantoccini
fao
faq
faqs
faquir
faquirs
@@ -16214,7 +16202,6 @@ fwd
fwiw
fwy
fy
fyi
fylfot
fyn
ga
@@ -16857,7 +16844,6 @@ gide
gideon
gielgud
gienah
gif
gifu
gigaflops
gigagram
@@ -17405,7 +17391,6 @@ gp
gpa
gpo
gps
gpu
gq
gr
grabbier
@@ -18446,7 +18431,6 @@ hbo
hd
hdd
hdl
hdmi
hdqrs
hdtv
headbanger
@@ -19938,7 +19922,6 @@ idahoan
idahoans
idahoes
idahos
ide
idealiser
idealizer
ideated
@@ -20150,7 +20133,6 @@ immurements
immures
immuring
imnsho
imo
imodium
imogen
imogene
@@ -28347,7 +28329,6 @@ noxzema
noyade
noyce
noyes
np
npr
nr
nra
@@ -28771,7 +28752,6 @@ oistrakh
oj
ojibwa
ojibwas
ok
okapis
okas
okavango
@@ -28781,7 +28761,6 @@ oked
okeechobee
okefenokee
okhotsk
okie
okinawa
okinawan
oking
@@ -30390,7 +30369,6 @@ pcp
pcs
pct
pd
pdf
pdq
pdt
peabody
@@ -34628,7 +34606,6 @@ rizal
rizzio
rm
rms
rn
rna
roadability
roadblocked
@@ -42889,7 +42866,6 @@ urials
uriel
uriniferous
uris
url
urmia
urochrome
urogenous
@@ -42916,7 +42892,6 @@ usa
usably
usaf
usances
usb
uscg
usda
usenet
@@ -43773,7 +43748,6 @@ vowelizing
vower
vp
vries
vs
vt
vtol
vuillard
@@ -44399,7 +44373,6 @@ wienies
wiesbaden
wiesel
wiesenthal
wifi
wigan
wiggings
wiggins
+6 -3
View File
@@ -151,18 +151,20 @@ All four HXTM v3 assets are uncompressed and memory-mapped from the APK; Gradle
| Language | Words | Word pairs | Source of counts | Source of spelling |
|---|---:|---:|---|---|
| English | 86,133 | 417,480 | Google Books v3, 24 unigram / 589 bigram shards | SCOWL 2020.12.07 |
| English | 86,247 | 417,182 | Google Books v3, 24 unigram / 589 bigram shards | SCOWL 2020.12.07, plus contractions and Hex's own [chat and tech words](en-extra-words.tsv) |
| Spanish | 110,000 | 326,366 | Google Books v3, 3 / 73 shards; existing model unchanged | RLA-ES Hunspell |
| German | 95,000 | 368,534 | Google Books v3, all 8 / 181 German shards | German alphabetic corpus spellings |
| Bokmål | 95,000 | 370,560 | NB N-gram 2026 book unigrams and bigrams, language `nob` | Norsk ordbank, Bokmål full forms |
| French | 99,974 | 380,439 | Google Books v3, all 6 / 115 French shards | French corpus spellings, with the books' elided forms |
| Italian | 99,996 | 371,292 | Google Books v3, all 2 / 60 Italian shards | Italian corpus spellings, with the books' elided forms |
English was rebuilt with the shared builder from the same 24 unigram and 589 bigram shards and SCOWL. Run with the earlier rules, the same counts reproduce the earlier `en.hextm` byte for byte (SHA-256 `14370569…c4028`), so the new file (`c23e9c54…df30`) differs only by two additions. Google Books splits "don't" into "do" and "n't", so its own count of the contraction is tiny ("don't" cost 14.4 nats, "it's" 16.2, and SCOWL lists "I'm", "I'll", "I've" and "I'd" only with a capital, so they were missing): each contraction in the builder's `CONTRACTIONS` now counts as often as its expansion's pair ("do not") when that is commoner, and the missing ones are added in lowercase. And [en-extra-words.tsv](en-extra-words.tsv), 166 chat and tech words written for Hex ("app", "lol", "csv"), joins the vocabulary at its tier's cost (10, 12 or 13.5 nats), a word the books have only getting commoner. Both join before pairs are counted. `en.valid` and `en.capitals` are rebuilt from the new model (their builders also reproduce the earlier files from the earlier model); `build-capitals.py` holds Hex's own words at 94% like SCOWL's lowercase words, so "plz" and "okie" are never capitalised. English gate before → after: iOS (`ios/scripts/typing-gate.py`) 773 → 734 word errors (83.5% → 84.4% fewer than raw taps, correct words changed 0.27% → 0.26%), Android (`quality-gate.py`) 718 → 680 (84.7% → 85.5%, 0.32% both), critical cases passing.
French and Italian go through the same German adapter: every untagged shard of the language, 1980–2019, spellings from the corpus alone. The books keep many elisions as one token ("c'est", "qu'il", Italian "dell'anno"; French "l'" and "d'" are split off), so those stay words with their apostrophe, which the decoder reads without it being typed. The same letters run together without the apostrophe, ten times rarer ("cest", "quil", 26 French and 4 Italian forms), are left out so space puts it back. A word typed right after an elided article or pronoun ("l'", "qu'", "dell'") is read as a word of its own (`TypingWord.startsWord`).
The [shared iOS builder](build-typing-model.py), SHA-256 `cba009fe227632d9f8d176055f26ca34d5eb6f88a7cbd947955d8f9142878317`, sums counts from 1980–2019, selects informative pairs and writes quantized probabilities. The [German/Bokmål adapter](build-layout-model.py) uses the same writer. For German, it uses the iOS shard reader and filters lowercased words to its alphabet. For Bokmål, it NFC-normalizes and lowercases the words, filters vocabulary to standard Bokmål forms in the 1 February 2022 Ordbank `fullformsliste.txt` (`OPPSLAG`, normative and current in that snapshot), and only retains pairs whose two words are in that vocabulary. The September 2026 inflection export alone dropped common uninflected words such as `og`, `på` and `det`; it was not used in the shipped model. The complete snapshot supplied 617,139 distinct forms. Of 20,096,783 observed in-vocabulary pair types, 394,825 met the shared writer’s count and information thresholds; 370,560 fit the model budget.
The [shared iOS builder](build-typing-model.py), SHA-256 `2442a46ca46145f7d48efc8e73015299e7d60010810a8916239f170024a80446`, sums counts from 1980–2019, selects informative pairs and writes quantized probabilities. The [German/Bokmål adapter](build-layout-model.py) uses the same writer. For German, it uses the iOS shard reader and filters lowercased words to its alphabet. For Bokmål, it NFC-normalizes and lowercases the words, filters vocabulary to standard Bokmål forms in the 1 February 2022 Ordbank `fullformsliste.txt` (`OPPSLAG`, normative and current in that snapshot), and only retains pairs whose two words are in that vocabulary. The September 2026 inflection export alone dropped common uninflected words such as `og`, `på` and `det`; it was not used in the shipped model. The complete snapshot supplied 617,139 distinct forms. Of 20,096,783 observed in-vocabulary pair types, 394,825 met the shared writer’s count and information thresholds; 370,560 fit the model budget.
- [Google Books Ngram v3 (2020-02-17)](https://storage.googleapis.com/books/ngrams/books/datasetsv3.html): **CC BY 3.0**. English and Spanish keep the original shared builds. German uses no second dictionary.
- [Google Books Ngram v3 (2020-02-17)](https://storage.googleapis.com/books/ngrams/books/datasetsv3.html): **CC BY 3.0**. Spanish keeps the original shared build; English was rebuilt from the same shards (below). German uses no second dictionary.
- [NB N-gram 2026](https://data.norge.no/nb/datasets/f2eebe8b-bd83-34e4-bcf3-c0c5e37a77f8/n-grammer-fra-nasjonalbiblioteket-2026): the National Library of Norway’s counts are **CC0 1.0**. The [Norsk ordbank – Bokmål 2005, February 2022](https://data.norge.no/en/datasets/f0db926d-a154-3a12-82b8-6573b57f6dbb/norsk-ordbank-norwegian-bokmal-2005) spelling filter is separately **CC BY 4.0**.
- [SCOWL](https://wordlist.aspell.net/) permits commercial redistribution subject to its [included notices](../../app/src/main/assets/licenses/scowl.txt). The English literal-validity list contains 45,303 unique spellings absent from the frequency model (440,142 bytes). It is built from the same public SCOWL archive, not from benchmark outputs or personal data. It cannot supply scored candidates or word probabilities.
- [RLA-ES es_ES/es_MX sources](https://github.com/LibreOffice/dictionaries/tree/762abe74008b94b2ff06db6f4024b59a8254c467/es) use their **MPL 1.1** option. [APK credits, source links and modification notices](../../app/src/main/assets/licenses/credits.txt) · [full licence texts](../../app/src/main/assets/licenses/).
@@ -227,6 +229,7 @@ adapted from Shutterstock's [LDNOOBW revision 5faf2ba](https://github.com/LDNOOB
```sh
mkdir -p "$T/models" "$T/source"
python3 benchmark/typing/build-typing-model.py en "$T/source/en" "$T/models/en.hextm"
python3 benchmark/typing/build-layout-model.py de "$T/source/de" "$T/models/de.hextm"
python3 benchmark/typing/build-layout-model.py nb "$T/source/nb" "$T/models/nb.hextm"
python3 benchmark/typing/build-layout-model.py fr "$T/source/fr" "$T/models/fr.hextm"
@@ -155,6 +155,11 @@ def merged_counts(lang, work):
def main():
lang, model, work, output = sys.argv[1:5]
lowercase = scowl_lowercase(sys.argv[5]) if lang == "en" else set()
if lang == "en":
# Hex's own chat and tech words (en-extra-words.tsv, which build-typing-model.py adds to the
# model) are lowercase words: "plz" and "okie", capitalised in books, are held too.
extra = os.path.join(os.path.dirname(os.path.abspath(__file__)), "en-extra-words.tsv")
lowercase |= {line.split("\t")[0] for line in open(extra, encoding="utf-8") if line.strip() and not line.startswith("#")}
merged = merged_counts(lang, work)
unigram, pair = model_words(model)
words = set(unigram)
+54 -1
View File
@@ -4,6 +4,16 @@ Books Ngram v3 (2020-02-17, CC BY 3.0) word and word-pair counts, keeping only w
word list knows: SCOWL (sizes up to 70) for English, RLA-ES (LibreOffice's es_ES and
es_MX Hunspell dictionaries, used under their MPL 1.1 option) for Spanish. Counts are summed over 1980-2019.
English also takes two things the books can't give it:
- Contractions at the frequency of the words they stand for. Google Books splits "don't"
into "do" and "n't", so its own count of "don't" is tiny (14.4 nats in the first model,
as rare as a word ranked 100,000th). Each contraction in CONTRACTIONS counts as often as
its expansion's pair ("do not") when that is commoner, and the ones SCOWL lists only with
a capital ("I'm") or not at all are added in lowercase.
- en-extra-words.tsv beside this script: chat and tech words written for Hex ("app", "lol",
"csv"), each at its tier's cost; a word the books have only gets commoner.
Both join the vocabulary before pairs are counted, so their pairs are counted too.
python3 -m venv /tmp/venv && /tmp/venv/bin/pip install spylls # Spanish only
/tmp/venv/bin/python scripts/build-typing-model.py es <workdir> HEXKeyboard/TypingModel/es.hextm
@@ -33,6 +43,21 @@ MAX_WORDS = {"en": 90_000, "es": 110_000}
MAX_BYTES = 3_600_000 # the whole model
MIN_PAIR = 2_000 # pairs rarer than this (1980-2019) can't make the cut
LETTERS = {"en": "abcdefghijklmnopqrstuvwxyz'", "es": "abcdefghijklmnopqrstuvwxyzñáéíóúü"}
CONTRACTIONS = {"en": {
"don't": "do not", "doesn't": "does not", "didn't": "did not", "can't": "can not", "won't": "will not",
"isn't": "is not", "aren't": "are not", "wasn't": "was not", "weren't": "were not", "haven't": "have not",
"hasn't": "has not", "hadn't": "had not", "wouldn't": "would not", "couldn't": "could not",
"shouldn't": "should not", "mustn't": "must not", "needn't": "need not",
"i'm": "i am", "i'll": "i will", "i've": "i have", "i'd": "i would",
"it's": "it is", "that's": "that is", "what's": "what is", "where's": "where is", "who's": "who is",
"there's": "there is", "here's": "here is", "he's": "he is", "she's": "she is", "let's": "let us",
"you're": "you are", "we're": "we are", "they're": "they are", "you'll": "you will", "we'll": "we will",
"they'll": "they will", "he'll": "he will", "she'll": "she will", "it'll": "it will",
"you've": "you have", "we've": "we have", "they've": "they have", "you'd": "you would",
"we'd": "we would", "they'd": "they would", "he'd": "he would", "she'd": "she would",
}}
EXTRA_WORDS = {"en": "en-extra-words.tsv"}
TIER_COST = {"1": 10.0, "2": 12.0, "3": 13.5} # nats: about the 2,000th word, then rarer
def urls(lang, n):
@@ -161,6 +186,20 @@ def cost(p):
return max(0, min(255, round(-math.log(max(p, 1e-30)) * 8)))
def extra_words(lang, total):
"""EXTRA_WORDS' words with the count their tier's cost stands for."""
if lang not in EXTRA_WORDS:
return {}
words = {}
for line in open(os.path.join(os.path.dirname(os.path.abspath(__file__)), EXTRA_WORDS[lang]), encoding="utf-8"):
if not line.strip() or line.startswith("#"):
continue
word, tier = line.rstrip("\n").split("\t")
assert re.fullmatch("[" + LETTERS[lang] + "]+", word), word
words[word] = max(words.get(word, 0), round(total * math.exp(-TIER_COST[tier])))
return words
def main(lang, work, out_path):
for d in ("raw", "uni", "bi"):
os.makedirs(os.path.join(work, d), exist_ok=True)
@@ -189,14 +228,28 @@ def main(lang, work, out_path):
for line in open(vocab_path, encoding="utf-8"):
w, c = line.rstrip("\n").split("\t")
vocab[w] = int(c)
for w, c in extra_words(lang, total).items():
vocab[w] = max(vocab.get(w, 0), counts.get(w.encode("utf-8"), 0), c)
for w in CONTRACTIONS.get(lang, {}):
vocab.setdefault(w, max(1, counts.get(w.encode("utf-8"), 0)))
# Pairs are counted over the vocabulary with these words (a cached bi/ from a run
# without them lacks their pairs).
pair_vocab = os.path.join(work, "vocab-pairs.tsv")
with open(pair_vocab, "w", encoding="utf-8") as f:
for w in sorted(vocab):
f.write(f"{w}\t{vocab[w]}\n")
with multiprocessing.Pool(workers, initializer=load_vocab, initargs=(vocab_path,)) as pool:
with multiprocessing.Pool(workers, initializer=load_vocab, initargs=(pair_vocab,)) as pool:
bi_files = pool.map(count_pairs, [(lang, u, work) for u in urls(lang, 2)])
pairs = {}
for p in bi_files:
for line in open(p, "rb"):
k, c = line.rstrip(b"\n").split(b"\t")
pairs[k] = pairs.get(k, 0) + int(c)
# Pairs of words no longer in the vocabulary (a bi/ cached by a run with more words) go.
pairs = {k: c for k, c in pairs.items() if all(w.decode("utf-8") in vocab for w in k.split(b" "))}
for w, expansion in CONTRACTIONS.get(lang, {}).items():
vocab[w] = max(vocab[w], pairs.get(expansion.encode("utf-8"), 0))
write_model(lang, vocab, total, pairs, out_path)
+171
View File
@@ -0,0 +1,171 @@
# Chat and tech words for the English typing model (build-typing-model.py), written for Hex
# by its developers: ours, not copied from any corpus, dictionary or other keyboard.
# Each line: word<TAB>tier. Tier 1 costs 10 nats (about the model's 2,000th word), tier 2
# 12, tier 3 13.5; a word the books already have only gets commoner. Lowercase a-z and '
# only, no brand or product names (the model is lowercase; their capitals come from elsewhere).
ok 1
lol 1
haha 1
yep 1
yup 1
nope 1
gonna 1
wanna 1
gotta 1
app 1
apps 1
email 1
emails 1
online 1
website 1
wifi 1
laptop 1
emoji 1
text 1
texts 1
texting 1
okay 1
yeah 1
hey 1
thanks 1
hahaha 2
lmao 2
omg 2
btw 2
idk 2
tbh 2
imo 2
fyi 2
brb 2
thx 2
pls 2
plz 2
np 2
dm 2
dms 2
gif 2
gifs 2
meme 2
memes 2
selfie 2
selfies 2
hashtag 2
emojis 2
vs 2
ceo 2
api 2
apis 2
gpu 2
gpus 2
cpu 2
cpus 2
csv 2
json 2
repo 2
repos 2
url 2
urls 2
pdf 2
pdfs 2
login 2
logins 2
signup 2
backend 2
frontend 2
dev 2
devs 2
config 2
configs 2
async 2
smh 2
ngl 2
tmr 2
tmrw 2
rn 2
irl 2
jk 2
yw 2
ikr 2
nvm 2
wfh 2
asap 2
faq 2
diy 2
bday 2
convo 2
convos 2
pic 2
pics 2
vid 2
vids 2
lmk 2
ttyl 2
omw 2
wyd 2
hbu 2
lowkey 2
vibe 2
vibes 2
sus 2
bruh 2
bro 2
bros 2
sis 2
fam 2
dude 2
dudes 2
hmm 2
mhm 2
ugh 2
yay 2
aww 2
oops 2
whoops 2
yikes 2
okie 2
usb 2
hdmi 2
ssd 2
sdk 2
ui 2
ux 2
cli 2
ide 2
ai 2
llm 2
llms 2
chatbot 2
chatbots 2
startup 2
startups 2
crypto 2
bitcoin 2
podcast 2
podcasts 2
livestream 2
streaming 2
app's 2
apps' 3
npm 3
refactor 3
refactoring 3
saas 3
fintech 3
blockchain 3
nft 3
nfts 3
woohoo 3
hiya 3
realtime 3
codebase 3
codebases 3
dataset 3
datasets 3
workflow 3
workflows 3
onboarding 3
screenshot 3
screenshots 3
smartwatch 3
zoom 3
slack 3
1 # Chat and tech words for the English typing model (build-typing-model.py), written for Hex
2 # by its developers: ours, not copied from any corpus, dictionary or other keyboard.
3 # Each line: word<TAB>tier. Tier 1 costs 10 nats (about the model's 2,000th word), tier 2
4 # 12, tier 3 13.5; a word the books already have only gets commoner. Lowercase a-z and '
5 # only, no brand or product names (the model is lowercase; their capitals come from elsewhere).
6 ok 1
7 lol 1
8 haha 1
9 yep 1
10 yup 1
11 nope 1
12 gonna 1
13 wanna 1
14 gotta 1
15 app 1
16 apps 1
17 email 1
18 emails 1
19 online 1
20 website 1
21 wifi 1
22 laptop 1
23 emoji 1
24 text 1
25 texts 1
26 texting 1
27 okay 1
28 yeah 1
29 hey 1
30 thanks 1
31 hahaha 2
32 lmao 2
33 omg 2
34 btw 2
35 idk 2
36 tbh 2
37 imo 2
38 fyi 2
39 brb 2
40 thx 2
41 pls 2
42 plz 2
43 np 2
44 dm 2
45 dms 2
46 gif 2
47 gifs 2
48 meme 2
49 memes 2
50 selfie 2
51 selfies 2
52 hashtag 2
53 emojis 2
54 vs 2
55 ceo 2
56 api 2
57 apis 2
58 gpu 2
59 gpus 2
60 cpu 2
61 cpus 2
62 csv 2
63 json 2
64 repo 2
65 repos 2
66 url 2
67 urls 2
68 pdf 2
69 pdfs 2
70 login 2
71 logins 2
72 signup 2
73 backend 2
74 frontend 2
75 dev 2
76 devs 2
77 config 2
78 configs 2
79 async 2
80 smh 2
81 ngl 2
82 tmr 2
83 tmrw 2
84 rn 2
85 irl 2
86 jk 2
87 yw 2
88 ikr 2
89 nvm 2
90 wfh 2
91 asap 2
92 faq 2
93 diy 2
94 bday 2
95 convo 2
96 convos 2
97 pic 2
98 pics 2
99 vid 2
100 vids 2
101 lmk 2
102 ttyl 2
103 omw 2
104 wyd 2
105 hbu 2
106 lowkey 2
107 vibe 2
108 vibes 2
109 sus 2
110 bruh 2
111 bro 2
112 bros 2
113 sis 2
114 fam 2
115 dude 2
116 dudes 2
117 hmm 2
118 mhm 2
119 ugh 2
120 yay 2
121 aww 2
122 oops 2
123 whoops 2
124 yikes 2
125 okie 2
126 usb 2
127 hdmi 2
128 ssd 2
129 sdk 2
130 ui 2
131 ux 2
132 cli 2
133 ide 2
134 ai 2
135 llm 2
136 llms 2
137 chatbot 2
138 chatbots 2
139 startup 2
140 startups 2
141 crypto 2
142 bitcoin 2
143 podcast 2
144 podcasts 2
145 livestream 2
146 streaming 2
147 app's 2
148 apps' 3
149 npm 3
150 refactor 3
151 refactoring 3
152 saas 3
153 fintech 3
154 blockchain 3
155 nft 3
156 nfts 3
157 woohoo 3
158 hiya 3
159 realtime 3
160 codebase 3
161 codebases 3
162 dataset 3
163 datasets 3
164 workflow 3
165 workflows 3
166 onboarding 3
167 screenshot 3
168 screenshots 3
169 smartwatch 3
170 zoom 3
171 slack 3
Binary file not shown.
+3 -1
View File
@@ -623,7 +623,9 @@ never at a launch by itself.
model, except as bilingual autocorrect's second language (below). The
models (`HEXKeyboard/TypingModel/en.hextm` and `es.hextm`, about 3.6 MB each) are
built from Google Books Ngram v3 by `scripts/build-typing-model.py` (see
Acknowledgements below); `de.hextm` is the German model Android builds and ships
Acknowledgements below); English's contractions count as often as the words they stand
for ("do not"), and it adds Hex's own chat and tech words (`scripts/en-extra-words.tsv`),
byte-identical to Android's `en.hextm`; `de.hextm` is the German model Android builds and ships
(`android/benchmark/typing/build-layout-model.py`), the same v3 format and, on iOS,
off until the experiment below is turned on. `fr.hextm` is Android's French model, built
the same way from Google Books v3's French shards (corpus spellings, with the books'
+54 -1
View File
@@ -4,6 +4,16 @@ Books Ngram v3 (2020-02-17, CC BY 3.0) word and word-pair counts, keeping only w
word list knows: SCOWL (sizes up to 70) for English, RLA-ES (LibreOffice's es_ES and
es_MX Hunspell dictionaries, used under their MPL 1.1 option) for Spanish. Counts are summed over 1980-2019.
English also takes two things the books can't give it:
- Contractions at the frequency of the words they stand for. Google Books splits "don't"
into "do" and "n't", so its own count of "don't" is tiny (14.4 nats in the first model,
as rare as a word ranked 100,000th). Each contraction in CONTRACTIONS counts as often as
its expansion's pair ("do not") when that is commoner, and the ones SCOWL lists only with
a capital ("I'm") or not at all are added in lowercase.
- en-extra-words.tsv beside this script: chat and tech words written for Hex ("app", "lol",
"csv"), each at its tier's cost; a word the books have only gets commoner.
Both join the vocabulary before pairs are counted, so their pairs are counted too.
python3 -m venv /tmp/venv && /tmp/venv/bin/pip install spylls # Spanish only
/tmp/venv/bin/python scripts/build-typing-model.py es <workdir> HEXKeyboard/TypingModel/es.hextm
@@ -33,6 +43,21 @@ MAX_WORDS = {"en": 90_000, "es": 110_000}
MAX_BYTES = 3_600_000 # the whole model
MIN_PAIR = 2_000 # pairs rarer than this (1980-2019) can't make the cut
LETTERS = {"en": "abcdefghijklmnopqrstuvwxyz'", "es": "abcdefghijklmnopqrstuvwxyzñáéíóúü"}
CONTRACTIONS = {"en": {
"don't": "do not", "doesn't": "does not", "didn't": "did not", "can't": "can not", "won't": "will not",
"isn't": "is not", "aren't": "are not", "wasn't": "was not", "weren't": "were not", "haven't": "have not",
"hasn't": "has not", "hadn't": "had not", "wouldn't": "would not", "couldn't": "could not",
"shouldn't": "should not", "mustn't": "must not", "needn't": "need not",
"i'm": "i am", "i'll": "i will", "i've": "i have", "i'd": "i would",
"it's": "it is", "that's": "that is", "what's": "what is", "where's": "where is", "who's": "who is",
"there's": "there is", "here's": "here is", "he's": "he is", "she's": "she is", "let's": "let us",
"you're": "you are", "we're": "we are", "they're": "they are", "you'll": "you will", "we'll": "we will",
"they'll": "they will", "he'll": "he will", "she'll": "she will", "it'll": "it will",
"you've": "you have", "we've": "we have", "they've": "they have", "you'd": "you would",
"we'd": "we would", "they'd": "they would", "he'd": "he would", "she'd": "she would",
}}
EXTRA_WORDS = {"en": "en-extra-words.tsv"}
TIER_COST = {"1": 10.0, "2": 12.0, "3": 13.5} # nats: about the 2,000th word, then rarer
def urls(lang, n):
@@ -161,6 +186,20 @@ def cost(p):
return max(0, min(255, round(-math.log(max(p, 1e-30)) * 8)))
def extra_words(lang, total):
"""EXTRA_WORDS' words with the count their tier's cost stands for."""
if lang not in EXTRA_WORDS:
return {}
words = {}
for line in open(os.path.join(os.path.dirname(os.path.abspath(__file__)), EXTRA_WORDS[lang]), encoding="utf-8"):
if not line.strip() or line.startswith("#"):
continue
word, tier = line.rstrip("\n").split("\t")
assert re.fullmatch("[" + LETTERS[lang] + "]+", word), word
words[word] = max(words.get(word, 0), round(total * math.exp(-TIER_COST[tier])))
return words
def main(lang, work, out_path):
for d in ("raw", "uni", "bi"):
os.makedirs(os.path.join(work, d), exist_ok=True)
@@ -189,14 +228,28 @@ def main(lang, work, out_path):
for line in open(vocab_path, encoding="utf-8"):
w, c = line.rstrip("\n").split("\t")
vocab[w] = int(c)
for w, c in extra_words(lang, total).items():
vocab[w] = max(vocab.get(w, 0), counts.get(w.encode("utf-8"), 0), c)
for w in CONTRACTIONS.get(lang, {}):
vocab.setdefault(w, max(1, counts.get(w.encode("utf-8"), 0)))
# Pairs are counted over the vocabulary with these words (a cached bi/ from a run
# without them lacks their pairs).
pair_vocab = os.path.join(work, "vocab-pairs.tsv")
with open(pair_vocab, "w", encoding="utf-8") as f:
for w in sorted(vocab):
f.write(f"{w}\t{vocab[w]}\n")
with multiprocessing.Pool(workers, initializer=load_vocab, initargs=(vocab_path,)) as pool:
with multiprocessing.Pool(workers, initializer=load_vocab, initargs=(pair_vocab,)) as pool:
bi_files = pool.map(count_pairs, [(lang, u, work) for u in urls(lang, 2)])
pairs = {}
for p in bi_files:
for line in open(p, "rb"):
k, c = line.rstrip(b"\n").split(b"\t")
pairs[k] = pairs.get(k, 0) + int(c)
# Pairs of words no longer in the vocabulary (a bi/ cached by a run with more words) go.
pairs = {k: c for k, c in pairs.items() if all(w.decode("utf-8") in vocab for w in k.split(b" "))}
for w, expansion in CONTRACTIONS.get(lang, {}).items():
vocab[w] = max(vocab[w], pairs.get(expansion.encode("utf-8"), 0))
write_model(lang, vocab, total, pairs, out_path)
+171
View File
@@ -0,0 +1,171 @@
# Chat and tech words for the English typing model (build-typing-model.py), written for Hex
# by its developers: ours, not copied from any corpus, dictionary or other keyboard.
# Each line: word<TAB>tier. Tier 1 costs 10 nats (about the model's 2,000th word), tier 2
# 12, tier 3 13.5; a word the books already have only gets commoner. Lowercase a-z and '
# only, no brand or product names (the model is lowercase; their capitals come from elsewhere).
ok 1
lol 1
haha 1
yep 1
yup 1
nope 1
gonna 1
wanna 1
gotta 1
app 1
apps 1
email 1
emails 1
online 1
website 1
wifi 1
laptop 1
emoji 1
text 1
texts 1
texting 1
okay 1
yeah 1
hey 1
thanks 1
hahaha 2
lmao 2
omg 2
btw 2
idk 2
tbh 2
imo 2
fyi 2
brb 2
thx 2
pls 2
plz 2
np 2
dm 2
dms 2
gif 2
gifs 2
meme 2
memes 2
selfie 2
selfies 2
hashtag 2
emojis 2
vs 2
ceo 2
api 2
apis 2
gpu 2
gpus 2
cpu 2
cpus 2
csv 2
json 2
repo 2
repos 2
url 2
urls 2
pdf 2
pdfs 2
login 2
logins 2
signup 2
backend 2
frontend 2
dev 2
devs 2
config 2
configs 2
async 2
smh 2
ngl 2
tmr 2
tmrw 2
rn 2
irl 2
jk 2
yw 2
ikr 2
nvm 2
wfh 2
asap 2
faq 2
diy 2
bday 2
convo 2
convos 2
pic 2
pics 2
vid 2
vids 2
lmk 2
ttyl 2
omw 2
wyd 2
hbu 2
lowkey 2
vibe 2
vibes 2
sus 2
bruh 2
bro 2
bros 2
sis 2
fam 2
dude 2
dudes 2
hmm 2
mhm 2
ugh 2
yay 2
aww 2
oops 2
whoops 2
yikes 2
okie 2
usb 2
hdmi 2
ssd 2
sdk 2
ui 2
ux 2
cli 2
ide 2
ai 2
llm 2
llms 2
chatbot 2
chatbots 2
startup 2
startups 2
crypto 2
bitcoin 2
podcast 2
podcasts 2
livestream 2
streaming 2
app's 2
apps' 3
npm 3
refactor 3
refactoring 3
saas 3
fintech 3
blockchain 3
nft 3
nfts 3
woohoo 3
hiya 3
realtime 3
codebase 3
codebases 3
dataset 3
datasets 3
workflow 3
workflows 3
onboarding 3
screenshot 3
screenshots 3
smartwatch 3
zoom 3
slack 3
1 # Chat and tech words for the English typing model (build-typing-model.py), written for Hex
2 # by its developers: ours, not copied from any corpus, dictionary or other keyboard.
3 # Each line: word<TAB>tier. Tier 1 costs 10 nats (about the model's 2,000th word), tier 2
4 # 12, tier 3 13.5; a word the books already have only gets commoner. Lowercase a-z and '
5 # only, no brand or product names (the model is lowercase; their capitals come from elsewhere).
6 ok 1
7 lol 1
8 haha 1
9 yep 1
10 yup 1
11 nope 1
12 gonna 1
13 wanna 1
14 gotta 1
15 app 1
16 apps 1
17 email 1
18 emails 1
19 online 1
20 website 1
21 wifi 1
22 laptop 1
23 emoji 1
24 text 1
25 texts 1
26 texting 1
27 okay 1
28 yeah 1
29 hey 1
30 thanks 1
31 hahaha 2
32 lmao 2
33 omg 2
34 btw 2
35 idk 2
36 tbh 2
37 imo 2
38 fyi 2
39 brb 2
40 thx 2
41 pls 2
42 plz 2
43 np 2
44 dm 2
45 dms 2
46 gif 2
47 gifs 2
48 meme 2
49 memes 2
50 selfie 2
51 selfies 2
52 hashtag 2
53 emojis 2
54 vs 2
55 ceo 2
56 api 2
57 apis 2
58 gpu 2
59 gpus 2
60 cpu 2
61 cpus 2
62 csv 2
63 json 2
64 repo 2
65 repos 2
66 url 2
67 urls 2
68 pdf 2
69 pdfs 2
70 login 2
71 logins 2
72 signup 2
73 backend 2
74 frontend 2
75 dev 2
76 devs 2
77 config 2
78 configs 2
79 async 2
80 smh 2
81 ngl 2
82 tmr 2
83 tmrw 2
84 rn 2
85 irl 2
86 jk 2
87 yw 2
88 ikr 2
89 nvm 2
90 wfh 2
91 asap 2
92 faq 2
93 diy 2
94 bday 2
95 convo 2
96 convos 2
97 pic 2
98 pics 2
99 vid 2
100 vids 2
101 lmk 2
102 ttyl 2
103 omw 2
104 wyd 2
105 hbu 2
106 lowkey 2
107 vibe 2
108 vibes 2
109 sus 2
110 bruh 2
111 bro 2
112 bros 2
113 sis 2
114 fam 2
115 dude 2
116 dudes 2
117 hmm 2
118 mhm 2
119 ugh 2
120 yay 2
121 aww 2
122 oops 2
123 whoops 2
124 yikes 2
125 okie 2
126 usb 2
127 hdmi 2
128 ssd 2
129 sdk 2
130 ui 2
131 ux 2
132 cli 2
133 ide 2
134 ai 2
135 llm 2
136 llms 2
137 chatbot 2
138 chatbots 2
139 startup 2
140 startups 2
141 crypto 2
142 bitcoin 2
143 podcast 2
144 podcasts 2
145 livestream 2
146 streaming 2
147 app's 2
148 apps' 3
149 npm 3
150 refactor 3
151 refactoring 3
152 saas 3
153 fintech 3
154 blockchain 3
155 nft 3
156 nfts 3
157 woohoo 3
158 hiya 3
159 realtime 3
160 codebase 3
161 codebases 3
162 dataset 3
163 datasets 3
164 workflow 3
165 workflows 3
166 onboarding 3
167 screenshot 3
168 screenshots 3
169 smartwatch 3
170 zoom 3
171 slack 3