A Chinese / English input-method model of Zhiyi IME: 8 ModernBERT layers of width 256 reading 128 tokens of context, a 32,000-token vocabulary, and one shared hashed n-gram memory table (1,000,003 rows x 64, stored as product quantization, 16 MB) that all three tasks read:
char_logits), through the head word choice uses;你的作业|了吗, "your homework | yet?").It replaces zhen-feather-preview-1121 in this repository and, since Zhiyi IME 1.7.3, in the IME (the ONNX file as released, with the word n-gram ng1017 beside it). In the IME end to end (CPU, quick inputs off): Simplified Chinese 88.2% (1121: 87.4%), long input 75.3% (72.4%), English 89.4% (89.0%); next words with a page of 10 (1000 rows): Chinese on the page 28.8% (28.0%), first 12.9% (14.0%), about 32 ms a prediction (35 ms).
Against 1121 (the model of Zhiyi IME 1.7.2):
onnx/laya.feather.onnx) for everything, instead of 1121's separate word-choice and
next-word graphs (the 4-bit set Zhiyi IME 1.7.2 ships is 56 MB): Mini's 32k vocabulary, and one table instead of a
decoder-only one;zhen-feather-preview-1121 stays in this repository's history and in its GitHub release. All Zhiyi models: https://github.com/dd1000001000/zhiyi_models
| File | |
|---|---|
model.safetensors |
all weights (44.3 MB): the token table, the unit table and the decoder already 4-bit as ggml Q4_0 blocks; the encoder, the head, the composition read-out and the table's two projections F16 (quantized to Q8_0 at load: config.json quantize_q8_0); the n-gram table as PQ16 codes + codebooks; the rest F32 |
config.json |
the structure (with encoder.layer_types), prefix_mask, shared_head, compact, char_count, special tokens, sequence settings (choice_context_tokens 128, max_context_tokens 160 for composition, context_prefix), ml, next_word (the decoder, rows_are_tokens, context_tokens 128), ngram (the table: its token, slot and decoder keys and the hash), vocab_size, q4_0 (each 4-bit tensor's [rows, columns]) and quantize_q8_0 |
next_rows.json |
per token: its piece and text, the mode masks (zh, en_start, en_cont), the end token, characters per token |
tokenizer.json |
the 32k Unigram tokenizer: context, tags, typed text |
tokenizer.candidates.json |
the same with Metaspace prepend_scheme never: candidates, Chinese and English (no leading ▁) |
unified_vocab.json |
the slot units and letters, the 9,067 composition characters (chars, the order of char_emb; char_tokens their 32k token ids) and the readings that say which characters a unit can spell |
test_vectors.safetensors |
13 word-choice, 6 composition and 15 next-word inputs with the fp32 PyTorch model's outputs, to check an implementation |
candle_ref/ |
a reference forward pass in Rust (candle 0.11), version 0.9.0: reads this file (4-bit, F16 and the table) |
onnx/ |
laya.feather.onnx (39.8 MB: word choice, composition and next words in one file, the table included; opset 21 + com.microsoft MatMulNBits / GatherBlockQuantized: the word-choice / composition / context branch 8-bit, the next-word step and the token table 4-bit), with both tokenizers and the JSON files |
example.py |
the quick start below |
LICENSE |
Apache License 2.0 |
Word choice, composition, next words and mid-text with onnx/laya.feather.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-zhen-feather", allow_patterns=["onnx/*"]), "onnx")
tok = Tokenizer.from_file(os.path.join(D, "tokenizer.json")) # context, tags, typed text
ctok = Tokenizer.from_file(os.path.join(D, "tokenizer.candidates.json")) # candidates (no leading ▁)
BOS, EOS, MASK = 2, 1, 4
CTX = 128 # context tokens (word choice and next words)
CTX_P2C = 160 # composition: the context with its prefix
# 1. Word choice: <bos> context <eos> <mask> x syllables <eos> cand1 cand2 ... <eos>; one score per candidate
# (context mode on the leading block, then key mode on the rest with that cache; ctx_tail = the context's last
# two tokens, for the table's candidate and slot keys)
print(choose("今天天气很好,我们去公园", ["san", "bu"], ["散步", "散布", "三部"]))
# 2. Composition: <bos> "已输入的上文: " + context <eos> in context mode, then <mask> x syllables <eos> in key mode
# with slot_pos (no candidates: marker_pos empty); per slot the best character it can spell
print(compose("明天早上八点", "wo men zai xue xiao men kou jian mian".split()))
# 3. Next words: context mode once (cross_k_out / cross_v_out / cross_mask_out: the context and the table's four
# positions), then is_step in a beam search over the 32k tokens
print(next_words("今天天气很好,我们一起去"))
print(next_words("Thank you very much for your", lang="en"))
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>
Output (ONNX Runtime 1.30.0, CPU):
[('散步', 1.92...), ('散布', -5.27...), ('三部', -6.15...)]
我们在学校门口见面
[('看看', -1.52...), ('旅游', -2.40...), ('体验', -4.32...), ('逛逛', -5.04...), ('逛街', -5.04...)]
[('support', -1.66...), ('service', -2.64...), ('help', -2.68...), ('advice', -3.20...), ('appreciation', -3.83...)]
[('司', -1.15...), ('园', -1.55...), ('交', -2.96...), ('交车', -2.97...), ('共', -3.47...)]
[('开始', -2.13...), ('工作', -2.67...), ('完成', -2.73...), ('结束', -3.93...), ('作业', -4.07...)]
The calls build the inputs of test_vectors.safetensors cases 0, 5, next0, next5, next7 and next8 (token for
token); the file's next words differ a little from the vectors' fp32 ones (the same first word in each of these four,
the later words partly another order). Traditional rows add the tag <zh-Hant> after <bos> and the typed text
instead of <mask> units in word choice (see "Inputs"). Set FEATHER_DIR to a local onnx folder to skip the
download.
The bool input is_step picks the branch (an If node runs only that one). 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 and leave out what the branch does not use.
is_step false (the default), word choice and composition: input_ids, unit_ids, past_enc_k /
past_enc_v (8 × 1 × 4 × P × 64), past_choice_k / past_choice_v (1 × 1 × 4 × P × 64) with 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 (one per marker), char_logits (one row of 9,067 per
slot), present_0 … present_3 (the encoder's and the head's keys and values), cross_k_out / cross_v_out,
cross_mask_out. Context mode (the leading block <bos> … <eos>, no past) gives the cache; key mode (the rest, the
cache as the past) gives the scores, with marker_pos and slot_pos counted from the start of the rest. Pass the
same ctx_tail in both modes: a candidate's first tokens and the first slots are keyed on the context's last tokens
in the table. Composition passes an empty marker_pos (1 × 0: no candidates, as trained) and the slots in
slot_pos; word choice reads logits and may pass slot_pos = [[0]].<bos> context[last 128 tokens] <eos> (mid-text:
<bos> left <mask> right <eos>, below) with unit ids 0 → cross_k_out, cross_v_out (4 × 1 × 6 × (T + 4) × 64),
the decoder's cross-attention keys and values of the T context positions and the table's four positions, and
cross_mask_out (1 × (T + 4), all true for one context). In an input method this is the context pass word choice
already runs, when the contexts are the same.is_step true, one next-word step for N hypotheses: prev (N, the previous token; any value at position 0),
pos (N), dec_past_k / dec_past_v (4 × N × 6 × P × 64) with dec_past_mask (N × P; at position 0 a placeholder
of length 1, false), cross_k / cross_v (4 × N × 6 × (T + 4) × 64, one copy per hypothesis) with cross_mask
(N × (T + 4), from cross_mask_out) → logits (N × 32,000, one per token), present_0 / present_1 = the
decoder's keys and values with this step appended.Speed (ONNX Runtime 1.24.4, CPU, AMD Ryzen 5 9600X; the search loop around the graph not counted; 300 pages of neutral v2, 300 Simplified composition rows of the dev set (157 of them in full pinyin) and 100 Chinese next-word test contexts, medians):
| zhen-feather-1127, 4 threads / 1 | zhen-feather-preview-1121, 4 threads | |
|---|---|---|
| Word choice, context mode (once per context) | 6.76 / 12.36 ms | 3.88 ms (laya.one.int8g.onnx) |
| Word choice, a key | 4.15 / 6.12 ms | 1.94 ms (laya.one.int8g.onnx), 2.54 ms (the 4-bit phone graph) |
| Composition, context mode + the slots | 2.88 + 2.55 / 3.05 + 2.47 ms | |
| A whole next-word prediction (beam 8, 5 words) | 12.6 / 18.6 ms | 51.9 ms (int8), 38.6 ms (the 4-bit phone graphs; 45.6 ms on 1 thread) |
1121's numbers are those measured for its release (same rows, same runtime). Word choice costs more mostly in the
table's keys (hashing and lookups for every token and slot, many small operators); next words cost less with 32,000
output tokens instead of 102,464 and the step in the same file. Memory of the process (onnx/, loaded / running):
131 / 316 MB.
One RTX 5070 Ti, from zhen-feather-preview-1121, the whole model.
ngram.idmap) so its trained rows keep their
meaning; the two new readers (ng_proj for the encoder's token keys, ng_sproj for the slot keys) start at zero.A tensor listed in config.json q4_0 is stored as ggml's Q4_0 blocks: dtype U8, shape rows × (columns / 32 × 18).
Each block of 32 values along a row is 18 bytes: an f16 scale d (little-endian), then 16 bytes q; value j
(0…15) is ((q[j] & 15) − 8) · d, value j + 16 is ((q[j] >> 4) − 8) · d. This is the layout candle's
qtensor_from_ggml(GgmlDType::Q4_0, …) (and llama.cpp) read, so a linear layer runs as a 4-bit matrix product:
use candle_core::quantized::{ggml_file::qtensor_from_ggml, GgmlDType, QMatMul};
let raw = safetensors.load(name, &device)?.flatten_all()?.to_vec1::<u8>()?;
let w = QMatMul::from_qtensor(qtensor_from_ggml(GgmlDType::Q4_0, &raw, vec![rows, cols], &device)?)?;
// w.forward(&x) = x · wᵀ, then add the bias if the layer has one
The 4-bit tensors: every linear weight of the decoder (next.*), and the two embedding tables
encoder.embeddings.tok_embeddings.weight (32000 × 256) and unit_emb.weight (3833 × 256), whose rows are unpacked
when read. The token table is also the read-out: keep it as a Q4_0 matrix for x · tableᵀ and unpack only the rows a
lookup needs (one copy in memory). The tensors in quantize_q8_0 (the encoder's and the head's matrices, scorer.1,
out.1, char_emb, ng_proj, ng_sproj) are F16, for an implementation to quantize to 8 bits as it loads them
(candle_ref: Q8_0): at 4 bits composition lost 6.7 points of whole Simplified sentences of 300. Everything else is
F32.
The table (ngram.codes U8 1000003 × 16, ngram.codebooks F32 16 × 256 × 4): row r is the 16 codebook vectors
codebooks[p, codes[r, p]] (p = 0…15) one after another, 64 values.
The hash (config.json ngram.hash): for a salt and key tokens t₁ … tₖ, in int64 with a wrapping multiply,
x = salt * 0x9E3779B1 + 12345
for t in t1 ... tk: x = (x XOR (t + 1)) * 0x100000001B3; x = x XOR (x >> 29) (arithmetic shift)
row = x mod 1000003 (non-negative)
An absent key token is −7. Token ids in every key are the old ones, o = ngram.idmap[id]; slot keys use the unit ids
as unit_ids holds them (tone included).
Names are the PyTorch ones.
| Tensor | Shape | |
|---|---|---|
encoder.embeddings.tok_embeddings.weight |
32000 × 256 | Q4_0; token id = row |
encoder.embeddings.norm.weight |
256 | LayerNorm, no bias |
encoder.layers.N.attn_norm.weight (N ≥ 1; layer 0 has none) |
256 | |
encoder.layers.N.attn.Wqkv.weight |
768 × 256 | N = 0…7, F16 |
encoder.layers.N.attn.Wo.weight |
256 × 256 | F16 |
encoder.layers.N.mlp_norm.weight |
256 | |
encoder.layers.N.mlp.Wi.weight |
1024 × 256 | F16 |
encoder.layers.N.mlp.Wo.weight |
256 × 512 | F16 |
encoder.final_norm.weight |
256 | |
unit_emb.weight |
3833 × 256 | Q4_0; row 0 = none, 1-3804 the units of unified_vocab.json, 3805-3832 letters |
tone_emb.weight |
6 × 256 | Zhuyin tones: row 0 = none, 1-5 (5 = neutral) |
type_emb.weight |
3 × 256 | row 0 is the one used |
cand_emb |
256 | added at each candidate's first token |
ngram.codes, ngram.codebooks |
1000003 × 16, 16 × 256 × 4 | the table (PQ16) |
ngram.idmap |
32000 (I32) | token id → the id every key is hashed on (the 256k vocabulary's) |
ng_proj.weight, ng_proj.bias |
256 × 128, 256 | token keys: two table rows (2 × 64) → the encoder's input; F16 |
ng_sproj.weight, ng_sproj.bias |
256 × 128, 256 | slot keys: two table rows → the encoder's input; F16 |
head.layers.0.* |
one nn.TransformerEncoderLayer (matrices F16) |
|
scorer.0 (LayerNorm), scorer.1 (256 → 256), scorer.3 (256 → 1) |
word choice | |
out.0 (LayerNorm), out.1 (256 → 256) |
composition | |
char_emb.weight |
9067 × 256 | the 9,067 characters' token-embedding rows (unified_vocab.json chars order, char_tokens); F16 |
char_bias |
9067 | composition |
next.mem_in.0 (256 → 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 (256 → 384) |
a token's embedding → the decoder's input | |
next.start |
384 | the input at position 0 |
next.start_word |
384 | position 0 in training's "word" mode (2+ character Chinese rows); the search below uses next.start |
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; matrices Q4_0 |
|
next.out.0 (LayerNorm), next.out.1 (384 → 256) |
the decoder's output | |
next.bias |
32000 | the read-out's bias, per token |
One sequence at a time (batch 1, no padding; with padding, mask padded keys in every attention).
The prefix mask. Let n be the position of the first <eos> (1) plus one: positions 0 … n−1 are the
leading block. A query inside the block may attend only to keys inside it; a query after it attends to every key
(within the sliding window where the layer has one). This holds in every encoder layer and in the head layer.
x = tok_emb[input_ids] + unit_emb[unit_ids % 3833] + tone_emb[unit_ids / 3833], plus cand_emb at every
position in marker_pos (each candidate's first token; none in composition).
Token keys, on o = ngram.idmap[input_ids]: for every context position p (1 ≤ p < n − 1, between <bos> and
the first <eos>) and every candidate token (from the first marker up to, not including, the final <eos>):
prev1 = o[p − 1], prev2 = o[p − 2] (−7 at p < 2); for a candidate token at offset off from its candidate's
first token: off = 0 → prev1 = o[n − 2], prev2 = o[n − 3] (the context's last two tokens; −7 when n < 3),
off = 1 → prev2 = o[n − 2];x[p] += ng_proj(concat(row(hash(1; prev1, o[p])), row(hash(2; prev2, prev1, o[p])))).
Every other position adds ng_proj's bias alone.Slot keys, on the unit ids u = unit_ids and c1 = o[n − 2], c2 = o[n − 3] (the context's last two tokens;
c2 = −7 when n < 3): at every position p with u[p] > 0 (the typed units of word choice and composition),
hash(5; u[p−1], u[p]) if position p − 1 is a unit, else hash(7; c1, u[p]);hash(6; u[p−2], u[p−1], u[p]) if positions p − 1 and p − 2 are units, hash(8; c1, u[p−1], u[p]) if
only p − 1 is, else hash(9; c2, c1, u[p]);x[p] += ng_sproj(concat(row(bigram), row(trigram))). Every other position adds ng_sproj's bias alone.Then LayerNorm (encoder.embeddings.norm).
Encoder: 8 pre-norm ModernBERT layers, width 256, 4 heads of 64, no biases.
h = attn_norm(x) (layer 0: h = x); q, k, v = split(Wqkv h), laid out as (3, heads, 64).x·cos + rotate_half(x)·sin, frequencies
1 / 160000^(2i/64), positions 0, 1, 2, ….config.json
encoder.layer_types: full_attention), the others only where |i − j| ≤ 64 (sliding_attention).x += Wo(attention); then a, g = split(Wi mlp_norm(x)) (512 each), x += mlp.Wo(gelu(a) · g), exact (erf)
GELU.final_norm.Head: h0 = encoder output + type_emb[0], then head.layers.0 (PyTorch nn.TransformerEncoderLayer,
norm_first=True, 4 heads, feed-forward 1024 with ReLU, LayerNorm eps 1e-5, in_proj_weight = q, k, v stacked;
no final norm), with the prefix mask.
Word choice: at each candidate's first token p, score = scorer.3(gelu(scorer.1(scorer.0(h0[p])))) (erf
GELU). Higher is better.
Composition: at each slot s, q = out.1(out.0(h0[s])) and char_logits = q · char_embᵀ + char_bias
(9,067). Compare only the characters the slot's unit can spell (f: / jf:: that syllable's characters; p: /
jp:: those of every syllable starting with it), from unified_vocab.json: Simplified rows readings (the first
6,163 characters, ml.old_chars); Traditional pinyin and Zhuyin rows ml.pinyin, Cantonese rows ml.jyutping,
both without ml.simp_only. 229 of the 9,067 characters have no token of their own in the 32k vocabulary: their
char_emb row is <unk>'s, so only char_bias tells them apart.
Caching the context. Run the block alone once per context and keep each layer's keys and values (after RoPE)
for its n positions; on each key run only the positions after it (the ONNX file's context and key modes). The key
part needs the context's last two tokens for its token and slot keys (ctx_tail).
<bos> encode(context)[last 128 tokens] <eos> (English: the context's trailing spaces cut
first) with the encoder above (unit ids 0, no candidates; one prefix block, so the plain mask with the sliding
window). m = next.mem_in.1(next.mem_in.0(encoder output + type_emb[0])), (T, 384).
Mid-text: <bos> L <mask> R <eos> with R = encode(right)[first 32 tokens] and
L = encode(left)[−(127 − len(R)):] (as trained: the left side gives way to the right side), the gap marked by
<mask> (a context never holds one: replace <mask> in the text by a space first). Encode the right side on its
own; English: cut the left side's trailing spaces as before.o = ngram.idmap[c], with g the <mask> position (else
the final <eos>): l1, l2, l3 = o[g−1], o[g−2], o[g−3], r1, r2 = o[g+1], o[g+2] (−7 without a gap; indices
clamped to the block); keys hash(1; l2, l1), hash(2; l3, l2, l1), hash(3; r1, r2), hash(4; l1, r1)
(ngram.decoder.salt_offset 0: the first two are the same rows as the last context token's token keys);
position j = next.mem_norm(next.mem_proj(row(key_j)) + next.mem_type[j]). Append the four after m: the memory
is (T + 4, 384).multihead_attn.in_proj_weight (and bias): compute them once per context.next.start; position j ≥ 1 is next.tok_in(tok_emb[t_j]), t_j the token 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)) with a causal mask; x += multihead_attn(norm2(x), memory) (all T + 4
positions); x += linear2(relu(linear1(norm3(x)))). Attention scale 1/8.logits = next.out.1(next.out.0(x)) · tok_embᵀ + next.bias over the 32,000 tokens. A cache of each
layer's self-attention keys and values makes a step cost one position.Search (as example.py and candle_ref): beam 8, k = 5 words, at most 6 tokens a word.
zh tokens (Simplified Han) and the end (<eos>, next_rows.json end);
English mode en_start at the first token, then en_cont or the end. The others get −10⁹ before the log-softmax.next_rows.json text_zh / text_en;
English stripped), kept if it has at least min_chars characters (2 for words, 1 to let single characters
through); hypotheses writing the same text are summed (log-sum-exp).min_chars 1; the words found are the
rest of the word.Token ids are tokenizer.json's, with <bos> (2) as [CLS], <eos> (1) as [SEP], <mask> (4). The context, a tag
and the typed text are encoded with tokenizer.json; candidates with tokenizer.candidates.json (no ▁, English
ones too), each cut to 16 tokens. Encode without special tokens. A Traditional row starts with the tag <zh-Hant> as
plain text; Simplified Chinese and English have no tag. Characters outside the 32k tokens fall back to UTF-8 bytes
(<0x..> tokens).
word choice, Simplified (pinyin) <bos> encode(context)[last 128] <eos> <mask> × typed units <eos> cand(候选1)[:16] cand(候选2)[:16] … <eos>
word choice, Traditional <bos> encode("<zh-Hant>") encode(context)[last 128] <eos> encode(typed text)[:24] <eos> cand(候選1)[:16] … <eos>
word choice, English as Simplified, one <mask> a typed letter (its letter unit)
composition <bos> [encode("<zh-Hant>")] encode("已输入的上文: " + context) <eos> <mask> × slots <eos>
next word <bos> encode(context)[last 128] <eos>
next word, mid-text <bos> encode(left)[−(127 − len(R)):] <mask> R = encode(right)[:32] <eos>
marker_pos lists the position of each candidate's first token. Each <mask> of the typed units carries its unit in
unit_ids (unified_vocab.json units: f:san = the full syllable san, p:s = typed only partly; English letters
3805 + the letter's index in letters); the other positions have unit 0.
Composition: the prefix 已输入的上文: (literal text, "typed context: "; config.json context_prefix) is encoded
together with the context; if that is longer than 160 tokens, keep the prefix's own tokens and the last tokens of the
rest, 160 in all. At most 24 slots; slot_pos lists them; each carries its unit: pinyin f: / p:, Jyutping jf: /
jp:, Zhuyin the syllable's pinyin unit + 3833 × tone (tone 1-5, 5 = neutral; config.json ml.tone_stride).
There are no candidates: marker_pos is empty.
test_vectors.safetensors, all int64 inputs, outputs of the fp32 PyTorch model with the table as stored (PQ16), the
other weights before rounding:
| Cases | Inputs | Output |
|---|---|---|
i = 0-4 (Simplified Chinese), 8-15 (the first row of each Traditional word-choice test file: pinyin, Zhuyin bopomofo_tw, Zhuyin libchewing, Jyutping, Cangjie 5, Quick 5, Cangjie 3, Quick 3) |
i.input_ids, i.unit_ids, i.marker_pos; i.slot_pos = [0], a placeholder |
i.logits (one per candidate) |
i = 5-7 (Simplified pinyin), 16-18 (the first row of the Traditional pinyin, Zhuyin and Jyutping composition test files) |
i.input_ids, i.unit_ids, i.slot_pos; i.marker_pos empty |
i.char_logits (slots × 9067, before the masks) |
nextN, N = 0-14 (8-11 mid-text; 7 and 12-14 min_chars 1) |
nextN.input_ids, nextN.mode (0 Chinese, 1 English), nextN.min_chars |
nextN.text (UTF-8, one word a line), nextN.logp (the 5 words) |
candle_ref reads this file and writes its outputs under the same names (it loads the model in about 0.3 s):
cd candle_ref
RUSTFLAGS="-C target-cpu=native" cargo build --release
target/release/zhiyi-ref ../model.safetensors ../test_vectors.safetensors out.safetensors
candle's quantized kernels choose their SIMD code at compile time: build with RUSTFLAGS="-C target-cpu=native" (or
at least x86-64-v3). candle_ref is a reference, not a fast runtime: it runs the whole sequence with the mask (no
cache) and reruns the decoder over each hypothesis' prefix at every step; the outputs are those of the cached runs. On
the vectors it picks the same best candidate in 13 of 13 word-choice cases (logits within 0.73) and gives the same
first word in 11 of the 15 next-word cases (4.0 of the 5 words shared on average).
The model alone, not the IME end to end. PyTorch = the trained model with the table as stored (PQ16), fp32 otherwise; the exported files are checked against it below.
Word choice, first candidate right, the whole test sets:
| Word choice | zhen-feather-preview-1121 | zhen-feather-1127 |
|---|---|---|
| Simplified Chinese, words and word pairs (6523) | 88.1% | 88.5% |
| Simplified Chinese, long input (2247) | 82.5% | 82.8% |
| English (2189) | 88.9% | 89.3% |
| Simplified Chinese web text, short (1001) | 91.9% | 91.5% |
| Simplified Chinese web text, long (344) | 87.2% | 88.4% |
| English web text (426) | 86.6% | 86.2% |
| Simplified Chinese, IME's real candidates (right word among them) (1634) | 90.3% | 90.6% |
| Simplified Chinese homophones with the previous sentence (800) | 90.9% | 90.9% |
| English, the older test set (840) | 86.8% | 85.2% |
| Traditional, pinyin (luna_pinyin) (3000) | 84.2% | 85.3% |
| Traditional, Zhuyin (bopomofo_tw) (3000) | 91.1% | 92.1% |
| Traditional, Zhuyin (libchewing) (3000) | 96.2% | 96.5% |
| Traditional, Jyutping (jyut6ping3) (3000) | 88.9% | 90.0% |
| Traditional, Cangjie 5 (3000) | 95.3% | 96.4% |
| Traditional, Quick 5 (3000) | 94.2% | 95.5% |
| Traditional, Cangjie 3 (3000) | 84.1% | 85.4% |
| Traditional, Quick 3 (3000) | 78.3% | 79.1% |
Composition, whole rows right / characters right (the best allowed character per slot):
| Composition | zhen-feather-preview-1121 | zhen-feather-1127 |
|---|---|---|
| Simplified, long pinyin in full (300) | 53.0% / 82.4% (its fp32 ONNX) | 58.7% / 84.7% |
| Traditional, pinyin (3000) | 35.4% / 71.1% | 41.5% / 75.2% |
| Traditional, Zhuyin (3000) | 65.9% / 90.9% | 71.9% / 92.7% |
| Cantonese, Jyutping (3000) | 33.3% / 67.9% | 37.2% / 71.3% |
Next word, the text's next word first (@1) / among the 5 words (@5), beam 8, the whole next-word test sets (mid-text = the rows whose text goes on after the word, that text as the right side; single characters = the rows of the set that allows them):
| @1 / @5 | zhen-feather-preview-1121 | zhen-feather-1127 |
|---|---|---|
| Chinese next word (4941) | 15.1 / 27.2% | 14.6 / 26.5% |
| ... with ng1017 | 15.4 / 27.8% | 14.6 / 27.7% |
| Chinese, single characters too (3548) | 21.7 / 35.6% | 20.1 / 35.3% |
| ... of them single characters (1489) | 32.3 / 49.8% | 29.6 / 47.8% |
| Chinese mid-text (3789) | 21.6 / 35.8% | 20.3 / 34.9% |
| Chinese completion (4941) | 56.8 / 78.5% | 55.7 / 78.3% |
| English next word (3000) | 24.2 / 43.0% | 22.5 / 41.4% |
| ... with a trigram of the training text | 24.0 / 43.4% | 23.2 / 41.8% |
| English mid-text (2969) | 41.4 / 60.4% | 36.3 / 54.8% |
The vocabulary change alone (1121 cut to 32k tokens, before any training) took English mid-text to 37.6 / 55.3% and English next words to 21.8 / 39.1%.
On the public neutral word-choice test sets (v2, v3 web, v4 chat, v5 hard; whole page, first candidate right):
| v2 | v3 | v4 | v5 | |
|---|---|---|---|---|
| zhen-feather-preview-1121, PyTorch fp32 | 93.07% | 93.57% | 91.93% | 70.67% |
| zhen-feather-1127, PyTorch | 93.61% | 93.99% | 92.22% | 72.36% |
zhen-feather-preview-1121, int8 ONNX (laya.int8g.onnx) |
92.3% | 92.9% | 91.6% | 68.7% |
zhen-feather-1127, ONNX (onnx/laya.feather.onnx) |
93.6% | 93.9% | 92.2% | 72.2% |
v5 by the context before the typed text (PyTorch; none / 1-16 characters / more):
| none | 1-16 characters | more | |
|---|---|---|---|
| zhen-feather-preview-1121 | 60.73% | 70.46% | 82.46% |
| zhen-feather-1127 | 62.11% | 72.79% | 83.74% |
The ONNX rows are the comparison scorer's (the charts below), the PyTorch rows the training code's; the two count the same rows slightly differently.
The exported files against PyTorch, on the same rows (300 a set: every set's first 300 rows, the Simplified word choice rows of the parity sets, composition alone on the dev set of the training data's composition rows (Simplified) and on the test files (Traditional); next words 300 Chinese and 300 English test rows, 150 mid-text rows of each and 150 Chinese completions):
ONNX onnx/laya.feather.onnx |
candle_ref on model.safetensors |
|
|---|---|---|
| Word choice: the same best candidate as PyTorch (9 sets) | 95.3-99.7% | 95.3-99.7% |
| Word choice: accuracy against PyTorch's, per set | −0.3 … +1.7 points | −0.3 … +1.3 points |
| Composition: the same character as PyTorch (4 sets) | 96.1-99.1% | 95.6-99.0% |
| Composition: whole rows against PyTorch's, per set | −0.3 … +0.6 points | −0.3 … +0.3 points |
| Simplified long pinyin (300): whole / characters | 58.0% / 84.8% (PyTorch 58.7% / 84.7%) | 58.3% / 84.7% |
| Next words: the same first word as PyTorch (5 sets) | 82.0-92.0% | 77.3-91.3% |
| Next words: @1 against PyTorch's, per set | −0.6 … +2.0 points | −1.4 … +0.3 points |
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
(zhiyi-ml-flash), Mini
(zhiyi-zhen-mini-12M) and Feather (this model), each scored
with its released ONNX file (this model: onnx/laya.feather.onnx), so the points can differ a little from the numbers
above. 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 32k tokenizer is a subset of its vocabulary). 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): Zhiyi's own 8-layer model (zh-lite-next-preview's Lite x8) online for word choice; Qwen3.5-9B (https://huggingface.co/Qwen/Qwen3.5-9B) fine-tuned with LoRA for word choice and composition (stored scores), Qwen3-1.7B-Base (https://huggingface.co/Qwen/Qwen3-1.7B-Base) and Qwen3-4B-Base (https://huggingface.co/Qwen/Qwen3-4B-Base; the new Chinese mid-text rows) for next words, all by the Qwen team (Alibaba Cloud), Apache-2.0. Text: as zhen-feather-preview-1121 (composition rows as ML-Flash-1103's: SkyPile-150B, LCCC, C4, SODA, Tatoeba, FineWeb, FineWeb-2, the Cantonese Wikipedia; rare-character rows from FineWeb-2; word choice and next words: FineWeb-2, LCCC, SkyPile-150B, FineWeb, C4), plus the new rows of this version: long contexts from FineWeb-2 (Penedo et al., 2025; ODC-By 1.0; cmn_Hani, Simplified and Traditional) and FineWeb, short-context word choice from FineWeb-2, LCCC and C4 with candidates from seven input-method engines run on the typed letters (Zhiyi, Rime with rime-ice and with luna_pinyin, libpinyin, libime, Qingjian and Microsoft Pinyin; only their candidate lists were used), readings from pypinyin, OpenCC and librime with the Rime schemas (rime-cantonese among them). These programs and data only produced training rows; none of them is in these files.
model.safetensors 44 MBonnx/laya.feather.onnx 40 MBtest_vectors.safetensors 2 MBjhu-clsp/mmBERT-small