Zhiyi translation model V5-Preview-0.5B (zhiyi-mt-v5-preview)
An offline translation model for Zhiyi IME: it translates IME candidates and sentences while you type, between Chinese, English, Japanese, Korean, French, German, Spanish, Russian and Vietnamese, and comes with a part-of-speech head for the candidate. Zhiyi IME has used it since 2026-11-15 (translator manifest 8, shown as "v5" in Settings).
New in V5-Preview: a candidate's translation continues the text before it. v4-1113-RL translated a candidate as if it stood alone, so after 我今天很 ("today I am very") the candidate 想你 became "I miss you."; V5-Preview writes the words a translation of the whole text would use: "miss you". Subject, person, number and tense follow the context (她昨天|买了一本书 -> "bought a book", 他每天都|跑步 -> "runs", 他一直在|想你 -> "thinking of you"); the context is not translated again, and there is no capital or full stop the continuation would not have. A wrong conversion (wrong characters that sound alike) is translated as typed, not replaced by a guess from the context, so it looks wrong. Without a context it translates as before (想你 -> "I miss you."). This holds between all nine languages, also when the context is in another language than the candidate.
Files
| File | Contents |
|---|---|
model.safetensors, tokenizer files, chat_template.jinja | float32 checkpoint for transformers |
zhiyi-mt-v5-preview-Q4_K_M.gguf (322 MB) | Q4_K_M for llama.cpp, without the part-of-speech head |
zhiyi-mt-v5-preview-Q4_K_M-pos.gguf (332 MB) | the same model with the head written in as GGUF metadata (zhiyi.pos_head.*); the file Zhiyi IME downloads |
pos_head/ (10 MB) | the head for transformers: pos_head.safetensors, pos_head.json, example script pos_head.py |
Which GGUF: both translate the same in any llama.cpp build (builds that do not know the zhiyi.pos_head.* keys
ignore them); take -pos.gguf only for part-of-speech tags from the patched llama-server. The GitHub release translator-v5-preview
has the head-less GGUF and this checkpoint as a zip.
Model
- Architecture: Qwen3 (
Qwen3ForCausalLM), 20 layers, hidden size 1024, input embeddings tied with the output layer, 470M parameters; the same structure, size and speed as v3, v4, v4-1026 and v4-1113-RL. - Base: NiuTrans/LMT-60-0.6B with 8 of its 28 layers removed (kept: 0-6, 10, 11, 16-23, 25-27).
- Training, from the averaged model that v4-1113-RL's reinforcement learning started from:
- One pass over 363,859 pairs: 203,859 candidates with their real preceding text (Chinese IME candidates, words of the other eight languages, Chinese, Japanese and Korean text with other languages mixed in), translated into all other languages as a continuation of the context by Qwen3.8-27B, 42,651 of them wrong conversions (judged by Qwen3.8-27B) translated character by character; plus 160,000 pairs of v4-1113-RL's data (sentences, candidates without a context, ambiguous words) so that nothing else is forgotten.
- Reinforcement learning (GRPO, one pass over 16,800 items) with v4-1113-RL's rule-only reward (target language by GlotLID, numbers and Latin-script names kept, the annotated meaning of ambiguous words, no copying, repetition or overlong answers) and two new checks for candidates in context: the first-letter case and final punctuation of the teacher's continuation, and no name copied from the context that neither the candidate nor the teacher's translation has. No learned quality metric is in the reward.
- Source texts: SkyPile-150B, LCCC, C4, mC4, FineWeb-2, the Cantonese Wikipedia and Tatoeba.
Prompt
The model was trained on this one prompt (v4-1113-RL's, word for word), not on LMT-60's chat format; other prompts work much worse.
<|im_start|>system
Translate the input method candidate into {Target}. Use the context only to pick the meaning. Output only the translation.<|im_end|>
<|im_start|>user
Context: {text before the cursor, optional: leave out the whole line}
{Source}: {text}<|im_end|>
<|im_start|>assistant
{Source}and{Target}are English language names: Chinese, English, Japanese, Korean, French, German, Spanish, Russian, Vietnamese.Textas the source name is accepted for an unknown source language.- Context: the text right before the cursor, its last 80 characters (as in training). It is not translated. Although
the system line says "only to pick the meaning", in this model it also decides the form of the translation. Leave
out the whole
Context:line to translate the text on its own. - The prompt ends with a newline after
assistant. Decode greedily and stop at<|im_end|>. - The included chat template builds exactly this prompt from a system and a user message.
Usage
transformers (4.56 or later for dtype=; older versions take torch_dtype=):
from transformers import AutoModelForCausalLM, AutoTokenizer
path = "zhiyi-ime/zhiyi-ime-translator-v5-0.5B" # or a local copy of this repository
tok = AutoTokenizer.from_pretrained(path)
model = AutoModelForCausalLM.from_pretrained(path, dtype="bfloat16")
def translate(text, source, target, context=""):
system = (f"Translate the input method candidate into {target}. "
"Use the context only to pick the meaning. Output only the translation.")
user = (f"Context: {context}\n" if context else "") + f"{source}: {text}"
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]
ids = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True)
out = model.generate(**ids, max_new_tokens=256, do_sample=False)
return tok.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True).strip()
print(translate("今天天气不错", "Chinese", "English"))
print(translate("想你", "Chinese", "English", context="我今天很"))
print(translate("bank", "English", "Chinese", context="We sat on the grass by the river"))
llama.cpp: run llama-server -m zhiyi-mt-v5-preview-Q4_K_M.gguf and send the prompt above to /completion with
"temperature": 0 and "stop": ["<|im_end|>"]. To make other quantizations, convert this checkpoint with
convert_hf_to_gguf.py; it quantizes like any Qwen3 model (GGUF, bitsandbytes, llm-compressor, ...). For methods
that calibrate, use calibration samples in the prompt format above.
Part-of-speech head
The head tags the candidate with one of 20 parts of speech: the 17 Universal Dependencies tags plus CLF (Chinese measure words), ONOM (onomatopoeia) and NONE (phrases, sentences, several words). It judges from the candidate and the text before it: "light" after "Please turn on the" is a noun, after "The bag is very" an adjective; 研究 after 科学家们正在 is a verb, after 这是一项重要的 a noun. It needs no second model: it reads five hidden states of the translator at the last prompt token, which the translator computes anyway. Its weak spot is Chinese words that can be verbs or nouns, or adjectives or nouns. It was trained as v4-1113-RL's head, on this model's hidden states.
With transformers (pos_head/pos_head.py does all of this and prints a few examples):
- Build the translation prompt above for the candidate, with the context cut to its last 80 characters and the source language named. Any target works, so the IME's own translation prompt serves (the head was trained on every target; English for Chinese candidates and Chinese for the others are a little better on Chinese words).
- Run the prompt through the model (no generation needed) and take, at the last prompt token (the
\nafterassistant),model(**ids, output_hidden_states=True).hidden_states[i][0, -1]for i = 6, 8, 10, 12, 14: the outputs of layers 6, 8, 10, 12 and 14 counted from 1, before the final norm (hidden_states[0]is the embeddings). - Apply the head (
pos_head.safetensors, float32):x_k = (h_k - mean[k]) / std[k]for each of the five states;z= the five concatenated (5120);logits = fc2(gelu(fc1(z)))(fc1 5120 -> 512, exact GELU, fc2 512 -> 20). The tag is the argmax;pos_head.jsonlists the 20 tags in order. The softmax is a usable confidence: show a tag only above a threshold if a wrong tag costs more than no tag.
With llama.cpp: Zhiyi IME's patched llama-server (llama.cpp b11480, MIT:
scripts/llama_server_pos; a Windows
x64 Vulkan build is llama-b11480-zhiyi-pos-prefix-vulkan-x64.zip in Zhiyi IME's
translator release) loads the head from
zhiyi-mt-v5-preview-Q4_K_M-pos.gguf and computes it while it translates. A /completion request with "pos": true
gets pos and pos_prob (the most likely tag and its probability) and pos_top (up to 5 tags with at least 1%,
[{"tag": "ADV", "prob": 0.58}, ...]) in its result. The patch's add_pos_head.py writes pos_head/ into any copy
of the GGUF the same way. SHA-256 of zhiyi-mt-v5-preview-Q4_K_M-pos.gguf:
89f1330c9911f25cb9ced58556674d37203dca9ee8532064b8629a9969f2ec59 (zhiyi-mt-v5-Q4_K_M.gguf in Zhiyi IME's
translator manifest 8).
In your own llama.cpp code, read the graph tensors l_out-5, l_out-7, l_out-9, l_out-11 and l_out-13
(0-based layer numbers) with an eval callback (cb_eval, as in llama.cpp's examples/eval-callback), taking the row
of each sequence's own last prompt token, and apply step 3.
Accuracy (%, held out; Chinese candidates translated into English, the others into Chinese):
| Head | UD 2.18 test sets (36,000 words) | UD, ambiguous words (2,726) | Hand-written pairs, Chinese (158) | Hand-written pairs, English (97) | Agreement with Qwen3.8-27B (15,079 candidates) | GLM-5.3 labels (418 candidates) |
|---|---|---|---|---|---|---|
| V5-Preview-0.5B (this model) | 92.7 | 78.4 | 92.4 | 92.8 | 87.8 | 78.5 |
| v4-1113-RL | 92.1 | 75.0 | 85.4 | 92.8 | 87.9 | 78.5 |
| Qwen3.8-27B | (reference) | 77.3 |
- UD test sets: human labels. By language (this head): Japanese 95.4, Spanish 95.3, French 94.9, Russian 93.8, German 93.6, English 93.5, Chinese 90.0, Vietnamese 89.8, Korean 87.7; UD's word conventions for Chinese, Korean and Vietnamese differ from IME candidates, so these three understate. Ambiguous words: words that take several parts of speech in UD's training sets.
- Hand-written pairs: the same candidate after preceding texts that call for different parts of speech, labelled by Claude Opus 5.5 following UD's rules.
- With each of the other targets, on 4,000 random UD test words: 91.6-93.3% (v4-1113-RL's head 91.5-92.7%); on the ambiguous words 76.2-79.4% (72.9-76.5%).
- Agreement with Qwen3.8-27B: sentences 99.7%, words 86.5%, short phrases 84.3%. Without the context it drops to 83.4% (15.3% of the answers change): the head does use the text before the candidate.
Results
Candidates in context (what is new):
- 100 hand-written candidates after a context that decides their form (subject, tense, aspect, person, number; 73 Chinese into English, 27 in other directions), each with hand-written acceptable continuations: the answer equals one of them for 71 (v4-1113-RL: 32) and contains one with at most two words more for 82 (59).
- Blind comparison on 60 random items of the IME set (below) where the two translations differ, judged by Claude Opus 5.5 without knowing which model wrote which: V5-Preview won 27, v4-1113-RL 6, 27 ties. v4-1113-RL mostly lost by translating a candidate as a sentence of its own (a capital, a subject the candidate does not have) or replacing a wrong conversion by a guess from the context.
- On 992 held-out candidates in context translated into English, French, German, Spanish and Vietnamese, 2.6% of the answers start with a capital the continuation does not have (v4-1113-RL: 81.9%).
Sentences and open test sets (a little below v4-1113-RL): COMET-22 (x100) and off-target rate (answers not in the target language's script), greedy decoding, as Q4_K_M GGUF in llama.cpp (NLLB-200-distilled-600M and M2M100-418M: float16 in Transformers with their own generation settings: greedy for NLLB, beam 5 for M2M100; OPUS-MT: the Helsinki-NLP pair models in CTranslate2 int8 with beam 4, the tc-big model where there is one; 46 of the 72 directions have a pair model, the other 26 go through English, and English to Japanese uses opus-mt-en-mul). FLORES-200 devtest and NTREX-128: all 72 directions among the 9 languages; WMT24++: English into the other 8. IME set: 1,559 real IME candidates and sentences (Chinese and English sources, into all 8 other languages), scored against Hy-MT2-7B's translations of each candidate on its own, so V5-Preview's continuations score lower there by design.
| Model | FLORES-200 | WMT24++ | NTREX-128 | IME set | Off-target FLORES-200 / WMT24++ / NTREX-128 |
|---|---|---|---|---|---|
| Hy-MT2-7B (teacher) | 87.9 | 85.8 | 85.8 | (reference) | 0.02% / 0.35% / 0.03% |
| LMT-60-0.6B | 82.2 | 76.7 | 81.4 | 0.26% / 0.90% / 0.21% | |
| NLLB-200-distilled-600M | 81.7 | 72.4 | 79.4 | 0.01% / 0.62% / 0.06% | |
| M2M100-418M | 80.4 | 68.3 | 78.6 | 0.00% / 0.94% / 0.01% | |
| OPUS-MT (CTranslate2 int8) | 79.5 | 71.3 | 76.5 | 0.00% / 0.46% / 0.01% | |
| Zhiyi v4-1026 | 84.1 | 80.6 | 81.8 | 80.5 | 0.03% / 0.46% / 0.03% |
| Zhiyi v4-1113-RL | 84.6 | 81.0 | 82.2 | 80.8 | 0.02% / 0.46% / 0.03% |
| Zhiyi V5-Preview-0.5B (this model) | 84.1 | 80.5 | 81.7 | 74.5 | 0.05% / 0.43% / 0.04% |
- IME set ignoring case and final punctuation: 76.1 (v4-1113-RL 81.1); on its 82 items without a context: 79.8 (80.9).
- FLORES-200 by group, v4-1113-RL -> V5-Preview: into English 86.0 -> 85.7, into Chinese 85.7 -> 85.3, from Chinese 85.2 -> 84.8, from English 87.3 -> 86.7, among the other 7 languages 83.6 -> 83.0.
- FLORES-200 by group against the other small open models (COMET-22, the same runs as the table above):
| Group | V5-Preview-0.5B | LMT-60-0.6B | NLLB-200-distilled-600M | M2M100-418M | OPUS-MT (CTranslate2 int8) |
|---|---|---|---|---|---|
| From English (8) | 86.7 | 85.1 | 84.1 | 81.6 | 83.3 |
| Into English (8) | 85.7 | 86.4 | 85.9 | 82.9 | 85.3 |
| From Chinese (8) | 84.8 | 83.0 | 80.6 | 80.9 | 79.4 |
| Into Chinese (8) | 85.3 | 85.7 | 75.9 | 78.9 | 80.5 |
| Into Japanese (8) | 87.5 | 86.3 | 82.8 | 83.9 | 72.6 |
| Among the other 7 languages (42) | 83.0 | 80.3 | 81.6 | 79.9 | 77.6 |
| Directions where it beats V5-Preview (of 72) | 15 | 19 | 0 | 14 |
- NLLB-200-distilled-600M wins 19 directions, mostly among the European languages (best German to French +1.7), but is weakest into Chinese (75.9; English to Chinese 11.3 below V5-Preview); it also writes ASCII punctuation in 98.8% of its Chinese answers, though converting it to full width adds only 0.4. M2M100-418M wins none (closest: French to Spanish, 1.1 below).
- OPUS-MT: its 7 tc-big pair models average 86.9 against V5-Preview's 85.9 on the same directions (best German to Spanish +3.0, English to French +2.1, French to English +1.8), while the 38 smaller pair models (78.8) and the 26 directions through English (78.8) are 4 to 6 points lower. Japanese is its weakest target, since English to Japanese has only the multi-target opus-mt-en-mul (71.4 on FLORES-200, 60.2 on WMT24++).
- Hugging Face's
vocab.jsonfor the three tc-big models with separate vocabularies (en-ko, ko-en, zh-ja) is the target vocabulary, soMarianTokenizerturns Korean or Chinese input into<unk>; the OPUS-MT numbers above encode the source with its ownsource.spmids instead. - Ambiguous words: on 169 words never seen in training (2,956 contexts) it picks the meaning the context calls for 73.0% of the time (v4-1113-RL 73.3%); on another 764 held-out words 62.7% (64.7%); on trained words in new contexts 70.4% (78.5%), partly because the scoring takes the annotated noun forms ("Detection") while this model writes the form that continues the context ("detected").
License and credits
Apache License 2.0 (LICENSE, NOTICE). The base model LMT-60-0.6B (NiuTrans), the teachers Hy-MT2-7B and
Hy-MT2-30B-A3B (Tencent) and Qwen3.8-27B, which wrote the translations in context, are under the Apache License 2.0
too (LICENSE-LMT-60.txt, LICENSE-Hy-MT2.txt, LICENSE-Hy-MT2-30B-A3B.txt). NOTICE lists the source texts and
the part-of-speech head's training data (labels by Qwen3.8-27B and GLM-5.3, Universal Dependencies 2.18 treebanks)
with their licenses.