The multilingual input-method model of Zhiyi IME: 8 ModernBERT layers of width 384 (the mmBERT-small tokenizer, 100,000 of its tokens kept), one shared hashed n-gram memory table (2,000,003 rows × 64, stored as product quantization, 32 MB) and a 4-layer next-word decoder, in one ONNX file. It does three things:
char_logits), in Simplified
and Traditional Chinese and Japanese;你的作业|了吗, "your homework | yet?"), and, when asked for, single characters
(new: 就, 要, 的 in Chinese, Traditional Chinese and Japanese, what phone keyboards offer after a word).It replaces ml-flash-next-preview-1114 in this repository (1114 stays in its history and in its GitHub release). What is new:
Việt, Hà, Nguyễn): 3.3% of Vietnamese tokens read <unk>; with this one under 0.3% do.Against 1114 (PyTorch, the table as stored, PQ16): the neutral word-choice sets v2 / v3 / v4 / v5 93.78 / 93.67 / 91.70 / 73.43% instead of 93.46 / 93.58 / 90.78 / 72.32%; Simplified Chinese long input 84.5% instead of 83.0%; Traditional and Japanese composition up by 0.5-1.3 points (whole rows); next words better in every language (the text's word first: Simplified Chinese 14.3% instead of 12.5%, Japanese 14.0% instead of 10.9%, Vietnamese 19.3% instead of 14.1%); mid-text and single characters, which 1114 never learned, 20.2% and 30.4% (Simplified Chinese) instead of 3.5% and 2.8%. Lower by 0.1-0.6 points: the three English word-choice sets (89.3% instead of 89.9%, web text 87.1% instead of 87.3%, completion 85.8% instead of 86.1%), Zhuyin (bopomofo_tw) 91.5% instead of 92.0%, Quick 3, the Japanese whole-sentence set and Korean; and with single characters allowed, the Chinese positions whose next unit is a word of two or more characters (12.2% instead of 14.2%: the single characters now compete for the first place). Tables under "Accuracy".
The price is size: the w8 file is 115 MB (1114: 94 MB), the slim file 91 MB (64 MB), 32 MB of each being the table; the compute per row is 1114's plus the table's lookups and two small projections (speed below). A preview: Zhiyi IME does not use it. All Zhiyi models: https://github.com/dd1000001000/zhiyi_models
| File | |
|---|---|
model.safetensors |
all weights (182 MB): matrices F16, quantized to Q8_0 when loading (below) to get the accuracy measured here; the n-gram table as PQ16 codes + codebooks |
config.json |
the structure (with encoder.layer_types), prefix_mask, shared_head, next_word_decoder, special tokens, sequence settings, ml (language tags, typed-text length, tone stride), ngram (the table: its keys and hash), next_word (the decoder), vocabulary and quantize_q8_0: the tensors to quantize |
next_rows.json |
the decoder's rows (= the token table's rows): token ids, pieces, the six languages' masks (allow_*, first_*, cont_*), the end row, langs, cjk, lang_tags, context_tokens |
tokenizer.json |
mmBERT's tokenizer (Gemma vocabulary, 256,000 tokens), unchanged: vocab_remap maps its ids to the 100,000 rows |
unified_vocab.json |
the 3,805 units, 28 letters, 9,067 characters and the other tables |
test_vectors.safetensors |
16 word-choice / composition inputs and 18 next-word inputs (2 a language, 2 completions, 2 mid-text, 2 with single characters) with the PyTorch model's outputs, to check an implementation |
candle_ref/ |
a reference forward pass in Rust (candle 0.11), version 0.11.0: reads this file and the table |
onnx/int8/ |
laya.one.next.w8.onnx (115 MB): the one graph (word choice and composition with a KV cache, and the next-word decoder), with its tokenizer and JSON files |
onnx/slim/ |
laya.one.next.slim.onnx (91 MB): the same graph with the token table and the unit embeddings in 4 bits; same inputs and outputs |
example.py |
the quick start below |
LICENSE |
Apache License 2.0 |
1114's onnx/int8/laya.int8g.onnx (word choice and composition without a cache, the whole sequence at once) has no
1130 counterpart: the one graph does both, and its context mode alone is that graph's first half.
Word choice, composition and next words with onnx/int8/laya.one.next.w8.onnx (the code is in example.py):
pip install onnxruntime tokenizers numpy huggingface_hub
python example.py
D = os.path.join(snapshot_download("zhiyi-ime/zhiyi-ml-flash", allow_patterns=["onnx/int8/*"]), "onnx", "int8")
tok = Tokenizer.from_file(os.path.join(D, "tokenizer.json")) # context, tags, typed text and candidates
BOS, EOS, MASK = 2, 1, 4
# 1. Word choice: <bos> context <eos> | <mask> x syllables <eos> <mask> cand1 <mask> cand2 ... <eos>
# (context mode on the leading block, then key mode on the rest with that cache; each candidate's score is read
# at the <mask> before it; ctx_tail = the context's last two tokens, for the table's candidate keys)
print(choose("今天天气很好,我们去公园", ["san", "bu"], ["散步", "散布", "三部"]))
# 2. Composition: <bos> "已输入的上文: " + context <eos> | <mask> x syllables <eos>; one character per slot
print(compose("明天早上八点", "wo men zai xue xiao men kou jian mian".split()))
# 3. Next words: context mode once with need_cross (the context's and the table's keys and values), then is_step in
# a beam search
print(next_words("今天天气很好,我们一起去"))
print(next_words("Thank you very much for your", "en"))
print(next_words("今天天氣很好,我們一起去", "hant"))
print(next_words("我们明天去公", min_chars=1)) # completion: the typed start of the word ends the context
print(next_words("你的作业", right="了吗")) # mid-text: <bos> left <mask> right <eos>
print(next_words("他说下班以后", min_chars=1)) # single characters too (phones)
Output (ONNX Runtime 1.30.0, CPU):
[('散步', 2.99...), ('三部', -7.13...), ('散布', -7.29...)]
我们在学校门口见面
[('看看', -2.98...), ('上海', -3.89...), ('深圳', -4.12...), ('北京', -4.42...), ('武汉', -4.47...)]
[('support', -2.37...), ('visit', -3.06...), ('work', -3.16...), ('help', -3.64...), ('feedback', -3.73...)]
[('看看', -3.52...), ('深圳', -3.71...), ('上海', -4.17...), ('這裡', -4.21...), ('海灘', -6.05...)]
[('园', -1.48...), ('司', -1.99...), ('交', -2.42...), ('车', -2.99...), ('共', -3.05...)]
[('结束', -1.22...), ('完成', -2.51...), ('开始', -2.95...), ('毕业', -3.82...), ('成功', -3.98...)]
[('就', -2.12...), ('会', -2.45...), ('要', -2.53...), ('还', -3.30...), ('我', -3.67...)]
The calls build the inputs of test_vectors.safetensors cases 0, 5, next0, next3, next4, next12, next14
and next16 (token for token); the int8 graph's words differ a little from the vectors' PyTorch ones (next0:
北京, 武汉 in place of 吃火锅, 玩儿; next3: visit in place of attention; the first word
is the same in all of them). In case 0 the other two candidates are tied in PyTorch (−7.22 both), so their order can
flip. Japanese, Korean and Vietnamese work the same way (next_words(text, "ja"), "ko", "vi"): the
language's tag from next_rows.json lang_tags goes after <bos>. For the slim file, set FLASH_DIR to a local
onnx/slim folder and GRAPH=laya.one.next.slim.onnx (same inputs and outputs); FLASH_DIR alone (a local
onnx/int8) skips the download.
One input is_step (bool scalar) picks the mode; an If node runs only that mode's branch. Every input has a small
default, so ONNX Runtime lists them as overridable initializers, not as graph inputs (get_overridable_initializers());
feed them by name as usual and leave out what the mode does not use.
is_step false (the default): word choice and composition with a KV cache: input_ids, unit_ids, past_enc_k /
_v (8 × 1 × 6 × P × 64), past_choice_k / _v (2 × 1 × 6 × P × 64), past_mask, marker_pos, slot_pos,
ctx_tail (1 × 2: the context block's tokens at positions n−3 and n−2, before its <eos>; −1 when the block
has under 3 tokens) → logits, char_logits, present_0 … present_3 (the encoder's and the head's keys and
values), and cross_k_out / cross_v_out (4 × 1 × 6 × (T + 4) × 64) with cross_mask_out (1 × (T + 4), bool):
the decoder's cross-attention keys and values of the tokens just run and of the table's four positions, computed
only when the input need_cross (bool scalar, default false) is true. Run the leading block <bos> … <eos> once per
context (no past) to get the cache, then on each key only the rest with the cache as the past, marker_pos and
slot_pos counted from the start of the rest. Pass the same ctx_tail in both modes (context mode does not read
it): a candidate's first tokens and the first syllables are keyed on the context's last tokens in the table.need_cross true on <bos> [tag] encode(context)[last 128 tokens] <eos>
(mid-text: <bos> [tag] left <mask> right <eos>, below) with unit ids 0 (Korean, Vietnamese, English: the
context's trailing spaces cut first). This is the block word choice runs, so an input method gets the next word's
keys and values in the same call as its context cache.is_step true: one decoder step for N hypotheses: prev (N, the previous row; any value at position 0), pos
(N, 0 = start), dec_past_k / dec_past_v (4 × N × 6 × P × 64) with dec_past_mask (N × P) = the earlier steps (at
position 0 a placeholder of length 1 with the mask false), cross_k / cross_v / cross_mask = the context's, one
copy per hypothesis (cross_mask from cross_mask_out) → logits (N × 100,000 rows), present_0 / present_1 =
the decoder's keys and values with this step appended.Quantization: the encoder, head and decoder matrices are dynamic int8 (DynamicQuantizeMatMul); only the shared token
table is weight-only (MatMulNBits in blocks of 32: 8 bits in w8, 4 bits in slim, where the unit embeddings are 4-bit
too), and the inputs read their rows from the read-out's quantized weight, so the token table is stored once. The
n-gram table is stored once too, as its PQ16 codes, and every lookup (encoder keys, slot keys, the decoder's four
positions) reads it. The hashes run on the raw token ids (before zhiyi_vocab_remap), as in training.
Speed (ONNX Runtime 1.30.0, CPU, AMD Ryzen 5 9600X, median; 1130 and 1114 timed in turn in one process while another training used part of the CPU, so compare the columns rather than read the times as absolute; the search loop around the graph not counted; 300 pages of neutral v2, 300 Simplified and 300 English next-word test contexts):
| 1130 w8 | 1130 slim | 1114 w8 | 1114 slim | |
|---|---|---|---|---|
| Word choice, context mode (once per context), 4 threads / 1 thread | 6.35 / 9.40 ms | 6.79 / 9.40 ms | 5.99 / 8.77 ms | 6.00 / 9.15 ms |
| Word choice, a key, 4 threads / 1 thread | 5.01 / 6.80 ms | 5.26 / 6.92 ms | 4.55 / 6.34 ms | 4.60 / 6.76 ms |
| A whole next-word prediction, Chinese, 4 threads / 1 thread | 14.8 / 25.7 ms | 14.7 / 24.4 ms | 13.4 / 23.0 ms | 12.3 / 21.9 ms |
| A whole next-word prediction, English, 4 threads / 1 thread | 12.3 / 18.9 ms | 12.0 / 18.5 ms | 11.9 / 19.7 ms | 11.1 / 19.3 ms |
The table's lookups and projections cost about 5-10% on word choice and on Chinese next words.
One RTX 5090, about 45 hours (sharing the card with another training), from ml-flash-next-preview-1114, the whole model, 421,393 steps over the data once (warm-up 2,000 steps, the last 10% decayed; learning rate 3e-4, encoder 3e-5, table 1e-3). Every step: 320 next-word rows, 64 word-choice rows and 32 composition rows.
min_chars picks
whether single characters may end it), and every number here is of that graph.Names are the PyTorch ones. Matrices F16, vectors and the decoder's 1-D tensors F32.
| Tensor | Shape | |
|---|---|---|
encoder.embeddings.tok_embeddings.weight |
100000 × 384 | the kept rows (see vocab_remap); also the decoder's input table and read-out |
vocab_remap |
256000 | I32: token id → row (tokens outside the kept set → <unk>'s row, the last) |
encoder.*, unit_emb.weight, tone_emb.weight, type_emb.weight |
as 1114 (8 layers; type_emb[0] is the one used) |
|
head.layers.{0,1}.*, scorer.*, out.*, char_emb.weight, char_bias |
as 1114: the shared head, word choice, composition | |
ngram.codes |
2000003 × 16 | U8: the table's PQ16 codes; row r = concat over p of ngram.codebooks[p, codes[r, p]] (64 values) |
ngram.codebooks |
16 × 256 × 4 | the PQ16 codebooks |
ng_proj (128 → 384), ng_sproj (128 → 384) |
the encoder-input projections of the token keys / the slot keys | |
next.mem_in.0 (384 → 384), next.mem_in.1 (LayerNorm) |
the decoder's memory | |
next.mem_proj (64 → 384), next.mem_norm (LayerNorm), next.mem_type |
4 × 384 | the decoder's four table positions |
next.tok_in (384 → 384) |
a row's embedding → the decoder's input | |
next.start |
384 | the input at position 0 |
next.pos.weight |
22 × 384 | learned positions |
next.layers.N.* (N = 0…3) |
nn.TransformerDecoderLayer: self_attn, multihead_attn (in_proj_weight = q, k, v stacked, 1152 × 384), linear1 (384 → 1536), linear2, norm1-norm3 |
|
next.out.0 (LayerNorm), next.out.1 (384 → 384) |
the decoder's output | |
next.bias |
100000 | the read-out's bias, one per row; −10000 on the rows no language writes |
The 72 tensors listed in config.json quantize_q8_0 (every linear weight of the encoder, the head, the table's
projections and the decoder) go to Q8_0: blocks of 32 along the input dimension, one f16 scale per block; so does the
decoder's read-out (the token table). With candle:
use candle_core::quantized::{GgmlDType, QMatMul, QTensor};
let w = safetensors.load(name, &device)?.to_dtype(DType::F32)?;
let w = QMatMul::from_qtensor(QTensor::quantize(&w, GgmlDType::Q8_0)?)?;
// w.forward(&x) = x · wᵀ, then add the bias if the layer has one
Keep the embeddings unquantized where they are indexed and everything 1-D in F32.
One sequence at a time, with the prefix mask: positions up to and including the first <eos> attend only to
themselves, in every encoder and head layer; the positions after them attend to everything.
x = tok_emb[vocab_remap[input_ids]] + unit_emb[unit_ids % 3833] + tone_emb[unit_ids / 3833] + ng(…), then
LayerNorm. ng is the table's part (all keys over the raw token ids; hash below):<bos>, before the first <eos>) and every candidate token (from
the first marker on, up to the final <eos>) adds ng_proj([row(k2); row(k3)]), k2 = hash(1; prev1, tok),
k3 = hash(2; prev2, prev1, tok); for a candidate's tokens prev1 / prev2 count from the latest marker at or before
the token, the context's last two tokens standing before it (that is what ctx_tail carries in the graph);ng_sproj([row(kb); row(kt)]),
kb = hash(5; u_prev, u) after a slot, else hash(7; c1, u); kt = hash(6; u_prev2, u_prev, u) after two slots,
hash(8; c1, u_prev, u) after one, else hash(9; c2, c1, u); c1 / c2 = the context's last / second-last token.full_attention), the others a window of ±64 (sliding_attention); exact GELU in the gated MLP; no biases.h0 = encoder output + type_emb[0], then the two head layers (nn.TransformerEncoderLayer,
norm_first=True, 6 heads, feed-forward 1536, ReLU), with the prefix mask.score = scorer.3(gelu(scorer.1(scorer.0(h0[marker])))) at each candidate's <mask>. Higher is
better.char_logits = out.1(out.0(h0[slot])) · char_embᵀ + char_bias, compared within the characters the
slot's unit spells in the row's language.Caching the context. Run the block alone once per context and keep each layer's keys and values; on each key run only the positions after it.
<bos> [encode(tag)] encode(context)[last 128 tokens] <eos> with unit ids 0 (Korean,
Vietnamese, English: the context's trailing spaces cut first; mid-text: below), through the encoder:
m = LayerNorm(next.mem_in.0(encoder output + type_emb[0])), (T, 384), then four table positions:
next.mem_norm(next.mem_proj(row(key_j)) + next.mem_type[j]) for the keys around the gap g (the <mask>, else the
final <eos>): hash(1; l2, l1), hash(2; l3, l2, l1), hash(3; r1, r2), hash(4; l1, r1) (l1 = the token before the
gap, r1 the one after it; r1 / r2 −7 without a right side). Memory = (T + 4, 384). Each decoder layer's
cross-attention keys and values are the memory through rows 384-767 and 768-1151 of its
multihead_attn.in_proj_weight (and bias): once per context.next.start; position j ≥ 1 is next.tok_in(E[r_j]), E =
tok_embeddings, r_j the row written at step j; plus next.pos.weight[j].nn.TransformerDecoderLayer, norm_first=True, 6 heads of 64, LayerNorm eps 1e-5, no dropout):
x += self_attn(norm1(x)) causal; x += multihead_attn(norm2(x), memory); x += linear2(relu(linear1(norm3(x)))).logits = next.out.1(next.out.0(x)) · Eᵀ + next.bias over the 100,000 rows.Search (as example.py and candle_ref): beam 8, k = 5 words, at most 6 tokens a word; the language's masks from
next_rows.json (disallowed rows −10⁹ before the log-softmax):
zh), Traditional (hant), Japanese (ja): any allow_* row, then allow_* rows or the end. A
word is its rows' pieces joined (none of them starts with ▁), kept with at least 2 characters (min_chars 2), or
with single characters too (min_chars 1: completion, and the phone-style list where 就, 的 and words are ranked
together).en), Korean (ko): a first_* row (a ▁ word start) first, then cont_* rows (pieces) or the end.
Vietnamese (vi): a first_* row first, then any allow_* row (more ▁ syllables: words of several syllables)
or the end. The word is the pieces joined with ▁ as a space, stripped; English and Vietnamese lower-cased.allow_* row (Chinese, Japanese), a cont_* piece (English, Korean) or any allow_vi row; the
words found are the rest of the word.<bos> [tag] left <mask> right <eos> with right = encode(text after the cursor)[:32] and the left
side cut so that the block is no longer than without a right side (128 tokens of text); the words are the ones that
fit the gap.Token ids are tokenizer.json's, <bos> (2) as [CLS], <eos> (1) as [SEP], <mask> (4); text encoded without
special tokens. A row in Traditional Chinese, Japanese, Korean or Vietnamese starts with its tag as plain text
(<zh-Hant>, <ja>, <ko>, <vi>); Simplified Chinese and English have none. The composition prefix
已输入的上文: ("text typed so far: ") is literal model input.
word choice (zh, en) <bos> encode(context)[last 128] <eos> <mask> × typed units <eos> <mask> encode(" 候选1")[:16] … <eos>
word choice (others) <bos> encode(tag) encode(context)[last 128] <eos> encode(typed text)[:24] <eos> <mask> encode(" 候选1")[:16] … <eos>
composition <bos> [encode(tag)] encode("已输入的上文: " + context) <eos> <mask> × slots <eos>
next word <bos> [encode(tag)] encode(context)[last 128] <eos>
next word, mid-text <bos> [encode(tag)] encode(left)[last 127 − len(R)] <mask> R = encode(right)[:32] <eos>
test_vectors.safetensors: word-choice / composition cases i = 0…15 (i.input_ids full-vocabulary ids,
i.unit_ids, i.marker_pos, i.slot_pos, PyTorch's i.logits / i.char_logits); next-word cases nextN,
N = 0…17: nextN.input_ids (the prefix block), nextN.mode (the language's index in langs: 0 zh, 1 en, 2 hant,
3 ja, 4 ko, 5 vi), nextN.min_chars, nextN.comp (1 = completion; cases 12 and 13; 14 and 15 are mid-text, 16 and
17 Chinese with min_chars 1) and PyTorch's 5 words nextN.text (UTF-8, one a line) with nextN.logp. The Q8_0 model agrees with the word-choice and composition outputs to about 2.19 and picks the same best candidates and characters in 15 of 16 cases (case 7, a partly typed syllable j g, differs in one character in all three files); on the next-word cases it gives the same first word in 18 of 18, the same 5 words in 15. The w8 ONNX file: the same first word in 15 of 18, the slim one in 17.
The model alone, not the IME end to end. Spot checks of the shipped files against PyTorch fp32 (the model as
exported: the table as PQ16, the 100k vocabulary): the first 300 rows of each Traditional, Japanese, Korean and
Vietnamese test file and every third row of the Simplified Chinese and English sets; Q8_0 = this file through
candle_ref; w8 / slim = the two ONNX files. Next word: the first 200 rows of each language's test set, 100 words cut
inside (completion), 100 mid-text rows (Simplified, English) and 100 natural-mix rows with min_chars 1 (Simplified).
Small sets: a row is a third or half a point.
| Word choice, first candidate right | fp32 | Q8_0 (candle_ref) |
w8 ONNX | slim ONNX |
|---|---|---|---|---|
| Simplified Chinese, words and word pairs (2175) | 88.1% | 88.1% | 88.1% | 88.1% |
| Simplified Chinese, long input (749) | 84.0% | 84.2% | 83.6% | 83.4% |
| English (729) | 90.3% | 90.1% | 89.8% | 90.0% |
| Simplified Chinese, IME's real candidates (545) | 89.5% | 89.5% | 89.5% | 89.9% |
| Simplified Chinese homophones with the previous sentence (267) | 91.8% | 91.8% | 91.8% | 91.8% |
| English word completion (280) | 85.7% | 85.7% | 84.3% | 85.4% |
| Traditional, pinyin (luna_pinyin) (300) | 84.7% | 84.7% | 85.7% | 84.3% |
| Traditional, Zhuyin (bopomofo_tw) (300) | 89.0% | 89.0% | 89.0% | 90.0% |
| Traditional, Zhuyin (libchewing) (300) | 94.7% | 94.7% | 95.0% | 95.3% |
| Traditional, Jyutping (jyut6ping3) (300) | 89.3% | 89.3% | 89.3% | 87.7% |
| Traditional, Cangjie 5 (300) | 96.0% | 96.0% | 96.0% | 96.0% |
| Traditional, Quick 5 (300) | 87.7% | 87.7% | 87.7% | 86.3% |
| Traditional, Cangjie 3 (300) | 84.0% | 84.0% | 83.0% | 83.0% |
| Traditional, Quick 3 (300) | 78.0% | 78.0% | 77.3% | 77.7% |
| Japanese, conversion (Mozc) (300) | 93.3% | 93.3% | 93.7% | 93.3% |
| Japanese, prediction (Mozc) (300) | 88.7% | 89.0% | 88.3% | 87.7% |
| Japanese, whole sentence (Mozc) (300) | 94.7% | 94.7% | 94.7% | 94.7% |
| Korean, word completion (300) | 63.3% | 64.0% | 64.0% | 64.7% |
| Vietnamese, without diacritics (300) | 89.7% | 90.0% | 89.3% | 90.0% |
| Vietnamese, first letters (300) | 74.7% | 74.7% | 75.0% | 74.0% |
| Composition, whole rows / characters right | fp32 | Q8_0 (candle_ref) |
w8 ONNX | slim ONNX |
|---|---|---|---|---|
| Simplified, long pinyin in full (300) | 62.7 / 87.4% | 62.3 / 87.8% | 60.3 / 86.9% | 60.3 / 87.1% |
| Traditional, pinyin (300) | 41.7 / 73.9% | 41.0 / 73.5% | 39.3 / 73.2% | 39.0 / 72.8% |
| Traditional, Zhuyin (70% with tones) (300) | 68.0 / 92.0% | 69.7 / 92.4% | 70.0 / 92.3% | 70.3 / 92.6% |
| Traditional, Jyutping (300) | 42.7 / 74.9% | 42.3 / 74.4% | 41.7 / 73.5% | 41.0 / 73.4% |
| Japanese, kana (300) | 72.0 / 96.3% | 69.7 / 96.1% | 69.7 / 96.1% | 69.3 / 96.1% |
| Next word @1 / @5 | fp32 | Q8_0 (candle_ref) |
w8 ONNX | slim ONNX | first word = fp32's (Q8_0 / w8 / slim) |
|---|---|---|---|---|---|
| Simplified Chinese (200) | 16.5 / 24.5% | 16 / 24.5% | 18 / 23.5% | 17 / 24% | 93% / 73.5% / 72.5% |
| English (200) | 20 / 38% | 19.5 / 38% | 20 / 36% | 18.5 / 38.5% | 96.5% / 81.5% / 78.5% |
| Traditional Chinese (200) | 13 / 23% | 13 / 22.5% | 13 / 21% | 12.5 / 21% | 93.5% / 69.5% / 64.5% |
| Japanese (200) | 13 / 25% | 13 / 24.5% | 11.5 / 23% | 11.5 / 23% | 96% / 69% / 65% |
| Korean (200) | 6.5 / 15% | 6.5 / 14.5% | 5.5 / 13.5% | 6 / 13.5% | 94.5% / 68% / 63% |
| Vietnamese (200) | 26.5 / 43.5% | 26.5 / 43.5% | 25.5 / 43% | 23.5 / 42% | 99% / 78% / 73.5% |
| Completion, Simplified (100) | 58 / 74% | 57 / 76% | 54 / 73% | 52 / 74% | 98% / 85% / 81% |
| Completion, English (100) | 32 / 39% | 32 / 39% | 32 / 42% | 31 / 41% | 96% / 72% / 68% |
| Completion, Traditional (100) | 56 / 80% | 56 / 80% | 59 / 76% | 57 / 75% | 98% / 86% / 87% |
| Completion, Japanese (100) | 57 / 77% | 57 / 77% | 56 / 74% | 54 / 72% | 98% / 88% / 86% |
| Completion, Korean (100) | 33 / 49% | 33 / 49% | 29 / 49% | 27 / 51% | 98% / 71% / 60% |
| Completion, Vietnamese (100) | 66 / 82% | 67 / 82% | 66 / 82% | 67 / 83% | 98% / 86% / 87% |
| Mid-text, Simplified (100) | 22 / 34% | 22 / 34% | 20 / 35% | 21 / 33% | 97% / 73% / 72% |
| Mid-text, English (100) | 35 / 51% | 35 / 50% | 34 / 51% | 32 / 53% | 97% / 72% / 69% |
Any next unit, Simplified (min_chars 1) (100) |
27 / 40% | 27 / 39% | 26 / 41% | 27 / 41% | 100% / 82% / 76% |
The Q8_0 file follows PyTorch closely (the same first next word in 93-100% of rows); the int8 ONNX files move more (dynamic per-tensor int8 for the matrices: the same first word in 60-88% of rows), with set scores within about two points either way.
On the full test sets, against ml-flash-next-preview-1114 (PyTorch fp32; 1130 with its table as stored, PQ16, and the 100,000-row vocabulary; first candidate right, the row's best):
| Word choice | 1114 | 1130 |
|---|---|---|
| Simplified Chinese, words and word pairs (6523) | 87.6% | 88.1% |
| Simplified Chinese, long input (2247) | 83.0% | 84.5% |
| Simplified Chinese web text, short / long (1001 / 344) | 91.3 / 90.1% | 92.1 / 91.3% |
| English (2189) | 89.9% | 89.3% |
| English web text (426) | 87.3% | 87.1% |
| Simplified Chinese, IME's real candidates (1634) | 88.4% | 89.1% |
| Simplified Chinese homophones with the previous sentence (800) | 89.6% | 90.4% |
| English word completion (840) | 86.1% | 85.8% |
| Traditional, pinyin (luna_pinyin) | 85.4% | 86.1% |
| Traditional, Zhuyin (bopomofo_tw) | 92.0% | 91.5% |
| Traditional, Zhuyin (libchewing) | 96.2% | 96.5% |
| Traditional, Jyutping (jyut6ping3) | 90.1% | 90.3% |
| Traditional, Cangjie 5 / Quick 5 | 95.2 / 89.6% | 95.6 / 89.8% |
| Traditional, Cangjie 3 / Quick 3 | 84.9 / 80.4% | 85.8 / 80.1% |
| Japanese, conversion / prediction (Mozc) | 92.1 / 85.1% | 92.2 / 85.5% |
| Japanese, whole sentence (Mozc) | 92.8% | 92.6% |
| Korean, word completion | 60.5% | 60.4% |
| Vietnamese, without diacritics / first letters | 89.4 / 72.7% | 90.8 / 74.5% |
(Traditional, Japanese, Korean and Vietnamese: 3,000 rows each.)
| Composition, whole rows / characters right (3,000 rows each) | 1114 | 1130 |
|---|---|---|
| Traditional, pinyin | 44.0 / 76.5% | 45.1 / 77.1% |
| Traditional, Zhuyin | 73.0 / 93.1% | 73.5 / 93.4% |
| Traditional, Jyutping | 40.6 / 72.9% | 41.1 / 73.4% |
| Japanese, kana | 66.8 / 95.0% | 68.1 / 95.4% |
Next words, the text's word first (@1) / among the 5 (@5), beam 8 (Simplified Chinese 4,941 rows, the others 3,000;
completion: the same rows with the word cut inside; mid-text: the rows whose text goes on after the word, that text as
the right side; "any next unit": the natural-mix test rows with min_chars 1, the text's real next unit as the answer,
split into those where it is a single character and those where it is a word):
| @1 / @5 | 1114 | 1130 |
|---|---|---|
| Simplified Chinese | 12.5 / 24.4% | 14.3 / 25.8% |
| ... with ng1017 (the n-gram of Zhiyi IME) | 12.9 / 24.9% | 14.7 / 27.9% |
| English | 21.5 / 40.4% | 22.6 / 41.4% |
| ... with a trigram of the training text | 21.6 / 41.7% | 22.8 / 42.8% |
| Traditional Chinese | 11.6 / 22.5% | 13.7 / 23.9% |
| Japanese | 10.9 / 21.3% | 14.0 / 26.0% |
| Korean | 8.4 / 15.4% | 9.2 / 16.2% |
| Vietnamese | 14.1 / 29.1% | 19.3 / 36.9% |
| Completion, Simplified / English | 53.1 / 75.0%, 30.1 / 39.1% | 54.5 / 77.8%, 31.8 / 38.8% |
| Completion, Traditional / Japanese | 48.6 / 71.5%, 36.0 / 58.9% | 53.3 / 75.7%, 50.4 / 73.8% |
| Completion, Korean / Vietnamese | 22.1 / 42.2%, 47.0 / 64.8% | 25.2 / 48.1%, 56.3 / 75.2% |
| Mid-text, Simplified / English | 3.5 / 9.6%, 4.4 / 12.6% | 20.2 / 35.8%, 36.0 / 55.6% |
| Mid-text, Traditional / Japanese | 2.3 / 6.0%, 2.3 / 6.5% | 19.2 / 32.9%, 21.6 / 36.5% |
| Mid-text, Korean / Vietnamese | 0.6 / 2.2%, 1.6 / 6.3% | 13.2 / 22.6%, 34.4 / 54.0% |
| Any next unit, Simplified | 9.4 / 18.3% | 19.8 / 35.0% |
| ... single characters | 2.8 / 7.1% | 30.4 / 49.8% |
| ... words of two or more characters | 14.2 / 26.4% | 12.2 / 24.3% |
| Any next unit, Traditional (single characters / words) | 8.3 / 16.4% (4.5 / 11.3%) | 17.2 / 29.3% (25.9 / 10.5%) |
| Any next unit, Japanese (single characters / words) | 8.3 / 16.9% (3.0 / 9.1%) | 12.3 / 24.0% (24.6 / 10.5%) |
(The last two rows' brackets give @1 only.) 1114 was never trained for mid-text or single characters; its numbers there are what an untrained decoder does. Many continuations make sense and only the text's word counts, so the next-word scores are low; the teacher Qwen3-1.7B-Base (1.7B parameters, beam 32) gets 26.2 / 45.5% (Simplified Chinese) and 39.2 / 64.9% (English).
On the public neutral word-choice test sets (v2, v3 web, v4 chat, v5 hard; whole page, first candidate right):
| v2 | v3 | v4 | v5 | |
|---|---|---|---|---|
| ML-Flash-1103, PyTorch fp32 | 93.53% | 93.74% | 91.06% | 71.55% |
| ml-flash-next-preview-1114, PyTorch fp32 | 93.46% | 93.58% | 90.78% | 72.32% |
| ml-flash-next-1130, PyTorch fp32 (table PQ16) | 93.78% | 93.67% | 91.70% | 73.43% |
ml-flash-next-preview-1114, int8 ONNX (laya.int8g.onnx) |
92.7% | 93.2% | 90.5% | 71.0% |
ml-flash-next-1130, int8 ONNX (onnx/int8) |
93.6% | 93.3% | 91.6% | 73.2% |
The ONNX rows are the comparison scorer's (the charts below), the fp32 rows the training code's; the two count the same rows slightly differently.
candle_ref: candle's quantized kernels choose their SIMD code at compile time, so build with
RUSTFLAGS="-C target-cpu=native" (or at least x86-64-v3), otherwise the Q8_0 dot products run scalar code.
cd candle_ref
RUSTFLAGS="-C target-cpu=native" cargo build --release
target/release/zhiyi-ref ../model.safetensors ../test_vectors.safetensors out.safetensors
candle_ref runs the whole sequence with the mask (it does not cache) and reruns the decoder over each hypothesis'
prefix at every step; the outputs are those of the cached runs.
Word choice on the public neutral test sets, each model alone (no engine, no n-gram), against the theoretical compute
to score a row: of the Zhiyi models only the four maintained ones are shown, pumpkin
(zhiyi-ml-pumpkin), Flash (this model), Mini
(zhiyi-zhen-mini-12M) and Feather
(zhiyi-zhen-feather), each scored with its released ONNX file
(this model: onnx/int8/laya.one.next.w8.onnx), so the points can differ a little from the numbers above. The table's
lookups and its two projections are not counted in the compute (as for Mini and Feather, which have tables too). The
other models (the file of each, its license and how it is run) and the scoring code:
https://github.com/dd1000001000/zhiyi_models/tree/main/comparisons/models
These weights are Zhiyi IME's own work and are licensed under the Apache License 2.0 (LICENSE). The reference
code in candle_ref/ is GPL-3.0-only, like Zhiyi IME (https://github.com/dd1000001000/zhiyi_ime/blob/main/LICENSE).
The upstream parts keep their licenses: the Laya architecture (https://huggingface.co/convaiinnovations/laya)
Apache-2.0, the mmBERT-small encoder and tokenizer (Marone et al., 2025; https://huggingface.co/jhu-clsp/mmBERT-small)
MIT. The n-gram table follows the idea of hashed n-gram embeddings read beside a transformer (Engram-style conditional
memory); the design and the code here are Zhiyi's own.
Teachers (only their scores and words were used; none of their weights are in these files): Qwen3.5-9B (https://huggingface.co/Qwen/Qwen3.5-9B) fine-tuned with LoRA for word choice and composition, Qwen3-1.7B-Base (https://huggingface.co/Qwen/Qwen3-1.7B-Base; Simplified Chinese, English) and Qwen3-4B-Base (https://huggingface.co/Qwen/Qwen3-4B-Base; Traditional Chinese, Japanese, Korean, Vietnamese) for next words and mid-text, all by the Qwen team (Alibaba Cloud), Apache-2.0. Next-word text: Chinese text of C4 (Raffel et al.) and LCCC, English text of FineWeb (CC-MAIN-2025-26) and C4, and FineWeb-2 (Penedo et al., ODC-By) in the other languages; the next words segmented with jieba (Chinese), SudachiPy (Japanese) and pyvi (Vietnamese). The short-context word-choice rows: candidates from several input-method engines run on the typed letters (only their candidate lists were used). These programs and data only produced training rows; none of them is in these files.
model.safetensors 174 MiBonnx/int8/laya.one.next.w8.onnx 110 MiBonnx/slim/laya.one.next.slim.onnx 87 MiBtest_vectors.safetensors 1 MiBjhu-clsp/mmBERT-small