The decision model
- Keyscase, Shift
- Rulestwo scores per key
- Modelbidirectional GRU
- Per keyChinese or English
- CompositionBlendKey
▲ Every key press reruns this on the keys not yet committed.
What it decides
Zhuyin keys sit on the same keys as Latin letters, so the same keys often spell both Zhuyin and English: ai is ㄇㄛ and also AI, 2 is ㄉ and also a digit. For every key in the composition, Rong Zhuyin decides Chinese or English; the Chinese part then goes to BlendKey’s character selection.
Why not rules alone
Rules say: keys that can’t form Zhuyin are English, words in an English dictionary are English. Without mistakes, good rules are already accurate. One mistyped key, though, breaks the Zhuyin and the rules turn that stretch into English. The model looks at the whole run of keys and recognises mistyped Zhuyin.
The model
| Input | Each key (with case), plus two rule-based scores: whether the key sits inside a valid Zhuyin syllable or a dictionary word, and how far apart the best “Chinese” and “English” readings of the whole run are (from word frequencies and an English letter model). |
|---|---|
| Network | Two bidirectional GRU layers of 128 units, reading up to about 60 uncommitted keys at once. |
| Output | The probability that each key is Chinese. On commit or punctuation an end marker is added, so a half-typed syllable is no longer treated as unfinished. |
| Size | About 460k parameters, stored as 8-bit integers: about 0.5 MB. |
| Speed | About 0.6 ms per decision on Apple silicon (40 keys, excluding character selection). |
| Runs | In Swift, inside the input method on your Mac. No network. |
Training data
- Chinese: Wikipedia, Common Voice Traditional Chinese sentences, and about 12,000 everyday sentences generated with the open model Qwen (Apache 2.0).
- English: English Wikipedia, Common Voice English sentences and Taskmaster dialogues; the frequency of English acronyms and names comes from English mixed into Chinese Wikipedia.
- Sentences are turned into Dachen key presses with human habits added: Zhuyin parts in a different order, about 2% wrong keys, spaces or none around English, capitals, half-typed sentences, and numbers before measure words, versions and dates.
About five million key sequences in total, trained on the author’s own machine (RTX 4090).
How it was tested
About 7,000 sentences the author actually typed and the model never saw (4,000 Chinese only, 2,000 mixed, 1,000 with numbers), replayed as key presses with the same typing habits. They are used only for testing. Share of sentences with every key right:
| Rules only | Rules + model | |
|---|---|---|
| Chinese only, no mistakes | 98.5% | 99.6% |
| Chinese only, 2% mistyped | 79.9% | 98.0% |
| Mixed, no mistakes | 95.2% | 95.2% |
| Mixed, 2% mistyped | 77.5% | 92.3% |
| With numbers | 88.1% | 88.0% |
“Rules only” uses the same dictionary and English frequencies without the model. When the model says it is 90% sure, it is right about 90% of the time (calibration error 0.07%), so the input method can mark the places it is unsure about.
What it can’t do
- A single English letter without Shift is hard for anyone and often becomes Zhuyin.
- Words only you use may be wrong the first time; after one Tab fix they are remembered.
- Keys that genuinely spell both (2 萬 and 斷) are decided from context, not always correctly.
- With no mistakes and common English words, the model is about as accurate as good rules; its main job is to keep mistyped input from falling apart.
Open source and data
Based on BlendKey (MIT); dictionary from McBopomofo (MIT); English word list from Bopomix (MIT). Training text from Wikipedia (CC BY-SA), Common Voice (CC0) and Taskmaster (CC BY 4.0); everyday sentences generated with Qwen (Apache 2.0).