Lightweight Vietnamese Text Correction v1.4

HuggingFace Website Colab Discord


Introduction

ProtonX Text Correction v1.4

A lightweight Vietnamese text correction model with 62.5M parameters, about a quarter of ProtonX Text Correction v1.3.1 (226M). It is built for OCR post-processing of scanned documents, forms and tables, and also cleans everyday typed Vietnamese text: messages, product and service text, school and office documents.

The model is optimized to clean up real-world OCR and typing mistakes such as:

  • missing or incorrect diacritics, also on lines written in capitals
  • broken word segmentation (merged and split words, also around numbers)
  • keyboard and Telex typos
  • misrecognized administrative terms
  • OCR symbol noise and look-alike characters (letters read as digits and digits read as letters)
  • misread fixed phrases of documents and forms: national title and motto, province names, form labels, relations

Built on a T5 encoder-decoder, the model is trained on about 2.2 million correction pairs, covering:

  • official documents and general Vietnamese text
  • OCR outputs from scanned PDFs, tables and administrative forms
  • typed text with missing diacritics, keyboard and Telex typos

Strict constraints ensure:

  • Correction ≠ rewriting
  • the meaning of the text must never change
  • people's names, numbers and document codes are kept as written
  • correct text is left unchanged
  • no paraphrasing

LICENSE

This model is released under the ProtonX Text Correction Model License (v1.4-NC).

See LICENSE.md for full terms, conditions, and usage restrictions.

Current Version: v1.4

Highlights

  • 62.5M parameters; about 4.8 times the throughput of ProtonX v1.3.1 on the same GPU

  • Much stronger than v1.3.1 on split and merged words, Telex typos, digit/letter confusions and spacing around numbers

  • Works line by line: up to 256 input tokens and 128 output tokens per line

  • Handles form and table lines from scanned documents, including uppercase lines, rare names and codes

  • Optional post-processing rules for fixed phrases of Vietnamese documents (see the last section)


Quick Usage with Transformers

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()

examples = [
    "Thong tu so 27/2019/TT-BTC ngay 14/05/2019 cua Bo Tai chinh huong dan muc thu phi tham dinh",
    "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",
    "Các thiết bị quản trị phải được cài đạt hệ điều hành, phàn mêm sạch, có các lóp tường lửa bảo vệ.",
]

prefix = "sửa câu: "  # required

inputs = tokenizer(
    [prefix + text for text in examples],
    return_tensors="pt",
    padding=True,
    truncation=True,
    max_length=256
).to(device)

with torch.no_grad():
    outputs = model.generate(
        **inputs,
        num_beams=4,
        max_new_tokens=128,
        early_stopping=True
    )

for text, output in zip(examples, tokenizer.batch_decode(outputs, skip_special_tokens=True)):
    print(f"Input: {text}")
    print(f"Output: {output}")
    print("-" * 40)

Correct one line at a time. Split long paragraphs into sentences or clauses of at most about 128 tokens before correcting them.


Benchmark

Internal Error-Type Benchmark (private)

30,398 held-out sentences in 11 error groups: OCR of official documents, real OCR lines, diacritics, keyboard and Telex typos, merged and split words, digit and letter confusions, spacing around numbers, look-alike letters, social-media normalization and others.

Metric v1.4 (62.5M) ProtonX v1.3.1 (226M)
CER ↓ (all sentences) 2.02% 5.07%
Exact match ↑ (all sentences) 68.10% 52.32%
ROUGE-L ↑ (all sentences) 96.61% 93.53%
CER ↓ (11 groups, each weighted equally) 1.77% 6.32%
Exact match ↑ (11 groups, each weighted equally) 70.88% 37.01%
ROUGE-L ↑ (11 groups, each weighted equally) 96.16% 89.84%

By error group (CER ↓ / exact match ↑):

Error group Sentences v1.4 (62.5M) ProtonX v1.3.1 (226M)
Split words 1,000 0.23% / 96.9% 14.72% / 13.9%
Merged words 1,000 0.27% / 95.4% 1.44% / 77.8%
Spacing around numbers 1,000 0.17% / 94.7% 3.14% / 10.6%
Digit confusions 1,000 0.16% / 95.1% 2.86% / 10.8%
Look-alike letters 1,000 0.44% / 91.2% 2.93% / 57.3%
Diacritics and typos (vi-spelling-correction) 3,000 0.61% / 80.3% 4.35% / 38.1%
Typos (vn-spell-correction held-out) 3,000 1.29% / 56.7% 2.95% / 38.7%
Telex/VNI typos, wrong capitals, swapped words (unseen noise generator) 3,000 4.60% / 21.0% 10.76% / 18.0%
Social-media normalization 1,045 7.57% / 21.9% 9.19% / 16.2%
Real OCR lines 150 2.32% / 54.7% 13.01% / 52.7%
OCR of official documents 15,203 1.80% / 71.8% 4.17% / 73.1%

CER: character error rate. Exact match: share of sentences corrected exactly. ROUGE-L: word-level F1 after lowercasing. Decoding: beam 4 for v1.4; beam 10 and 160 tokens for v1.3.1, as recommended on its model card.

ProtonX Text Correction Validation Dataset

Model ROUGE-L
v1.4 (62.5M) TBA
ProtonX v1.3.1 (226M) 96.95%

The v1.3.1 score is the one reported on its model card.

Benchmark Dataset


Training Details

  • Model: T5-small encoder-decoder, 62.5M parameters (6+6 layers, d_model 512), from nbdaaa/t5-small-vietnamese with the ViT5 tokenizer
  • About 2.2 million noisy → clean line pairs, in several continued-training rounds
  • Augmentation for official documents, forms and general text with OCR noise following the error profile of real scanned documents
  • Beam search decoding (4 beams)
  • Max sequence length: 256 input tokens and 128 output tokens per line
  • Input prefix: sửa câu:

Domain Coverage:

  • Government decrees and resolutions
  • Contracts and business documents
  • Administrative procedures and forms (civil status, residence, enterprise registration)
  • Tables and financial reports
  • OCR-normalized scanned documents
  • General Vietnamese text: news, education, services, everyday messages

Example Outputs

Input:

Thong tu so 27/2019/TT-BTC ngay 14/05/2019 cua Bo Tai chinh huong dan muc thu phi tham dinh
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
Hợp đồng lac động có hiệu lực từ ngày ký theo quy định tại điều30
Các thiết bị quản trị phải được cài đạt hệ điều hành, phàn mêm sạch, có các lóp tường lửa bảo vệ.

Output:

Thông tư số 27/2019/TT-BTC ngày 14/05/2019 của Bộ Tài chính hướng dẫn mức thu phí thẩm định
theo Thông tư số 27/2019/TT-BTC ngày 14 tháng 5 năm 2019 của Bộ Tài chính
Hợp đồng lao động có hiệu lực từ ngày ký theo quy định tại điều 30
Các thiết bị quản trị phải được cài đặt hệ điều hành, phần mềm sạch, có các lớp tường lửa bảo vệ.

Input (form lines, made-up data):

CONG HOA XA HOI CHU NGHIA VIET NAM
Họ và tên: TRẦN THỊ KHUÊ
Quan hệ với người được khai sinh: Mẻ đẹ
Nơi thường trú tạm tru: Số 45 đường Hoa Sữa, phường Tân Hòa
Số hồ sơ: 503217/11/09/0031

Output:

CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM
Họ và tên: TRẦN THỊ KHUÊ
Quan hệ với người được khai sinh: Mẹ đẻ
Nơi thường trú/tạm trú: Số 45 đường Hoa Sữa, phường Tân Hòa
Số hồ sơ: 503217/11/09/0031

v1.4 vs v1.3.1

Made-up lines, model outputs without post-processing rules.

Error Input v1.4 (62.5M) ProtonX v1.3.1 (226M)
Split words Hà ng hó a đượ c vậ n chuyể n bằ ng đườ ng bộ Hàng hóa được vận chuyển bằng đường bộ Hàm ứng phó ra được cơ vận án chuyển án bằng đường đường cán bộ
Split words Thờ i tiế t hôm nay có mư a rà o Thời tiết hôm nay có mưa rào Thời gian tiếp từ hôm nay có mưa rào rào
Split words Khách hà ng vui lò ng giữ hó a đơn để đổi trả Khách hàng vui lòng giữ hóa đơn để đổi trả Khách hàng ở vui lòng ứng giữ hóa đơn để đổi trả
Split words Cơ qu an có thẩm quy ền giải quy ết thủ tụ c Cơ quan có thẩm quyền giải quyết thủ tục Cơ quan ban có thẩm quyền giải quyết thủ tục cơ
Telex typos Toi muoons ddawng kys hocj theem lowps tieengs Anh Tôi muốn đăng ký học thêm lớp tiếng Anh Tôi muons ddawing kys hoc theem lowps tieengs Anh
Merged words Kếtquả học tập củahọc sinh được thôngbáo cho phụhuynh Kết quả học tập của học sinh được thông báo cho phụ huynh Kết quả học tập của học sinh được thông báo cho phụ huynh. (adds a period)
No diacritics Hom nay toi di cho mua rau va thit de nau com toi Hôm nay tôi đi chợ mua rau và thịt để nấu cơm tối Hôm nay tôi đi chợ mua rau và thịt để nấu cơm tôi
Letter read as digit Phòng họp số 3 tầng 1O, tòa nhà B Phòng họp số 3 tầng 10, tòa nhà B Phòng họp số 3 tầng 1O, tòa nhà B
Spacing around numbers Thời gian làm việc từ 8giờ đến 17 giờ 30phút Thời gian làm việc từ 8 giờ đến 17 giờ 30 phút Thời gian làm việc từ 8 giờ đến 17 giờ 30phút

Use Cases

  • OCR post-processing of scanned documents, forms and tables
  • Digitizing administrative forms
  • Standardizing official and business documents
  • Proofreading contracts, reports and everyday typed text
  • Restoring diacritics and fixing Telex typos in user input
  • Preprocessing for search and RAG systems
  • Low-cost deployment on CPU or small GPUs

Limitations

  • Does not paraphrase or rewrite text
  • Cannot restore missing semantic content
  • Works on single lines: quality drops on long paragraphs, which should be split first
  • Primarily optimized for Vietnamese; foreign words inside a line may be altered
  • Heavy slang and abbreviations of social media are only partly normalized
  • Outputs should be reviewed before use in official documents

Future Work

  • Higher accuracy on the ProtonX validation dataset
  • Longer inputs for long clauses and paragraphs
  • Wider coverage of handwritten form fields

Optional: Post-Processing Rules

What for: deterministic fixes the model may miss on forms and official headers. It keeps uppercase names and long numbers or codes the model changed (a rare uppercase given name, …/11/09/0031), restores fixed phrases (national title and motto, province names, form labels, relations), puts a misread motto back (Độc lập - Tuyền - Hạnh phúc → Độc lập - Tự do - Hạnh phúc) and fixes dates written in words. It changes nothing else and adds well under a millisecond per line.

When to use: OCR of scanned administrative documents and forms. For other text it rarely changes anything and can be left off.

from transformers import pipeline

fix = pipeline(model="protonx-models/protonx-legal-tc-v1.4", trust_remote_code=True)  # add device=0 for a GPU

print(fix("Độc lập - Tuyền - Hạnh phúc"))                # Độc lập - Tự do - Hạnh phúc
print(fix("Độc lập - Tuyền - Hạnh phúc", rules=False))   # model only: Độc lập - Tuyển - Hạnh phúc
print(fix(["dòng 1\ndòng 2", "dòng 3"]))                  # a list gives a list; each line is corrected on its own

The pipeline adds the prefix, corrects each line, then applies keep_source and the rules from phrase_rules.py / phrase_rules.json in this repository (pure Python, no extra dependency).


Fine-tuned on


Acknowledgments

Thanks to:

Downloads last month
215
Safetensors
Model size
62.5M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for protonx-models/protonx-tc-v1.4

Finetuned
(1)
this model