Expand description
Embedded reference EN/RU word frequencies and order-2 character chains.
Each language has two tables, and inference asks each a different question. The lexicon maps a lowercase word to its log10 corpus frequency: it says how common the candidate reading is and whether the typed string is already a word of its own language. The character chain gives the probability of each letter after the two before it, with start and end markers, so it can score any string of the alphabet, including one the lexicon has never seen; inference uses it for the chance that the typed letters were meant as typed.
assets/model.bin is produced by tools/pack-model.py, which documents the layout. Values
are log10 probabilities stored as integer micro-units; dividing by 10^6 reproduces the
correctly rounded parse of the frozen six-decimal source text exactly. Corpus frequencies
are not calibrated layout-error probabilities.
offset 0 "KRMODEL\0" u32 version [u8; 32] source SHA-256 u32 languages = 2
offset 48 per language, en then ru, all little-endian:
u32 L u16[L] alphabet, UTF-16 units
u32 n u32[n + 1] offsets, from 0, increasing
u8[offsets[n]] each word as alphabet indices, words in UTF-16 order
i32[n] log10 frequency of word i, micro-units
i32[S * S * S] log10 P(c | a, b) at (a * S + b) * S + c, micro-units
where S = L + 2: index L is the end marker and L + 1 the start markerThe words are sorted so that a lookup is a binary search; ё (U+0451) sorts after я, although
the alphabet lists it after е. Model::parse checks every count, offset, index and the
order once; each section is then its own slice, and a lookup cannot read past it.
Structs§
- Language
Model - One language’s frequency table and character chain, borrowed from a validated asset.
- Model
- Validated EN and RU models.
Enums§
- Model
Error - Structural reason an asset was rejected; carries no asset content.
Constants§
- MAX_
MODEL_ WORD - Longest stored word in UTF-16 units. Inference treats a longer word as ineligible.