hex/android/benchmark/typing/pt-inputs.tsv
Ryan Vogel 28eb44e695
android: Português typing (Brazilian model, accent holds, autocorrect, suggestions, swipe) (#2780)
* android typing: a reproducible Brazilian Portuguese model (pt.hextm, pt.valid, pt.capitals), not wired up yet

Google Books has no Portuguese, so the model is counted from sources licensed for commercial use
with attribution only (CC BY 4.0), each file pinned in benchmark/typing/pt-inputs.tsv by URL, fetch
date, size and SHA-256:
- 14 Leipzig Corpora Collection news downloads (only the downloads; the site and API are CC BY-NC),
  each sentence given to Brazil or Portugal by its site (.br, .pt, else spelling markers).
- ParlaIbero-BR and -PT v2 (Câmara dos Deputados 2009-2025, Assembleia da República 1995-2025).

build-layout-model.py pt: Brazil's counts (181.5M news words, 138.1M words of speech), news counted
ten times a speech for words and alone for word pairs (with speech pairs in, "obrigado" was followed
by "sr" and "deputado"), less spellings retired in 1990 ("idéia", "vôo") and plain twins 20 times
rarer than an accented one ("nao", "voce", Polish's rule), plus Hex's own chat words
(pt-extra-words.tsv, a draft for a Brazilian speaker to read). 100,029 words, 380,416 pairs, 3.60 MB.
build-valid-words.py pt: Brazil's other lowercase spellings, then Portugal's own spellings from
Portugal's counts ("telemóvel", "receção"), so a Portuguese typist's correct word stays as typed.
build-capitals.py pt: case shares from the same Brazilian counts, held as French's are.

Held-out set: portuguese_set.py makes held-out/pt.tsv.gz exactly as polish_set.py makes Polish's,
from Brazilian contributors' Tatoeba sentences; accent keys and seven critical cases added.
quality-gate.py now takes more than two critical cases (Polish already had five).
The APK pins the three new files (SHA256SUMS, verifyTypingModels); no layout or keyboard code
reads them yet, so nothing a person sees changes.

Verified: a from-scratch rebuild on the Studio in a separate folder gave byte-identical files
(pt.hextm 387bf9b6..., pt.valid b92acc12..., pt.capitals 0210f5bd...); 12,800 of the 12,873
held-out reference words are model or list words; on 5,000 other Brazilian Tatoeba sentences the
model reads 6.54 nats per known word (news only 6.55, speech only 6.90, both alike 6.59).
Not yet run: quality-gate.py pt (it compiles the app with Gradle, which waits for the coordinator).

* android typing: Portuguese words the context decides (é or e, está or esta), and a held accent stays

Step 4 of Portuguese typing. ContextWords gets Portuguese groups: the same letters with and without
an accent ("e"/"é", "esta"/"está", "nos"/"nós", "a"/"à", ...) and a verb beside the noun its accent
makes ("duvida"/"dúvida", "pratica"/"prática", "magoa"/"mágoa"). build-layout-model.py keeps those
verbs in the model (PT_CONTEXT_WORDS, the same words) although the plain-twin rule would leave them
out, so the words around can pick them; the rebuilt pt.hextm, pt.valid and pt.capitals differ only by
those 20 words and the pairs and costs that follow.

A Portuguese word typed with an accent held for it is no longer revised by the next word
(ContextWords.keepsTypedAccent): with the groups alone, the next word turned 26 held "é" into "e"
and 14 "à" into "a" in the clean replay, and correct words changed rose to 0.58%. French and
Italian keep revising a held accent, as before.

Verified with quality-gate.py all on the Studio (host JVM, Gradle --no-daemon, no emulator):
pt 83.75% fewer errors than raw taps (81.23% before), 0.16% of correct words changed (0.09%),
98.30% of unambiguous accents restored (98.31%), 51.98% of ambiguous ones (21.61%), ambiguous harm
0.29% (0.03%), critical cases 7/7 (6/7: "ele e muito bom" -> "ele é muito bom" now passes); PASS.
en, es, de, nb, fr and it: the gate's output identical field for field to origin/dev's.
Known limit, measured on Tatoeba sentences outside the held-out set: of 152 uses of those verbs
typed as written, 38 stay (13 before); 114 still become the noun. Simple pluperfects ("acontecera")
become the future. The held-out set has one such word ("recebera") and none of the verbs.

* android keyboard: Português gets its own layout and typing model, accent holds, swipe and filter

Step 5 of Portuguese typing. Português, dictated or pinned in Keyboard › Keyboard layout, now types
with its own model instead of English's word list standing in (Spoken.Portuguese, "pt"):
- Keys: QWERTY, as English's (KeyboardLetters "pt").
- Holds: iPhone Hex's Portuguese long presses (KeyboardLanguage.swift) on a, e, i, o, u, c and n;
  other letters hold nothing, as on iPhone.
- The strip's words between words: "eu", "o", "a" at a sentence's start, "e", "mas", "que" after a
  comma, and the commonest words where the pairs know none.
- never-suggest.tsv: Portuguese rows curated from LDNOOBW's pt list (CC BY 4.0, credit extended):
  11 slurs (viado, bicha, paneleiro, sapatão...) and 43 swear words with common inflections;
  ordinary words on that list (comer, cerveja, burro, saco, transar) and veado (deer) stay.
- Swipe: swipe_paths.py and swipe-bench.py know "pt".
Nederlands, Polski and Русский keep English's word list as a stand-in, as before.

Tests (existing files): InsertionTest now expects Português's layout and typing model;
NeverSuggestTest runs its filter, between-words and swipe checks for pt as for the other six.

Verified on the Studio (host JVM, Gradle --no-daemon, no emulator): testDebugUnitTest passes;
quality-gate.py all: pt PASS (83.75% fewer errors, 0.16% correct words changed, 98.30% accents,
7/7), the other six identical field for field to origin/dev's; swipe-bench.py, typical fingers:
pt 96.3% first word right, 99.5% typed or in the strip over 11,580 swipes, the other six as in the
README table. Not yet checked on an emulator.

* android typing: an infinitive before "-lo" or "-la" is no Portuguese word of its own

Found on the emulator: typing "obrig" offered "obrigá" in the strip. The counter split "obrigá-lo" at
its hyphen, so 569 infinitives written for an enclitic pronoun ("fazê", "ajudá", "tê") were model
words, offered as readings and completions and once read for "te" ("deverias te esquecer" ->
"tê"). build-layout-model.py now skips a word ending in á é ê í ô that "-lo", "-la", "-los" or
"-las" follows; the rebuilt pt.hextm, pt.valid and pt.capitals take other words in their place.

Verified on the Studio (host JVM, Gradle --no-daemon): quality-gate.py all, pt PASS: 83.81% fewer
errors than raw taps (83.75%), 0.16% correct words changed, 98.30% unambiguous accents, 51.98%
ambiguous, harm 0.27% (0.29%), 7/7, and "te" is no longer changed in the clean replay; the other
six identical field for field to origin/dev's. testDebugUnitTest passes. swipe-bench.py: pt 96.3%
first word right, 99.5% typed or in the strip over 11,581 swipes; the other six unchanged.

* android typing: no Portuguese word writes ç before e or i

Found on the emulator: a swiped "voce" offered "voçê" in the strip. Portuguese never writes ç
before e or i, so build-layout-model.py drops such spellings (5 model words: voçê, voçe, conheçe,
tropeçe and a Turkish club's name); the rebuilt pt.hextm, pt.valid and pt.capitals take other words
in their place. The benchmark README also records the emulator check in an outside app.

Verified with quality-gate.py, testDebugUnitTest and swipe-bench.py on the Studio after the merge of
dev that follows (numbers in that merge's pull request update).
2026-11-24 19:06:14 -05:00

21 lines
4.9 KiB
Text

# Portuguese typing model inputs (build-layout-model.py pt), each fetched once and checked
# against its size and SHA-256 before it is read. name<TAB>URL<TAB>fetched<TAB>bytes<TAB>SHA-256<TAB>licence
# The Leipzig files are the collection's downloadable corpora, never its website or API (CC BY-NC).
# The two ParlaIbero CSVs are Harvard Dataverse files 14215092 and 14215091 (MD5 53bc8b49…109e and
# 41218de9…1f05 as Dataverse lists them).
por-br_newscrawl_2011_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por-br_newscrawl_2011_1M.tar.gz 2026-11-24 203913314 c475fc95216aebc1a67ba68df106431a99c1419ab227f2daa06ded0042dbae1f Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_news_2019_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_news_2019_1M.tar.gz 2026-11-24 255233335 8a3fa261ab8770fffd10a7b1e258af758bceddaa45e1e3c4db9e6a0ce281d253 Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_news_2020_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_news_2020_1M.tar.gz 2026-11-24 257037716 a16196fbada20f3caa3b16a9a2adf4dffbcfad22d717b4b48b1a3d5f66669bc6 Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_news_2022_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_news_2022_1M.tar.gz 2026-11-24 261345429 0790deb8e6e987b2b8760bbfb58f8c81d7450bc605251c574d9f0985e63d420d Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_news_2023_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_news_2023_1M.tar.gz 2026-11-24 264635963 aed65cdbbfa66521c1ba12fe6d6fe66dda820940c6f537d1d7a39fd0d2880573 Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_news_2024_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_news_2024_1M.tar.gz 2026-11-24 265333698 cc8560f85eeea797ed9ddd5e8d3b8a3db5daea694f4b8272e20be8622c6ed865 Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_newscrawl_2011_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_newscrawl_2011_1M.tar.gz 2026-11-24 193103780 eed509ebc8e4d286f041162fc19a4ec7f0f75182c0f3df42dda7d0148ab579a7 Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_newscrawl_2015_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_newscrawl_2015_1M.tar.gz 2026-11-24 253984467 5c35c98675b0cac06088da394ccfd9ca430a3596a62e76b5db20ae37dd77b81f Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_newscrawl_2016_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_newscrawl_2016_1M.tar.gz 2026-11-24 253377525 3ddda51f6709879944a7980c52b4d825eab5d7e4ba05c69506dc62e72e5fdd4c Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_newscrawl_2018_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_newscrawl_2018_1M.tar.gz 2026-11-24 255852777 a060739d8060ffcf391fc0aaaddc2a148300de71fd66d7c0642e422b0336b110 Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por_newscrawl_2020_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por_newscrawl_2020_1M.tar.gz 2026-11-24 268434695 4aa0a1bef4e7524bad024d67c9ae3e449fa03550985d0707c2d3a037c2bf196b Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por-pt_newscrawl_2011_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por-pt_newscrawl_2011_1M.tar.gz 2026-11-24 241962491 3ff73a934ca4c35b27e106d725bab12cfdf8b54ef08d46331cb7e1fc7133f25a Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por-pt_web_2014_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por-pt_web_2014_1M.tar.gz 2026-11-24 254603893 7ff4e8966138b5ea3832378b846f989e536d92e2d27ada1ab38133e91219c146 Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
por-pt_web_2015_1M.tar.gz https://downloads.wortschatz-leipzig.de/corpora/por-pt_web_2015_1M.tar.gz 2026-11-24 265546940 362960b9176f6a1185aa86d5ee642b3e644c05df5181c810754be50af70d504a Leipzig Corpora Collection download, CC BY 4.0 (downloads only; https://wortschatz-leipzig.de/en/usage)
BR_interventions.csv https://dataverse.harvard.edu/api/access/datafile/14215092 2026-11-24 1527460901 a2371495c5d2096f052e185e88ee02fd151e427d8b159bbcff213063c8775078 ParlaIbero-BR v2, Rodrigues-Silveira 2026, doi:10.7910/DVN/VTXNW3, CC BY 4.0
PT_interventions.csv https://dataverse.harvard.edu/api/access/datafile/14215091 2026-11-24 1199719582 2acd628564da99eafeb3b076e6d554a3d4a30b3d2f3d387598f63b151f203392 ParlaIbero-PT v2, Rodrigues-Silveira 2026, doi:10.7910/DVN/VRPUFU, CC BY 4.0