verisbaby/vinai-translate-en2vi-v2-medev-lora
vinai-translate-en2vi-v2 · MedEV LoRA (English→Vietnamese medical translation)
A LoRA adapter that fine-tunes `vinai/vinai-translate-en2vi-v2` (mBART, 448M) on the [`MedEV medical parallel corpus for English→Vietnamese medical translation Dataset`](https://huggingface.co/datasets/nhuvo/MedEV).
🌸🌸🌸
Một bộ chuyển đổi LoRA tinh chỉnh `vinai/vinai-translate-en2vi-v2` (mBART, 448M) trên [`Bộ dữ liệu song ngữ y tế MedEV dành cho dịch thuật y tế tiếng Anh→tiếng Việt`](https://huggingface.co/datasets/nhuvo/MedEV).
This is the adapter only (~25 MB). Load it on top of the official base model, the base is not redistributed here.
What it improves (Nó cải thiện điều gì?)
The base VinAI model is strong on general Vietnamese↔English text but under-performs on clinical language (radiology findings, disease names, anatomical terms). Fine-tuning on MedEV adapts it to the medical domain while keeping the base model's fluency.
Results of Base vs. Base + MedEV LoRA (Kết quả: Base so với Base + MedEV LoRA)
Both rows use the same base model vinai-translate-en2vi-v2; the only difference is whether the MedEV LoRA adapter is attached. Same MedEV test set (N = 500), same decoding (beam = 5), sacreBLEU. Hai dòng dùng cùng một mô hình nền; khác biệt duy nhất là có gắn adapter LoRA hay không.
The MedEV LoRA adapter improves corpus-level BLEU by +1.34 which is a small but real domain-adaptation gain, in line with what LoRA fine-tuning typically yields. BLEU correlates with human judgement at the corpus level, not on single sentences, so the 500-sentence score above (not any individual example) is the valid comparison.
What is "Reference" (REF)? "Reference" (REF) là bản dịch chuẩn do con người viết sẵn, đi kèm tập kiểm thử MedEV. BLEU chấm điểm bằng cách đo mức trùng lặp chuỗi từ (n-gram) giữa bản dịch của mô hình và bản REF này. (The reference is the human translation shipped with the test set; BLEU measures n-gram overlap between a model's output and this reference. Note that MedEV references are sometimes loose/non-literal (see Example 2 below), which is normal for human translation)
Example translations (Ví dụ dịch)
Example 1
The adapter renders the procedure as "cắt đốt nội soi" (a surgical resection sense) rather than the literal "tán hơi", closer to the clinical intent. (Adapter dịch sát ý lâm sàng hơn.)
Example 2
Here the human reference even says "bệnh nhi" (pediatric patients), which is not in the English source, illustrating why single-sentence BLEU is unreliable and why the corpus score is the metric to trust. (Bản tham chiếu của con người còn ghi "bệnh nhi" dù tiếng Anh không có, cho thấy vì sao không nên đánh giá bằng từng câu lẻ.)
Evaluation notes (Ghi chú đánh giá)
- BLEU is a corpus-level metric; do not judge model quality from individual sentences.
- For a clinical application, consider also reporting COMET (better human-correlation) and a small human evaluation of clinical-term accuracy. Nên bổ sung COMET và đánh giá thủ công bởi chuyên gia.
Usage
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from peft import PeftModel
BASE = "vinai/vinai-translate-en2vi-v2"
ADAPTER = "verisbaby/vinai-translate-en2vi-v2-medev-lora" # HF repo id, or a local folder path
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16 if device == "cuda" else torch.float32
# 1) tokenizer: source English, target Vietnamese
tok = AutoTokenizer.from_pretrained(BASE, src_lang="en_XX")
tok.tgt_lang = "vi_VN"
# 2) base model — clear the forced language ids it ships with BEFORE attaching the adapter
model = AutoModelForSeq2SeqLM.from_pretrained(BASE, torch_dtype=dtype)
for attr in ("decoder_start_token_id", "forced_bos_token_id"):
if getattr(model.config, attr, None) is not None:
setattr(model.config, attr, None)
# 3) attach the LoRA adapter
model = PeftModel.from_pretrained(model, ADAPTER).to(device).eval()
vi_id = tok.convert_tokens_to_ids("vi_VN") # force Vietnamese as the first generated token
@torch.inference_mode()
def translate(text: str) -> str:
enc = tok(text, return_tensors="pt", padding=True, truncation=True, max_length=384).to(device)
out = model.generate(
**enc,
decoder_start_token_id=vi_id, forced_bos_token_id=vi_id,
num_beams=5, no_repeat_ngram_size=3, encoder_no_repeat_ngram_size=3,
repetition_penalty=1.2, max_length=384, early_stopping=True,
)
return tok.batch_decode(out, skip_special_tokens=True)[0].strip()
print(translate("Pleural effusion is observed in the right lung base."))
# expected Vietnamese with diacritics, e.g. "Tràn dịch màng phổi được quan sát thấy ở đáy phổi phải."Batch translation (faster for many sentences):
@torch.inference_mode()
def translate_many(texts, batch_size=8):
results = []
for i in range(0, len(texts), batch_size):
chunk = texts[i:i+batch_size]
enc = tok(chunk, return_tensors="pt", padding=True, truncation=True, max_length=384).to(device)
out = model.generate(
**enc, decoder_start_token_id=vi_id, forced_bos_token_id=vi_id,
num_beams=5, no_repeat_ngram_size=3, encoder_no_repeat_ngram_size=3,
repetition_penalty=1.2, max_length=384, early_stopping=True,
)
results.extend(s.strip() for s in tok.batch_decode(out, skip_special_tokens=True))
return resultsSanity check: the output should contain Vietnamese diacritics. If it comes back as English or garbled, the adapter did not attach, make sure you cleareddecoder_start_token_id/forced_bos_token_idon the base config beforePeftModel.from_pretrained, and thatADAPTERpoints to the folder containingadapter_config.json.
Training
- Base:
vinai/vinai-translate-en2vi-v2(mBART-large, 448M;src_lang=en_XX,tgt_lang=vi_VN) - Method: LoRA (PEFT), only adapter weights are trained, base is frozen
- Data: MedEV medical parallel corpus (~360K EN–VI sentence pairs)
- Decoding (recommended):
num_beams=5,no_repeat_ngram_size=3,encoder_no_repeat_ngram_size=3,repetition_penalty=1.2
LoRA config (from the training run):
r = 16
lora_alpha = 32
lora_dropout = 0.1
bias = "none"
task_type = SEQ_2_SEQ_LM
target_modules = ["q_proj", "k_proj", "v_proj", "out_proj"]Intended use & limitations
- Use: assisting English→Vietnamese translation of medical text (radiology reports, findings, disease names) for research and tooling.
- Not for: unsupervised clinical decision-making. Machine translation can mistranslate clinical terms; a qualified human should review medical output. The model can hallucinate on long inputs, use the decoding settings above and validate outputs.
License & attribution
Released under AGPL-3.0, inherited from the base model vinai/vinai-translate-en2vi-v2. If you serve this model over a network, AGPL-3.0 §13 requires you to offer users the complete corresponding source code.
Please cite the VinAI Translate paper when using this model:
@inproceedings{vinaitranslate,
title = {{A Vietnamese-English Neural Machine Translation System}},
author = {Thien Hai Nguyen and Tuan-Duy H. Nguyen and Duy Phung and
Duy Tran-Cong and Hieu Minh Tran and Manh Luong and
Tin Duy Vo and Hung Hai Bui and Dat Quoc Nguyen},
booktitle = {Proceedings of INTERSPEECH},
year = {2022}
}Citation for this adapter
@misc{vimed_medev_lora,
title = {MedEV LoRA adapter for vinai-translate-en2vi-v2 (English-Vietnamese medical translation)},
author = {Tran Thi The Nhan},
year = {2026},
note = {Part of the ViMed Vietnamese Medical VQA project},
url = {https://huggingface.co/verisbaby/vinai-translate-en2vi-v2-medev-lora}
}