English spell checkers live with an open vocabulary: new words, names and compounds appear all the time, so “not in the dictionary” is only a hint. Vietnamese is different, and that difference shaped the whole architecture of Writa.
A language you can enumerate
Vietnamese is written in syllables, and a valid syllable is an initial consonant, a rhyme and a tone. All three come from small, known sets. Generate every legal combination from a phonology table (27 initials × 160 rhymes, with tone rules) and you get 18,261 syllables. That’s the whole space.
So a syllable outside that set isn’t “probably misspelled”. It’s definitely misspelled. Detecting non-word errors becomes a
hash lookup with perfect precision, and a nice side effect is licensing: generating the set ourselves meant not
depending on hunspell-vi, which is GPLv3.
Detection is easy, so correction is everything
The errors people actually make are mostly real-word errors: a valid syllable in the wrong place. The classic is the hỏi/ngã tone confusion, plus s/x, ch/tr and r/d/gi, which depend on regional accents. “cũng cố” instead of “củng cố” passes every syllable check.
Generating candidates by blind edit distance produces mostly nonsense. Writa generates them from structured confusion rules that encode those specific mistakes, and makes any candidate needing two edits clear an extra score margin. A Viterbi decoder over an n-gram language model then picks the most likely sequence.
The same decoder adds missing diacritics. Typing khong co gi without accents is the same problem with a
different candidate generator, so diacritic restoration came almost for free and shipped in v0.1.
The metric that matters is false positives
A real-time checker that underlines correct text gets uninstalled within five minutes. Recall can improve over releases; trust, once lost, doesn’t come back. So the target was set on false positives: under 2 per 1,000 tokens.
Measured on 50,000 held-out sentences from Vietnamese Wikipedia:
| Measure | Result |
|---|---|
| False positives, accented text | 0.25 per 1,000 tokens |
| False positives, unaccented text | 0.24 per 1,000 tokens |
| False positives, real-word layer | 0.55 per 1,000 tokens |
| Precision / recall | 99.6% / 92.5% |
| Latency per word, p99 | 0.54 ms |
Two details did a lot of the work. Protected spans (URLs, emails, file paths, @mentions, hashtags, code, numbers) are never checked at all. And
real-word errors are scored with a two-way association, min(P(b|a), P(a|b)), which separates fixed compounds
from free word combinations. The one-way version kept flagging function words.
What’s still weak
Diacritic restoration reaches 95.2% on ordinary prose but only 92.2% on proper names, missing the 95% overall target. The corpus is Wikipedia, which doesn’t sound like a Zalo chat. Both are on the roadmap: frequencies of capitalised forms for names, and a chat-style corpus for v0.3.