Instructions to use febilly/Hy-MT3-1.8B-StreamRevise-LoRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use febilly/Hy-MT3-1.8B-StreamRevise-LoRA with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("tencent/Hy-MT3-1.8B") model = PeftModel.from_pretrained(base_model, "febilly/Hy-MT3-1.8B-StreamRevise-LoRA") - Notebooks
- Google Colab
- Kaggle
Hy-MT3-1.8B-StreamRevise (LoRA)
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.
Prompt format
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.
Streaming translation (partial & final)
【背景信息】
这是实时语音字幕翻译:结合上下文与上一版译文,尽量沿用仍然正确的前缀;进行中可输出半句且不猜后文,本句结束时补全结尾。
前文上下文:
{RECENT_SOURCE_1}
{RECENT_SOURCE_2}
上一版译文:
{PREVIOUS_TRANSLATION}
状态:{STATE}
请结合背景信息将以下文本翻译为{TARGET_LANGUAGE},注意只需要输出翻译后的结果,不要额外解释。
【待翻译文本】
{CURRENT_SOURCE}
{STATE}is进行中for partial updates and本句结束for finalized utterances.- Omit
前文上下文:when there is no history; omit上一版译文:on the first update of a new utterance. previous_sourceis intentionally excluded: comparing上一版译文directly against【待翻译文本】avoids exposure bias and improves correction of stale translation errors.- Keep at most the latest 5 source utterances in
前文上下文:.
Standalone whole-sentence translation
将以下文本翻译为{TARGET_LANGUAGE},注意只需要输出翻译后的结果,不要额外解释:
{SOURCE_TEXT}
Chat template
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|>).
Copy-paste renderer
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}"
Streaming example
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 本句结束.
Usage
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))
Driving it as a stream
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.
Evaluation
Evaluated with greedy decoding (do_sample=False / temperature=0, repeat_penalty=1.0).
FLORES-200 devtest (Q4_K_M GGUF, full 1,012 examples × 6 directions)
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 |
Streaming behavior & diagnostic probes (BF16 adapter vs. Q4_K_M GGUF)
| 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 |
Training
| 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 |
Data construction
The training corpus is balanced across all six directions between Chinese, English, and Japanese and combines spoken subtitles/transcripts with general text:
- Strict causal progression: streaming trajectories are constructed strictly step by step without exposing future source text to intermediate steps, preventing future-content hallucination.
- Minimal-edit on-policy supervision: base-model translations anchor lexical style and general translation knowledge, while streaming revisions teach prefix reuse, non-speculative partial output without premature punctuation, ASR-revision recovery, and clean finalization.
- Error-recovery & ASR-jitter coverage: ~16.6% of streaming steps explicitly train recovery from stale translation errors and ASR back-revisions; partial inputs also include simulated tentative ASR periods and mid-clause cuts.
- Standalone anchors: 15% of training examples are unmodified whole-sentence translation anchors so ordinary one-shot translation remains intact.
The training dataset is not released.
Limitations
- Stability is a learned tendency, not a hard constraint. Substantive ASR revisions can and should rewrite earlier words.
- Prompt format matters. Off-format prompts reduce prefix stability and punctuation control.
- Primary training coverage is Chinese, English, and Japanese. Zero-shot cross-lingual streaming works on
tested pairs (
ko→zh,fr→zh,es→en), but non-core directions were not trained directly. - Sentence-scoped revision. Finalized earlier subtitles are not revisited.
- Greedy decoding is assumed.
- Garbled or highly incomplete ASR hypotheses can still cause mistranslations; the adapter inherits the base model's limitations.
License
Apache 2.0, matching tencent/Hy-MT3-1.8B.
- Downloads last month
- 8