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.
| 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.
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.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. Text as the source name is accepted for an unknown source language.Context: line to translate the text on its own.assistant. Decode greedily and stop at <|im_end|>.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.
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):
\n after
assistant), 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).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.json lists 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 |
Candidates in context (what is new):
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% |
| 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 |
vocab.json for the three tc-big models with separate vocabularies (en-ko, ko-en, zh-ja) is the
target vocabulary, so MarianTokenizer turns Korean or Chinese input into <unk>; the OPUS-MT numbers above
encode the source with its own source.spm ids instead.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.
model.safetensors 1.9 GBpos_head/pos_head.safetensors 11 MBNiuTrans/LMT-60-0.6B