English | 中文
A LoRA adapter for tencent/Hy-MT3-1.8B, fine-tuned for
live subtitle translation with incrementally changing ASR hypotheses.
On every ASR update, the caller sends the current source hypothesis, the previous translation of the current
utterance (if any), optional recent source-only context sentences, and an explicit state (进行中 for
in-progress partials or 本句结束 for finalized utterances). The adapter teaches the model to preserve
still-correct prefixes, extend translations without guessing unuttered words or emitting premature terminal
punctuation during partials, revise when ASR corrects earlier speech, and finalize cleanly with appropriate
punctuation when the utterance ends.
For a ready-to-run 4-bit local model (1.13 GB / 1.06 GiB), use Hy-MT3-1.8B-StreamRevise-GGUF.
The adapter uses Hy-MT3's 【背景信息】 / 【待翻译文本】 layout with Chinese target language names
(中文, 英语, 日语, etc.) and source-only context placed at the beginning of the prompt so inference
engines can reuse the prefix KV cache across updates of the same utterance.
【背景信息】
这是实时语音字幕翻译:结合上下文与上一版译文,尽量沿用仍然正确的前缀;进行中可输出半句且不猜后文,本句结束时补全结尾。
前文上下文:
{RECENT_SOURCE_1}
{RECENT_SOURCE_2}
上一版译文:
{PREVIOUS_TRANSLATION}
状态:{STATE}
请结合背景信息将以下文本翻译为{TARGET_LANGUAGE},注意只需要输出翻译后的结果,不要额外解释。
【待翻译文本】
{CURRENT_SOURCE}
{STATE} is 进行中 for partial updates and 本句结束 for finalized utterances.前文上下文: when there is no history; omit 上一版译文: on the first update of a new utterance.previous_source is intentionally excluded: comparing 上一版译文 directly against 【待翻译文本】
avoids exposure bias and improves correction of stale translation errors.前文上下文:.将以下文本翻译为{TARGET_LANGUAGE},注意只需要输出翻译后的结果,不要额外解释:
{SOURCE_TEXT}
Use a single user turn. tokenizer.apply_chat_template handles the wrapper; for raw completion endpoints
the exact layout is:
<|hy_begin▁of▁sentence|><|hy_User|>{PROMPT}<|hy_Assistant|>
Generation stops on token 120020 (<|hy_place▁holder▁no▁2|>).
LANG_NAMES_ZH = {
"zh": "中文",
"en": "英语",
"ja": "日语",
"ko": "韩语",
"fr": "法语",
"de": "德语",
"es": "西班牙语",
"ru": "俄语",
"pt": "葡萄牙语",
"it": "意大利语",
}
STREAM_INSTRUCTION = (
"这是实时语音字幕翻译:结合上下文与上一版译文,尽量沿用仍然正确的前缀;"
"进行中可输出半句且不猜后文,本句结束时补全结尾。"
)
def render_streaming_prompt(
*,
target_language: str,
current_source: str,
is_final: bool,
history=(),
previous_translation: str = "",
) -> str:
target = LANG_NAMES_ZH.get(target_language.lower(), target_language)
bg_parts = [STREAM_INSTRUCTION]
hist_lines = [str(s).strip() for s in history[-5:] if str(s or "").strip()]
if hist_lines:
bg_parts.append("前文上下文:\n" + "\n".join(hist_lines))
prev_tgt = (previous_translation or "").strip()
if prev_tgt:
bg_parts.append("上一版译文:\n" + prev_tgt)
state_label = "本句结束" if is_final else "进行中"
bg_parts.append(f"状态:{state_label}")
return (
"【背景信息】\n"
+ "\n\n".join(bg_parts)
+ f"\n\n请结合背景信息将以下文本翻译为{target},注意只需要输出翻译后的结果,不要额外解释。\n\n"
+ f"【待翻译文本】\n{current_source}"
)
def render_native_prompt(*, target_language: str, text: str) -> str:
target = LANG_NAMES_ZH.get(target_language.lower(), target_language)
return f"将以下文本翻译为{target},注意只需要输出翻译后的结果,不要额外解释:\n\n{text}"
An actual greedy Q4_K_M run on a synthetic English-to-Chinese ASR trajectory:
| step | state | current_source |
previous_translation |
output |
|---|---|---|---|---|
| 1 | 进行中 |
The morning train. |
(none) | 早晨的火车 |
| 2 | 进行中 |
The morning train was delayed by ten minutes because of the heavy rain. |
早晨的火车 |
早晨的火车因大雨晚点十分钟 |
| 3 | 进行中 |
The morning train was delayed by ten minutes because of the heavy rain, so we decided to walk to the next station. |
早晨的火车因大雨晚点十分钟 |
早晨的火车因大雨晚点十分钟,所以我们决定步行到下一站 |
| 4 | 本句结束 |
The morning train was delayed by ten minutes because of the heavy rain, so we decided to walk to the next station. |
早晨的火车因大雨晚点十分钟,所以我们决定步行到下一站 |
早晨的火车因大雨晚点十分钟,所以我们决定步行到下一站。 |
Notice how partial steps strip the ASR's tentative period, preserve the established prefix verbatim across
extensions, and only add the final period on 本句结束.
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
BASE = "tencent/Hy-MT3-1.8B"
ADAPTER = "febilly/Hy-MT3-1.8B-StreamRevise-LoRA"
tokenizer = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
BASE, dtype=torch.bfloat16, device_map="auto", trust_remote_code=True
)
model = PeftModel.from_pretrained(model, ADAPTER).eval()
def translate(prompt: str) -> str:
text = tokenizer.apply_chat_template(
[{"role": "user", "content": prompt}],
tokenize=False,
add_generation_prompt=True,
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.inference_mode():
output = model.generate(
**inputs,
do_sample=False,
max_new_tokens=160,
eos_token_id=120020,
pad_token_id=tokenizer.pad_token_id,
)
return tokenizer.decode(
output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True
).strip()
prompt = render_streaming_prompt(
target_language="zh",
current_source="The morning train was delayed by ten minutes because of the heavy rain, so we decided to walk to the next station.",
is_final=True,
history=["The weather forecast warned about a storm this morning."],
previous_translation="早晨的火车因大雨晚点十分钟",
)
print(translate(prompt))
The model is stateless; the caller owns the revision chain:
history = []
previous_translation = ""
for current_source, is_final in asr_updates():
output = translate(
render_streaming_prompt(
target_language="zh",
current_source=current_source,
is_final=is_final,
history=history,
previous_translation=previous_translation,
)
)
if output:
display(output)
previous_translation = output
if is_final:
if current_source.strip():
history.append(current_source.strip())
history = history[-5:]
previous_translation = ""
Always use greedy decoding (do_sample=False / temperature=0) and enable prefix KV caching when
supported by your inference engine.
Evaluated with greedy decoding (do_sample=False / temperature=0, repeat_penalty=1.0).
Corpus chrF (word_order=0) on native whole-sentence translation — 46.194 combined corpus (41.318
6-direction mean):
| direction | chrF |
|---|---|
| Japanese → Chinese | 26.408 |
| Chinese → Japanese | 32.231 |
| English → Chinese | 36.794 |
| Chinese → English | 57.770 |
| Japanese → English | 55.341 |
| English → Japanese | 39.364 |
| benchmark / metric | BF16 adapter | Q4_K_M GGUF |
|---|---|---|
254 closed-loop chains — partial punct violation ↓ |
0.13% | 0.25% |
254 closed-loop chains — final punct completion ↑ |
91.73% | 90.55% |
254 closed-loop chains — partial / final LCP ↑ |
0.755 / 0.877 | 0.813 / 0.916 |
Real 3-audio ASR replay — partial punct violation ↓ |
0.00% | 0.34% |
Real 3-audio ASR replay — p2p LCP / same-src p→f LCP ↑ |
0.920 / 1.000 | 0.934 / 0.995 |
| Stale-error 2-step repair / false-rewrite probe | 91.7% / 8.3% | 91.7% / 8.3% |
| ASR revision probe | 90.9% | 90.9% |
| Context polysemy probe | 79.2% | 87.5% |
Unseen zero-shot streaming (ko→zh / fr→zh / es→en chrF++) |
20.68 / 24.23 / 59.07 | 20.06 / 23.96 / 58.74 |
| item | value |
|---|---|
| Base model | tencent/Hy-MT3-1.8B (HunYuanDenseV1, 32 layers, hidden size 2048, 16 Q / 4 KV heads) |
| Method | Attention-only LoRA (r=32, alpha=64, dropout=0.05) |
| Target modules | q_proj, k_proj, v_proj, o_proj (128 linear layers across 32 transformer blocks) |
| Trainable parameters | 13,631,488 (~0.75%) |
| Training set | 18,555 examples (13,162 regular streaming steps + 2,610 repair steps + 2,783 native anchors) |
| Schedule | 2 epochs, 1,160 optimizer steps, per-device batch size 8, grad accum 4 (effective batch size 32) |
| Optimizer | AdamW (weight_decay=0.01), peak LR 1e-4, 6% linear warmup, cosine decay, seed 42 |
| Precision | bf16 |
The training corpus is balanced across all six directions between Chinese, English, and Japanese and combines spoken subtitles/transcripts with general text:
The training dataset is not released.
ko→zh, fr→zh, es→en), but non-core directions were not trained directly.Apache 2.0, matching tencent/Hy-MT3-1.8B.
tencent/Hy-MT3-1.8B