Lightweight Vietnamese Legal Text Correction v1.4
fixing OCR errors in legal documents
2 min readupdated
This model is designed to automatically clean and correct Vietnamese text obtained from scanned document recognition (OCR) or typed with typos. The output is a clean legal or administrative document with no distortion of meaning, names, or numbers. Built on a T5 encoder-decoder architecture (the nbdaaa/t5-small-vietnamese model) with 62.5M parameters, it was trained on 2.2 million error-correction pairs. The model offers high processing speed and is ideal for developers and companies focused on document digitization and official form processing.
Key features
- The compact 62.5M parameter size ensures high speed and deployment on CPUs or small GPUs.
- Specialization in fixing typical OCR errors (missing diacritics, confused numbers and letters, run-on words).
- Strict constraints on preserving meaning: the model does not paraphrase, leaving names, numbers, and codes unchanged.
- Support for input strings up to 256 tokens long and output up to 128 tokens long.
What you can do
- Set up post-processing and cleanup for scanned administrative forms, templates, and tables.
- Use as a text preprocessing step for legal retrieval-augmented generation (RAG) search systems.
- Automate the verification of contracts and official government documents in Vietnamese.
Example
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model_path = "protonx-models/protonx-legal-tc-v1.4"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval()
text = "t%eo Th@ng tư s= 27/2019/TT-BTC ngày 14 thán# 5 năm 2019 của Bộ Tài chính"
prefix = "sửa câu: "
inputs = tokenizer(prefix + text, return_tensors="pt").to(device)
outputs = model.generate(**inputs, num_beams=4, max_new_tokens=128)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Read more
DetailsBuilt on
nbdaaa/t5-small-vietnamese and the ViT5 tokenizer.Metrics on the internal benchmark: CER 2.02%, Exact Match 68.10%, ROUGE-L 96.61%.
Trained on 2.2 million line pairs augmented with noise typical of real scans.










Comments