ViT5 for Vietnamese diacritic restoration

Adds the accents back to Vietnamese text typed without them: toi di hoc o truong dai hoc -> tôi đi học ở trường đại học.

ViT5-base fine-tuned as a sequence-to-sequence model on 100,000 lowercase sentences from Vietnamese Wikipedia (1 epoch). A smaller model from the same project, a BiLSTM, runs right in your browser in the live demo.

Results (held-out test set, 16,516 Wikipedia sentences)

Model Syllable accuracy Sentence accuracy
Bigram + Viterbi baseline 94.47% 47.95%
Character BiLSTM, trained from scratch 94.73% 49.04%
This model 95.43% 55.35%

Sentence accuracy is the share of sentences where every word is correct.

How to use

from transformers import AutoModelForSeq2SeqLM, PreTrainedTokenizerFast

tokenizer = PreTrainedTokenizerFast.from_pretrained("hao0256/vit5-vietnamese-diacritics")
model = AutoModelForSeq2SeqLM.from_pretrained("hao0256/vit5-vietnamese-diacritics")

inputs = tokenizer(["toi di hoc o truong dai hoc"], return_tensors="pt")
output = model.generate(**inputs, max_new_tokens=64)
print(tokenizer.decode(output[0], skip_special_tokens=True))

Notes:

  • Input should be lowercase, one sentence at a time, which is the format the model was trained on.
  • Load the tokenizer with PreTrainedTokenizerFast: with transformers 5, AutoTokenizer fails on ViT5's BPE tokenizer.
  • The model generates text, so it can occasionally drop or change a word. The demo aligns the output with the input and keeps only the accents (see app.py in the Space).

Limitations

Trained on Wikipedia, which is formal text: slang, abbreviations and chat-style text may work less well. Proper names are the hardest case, partly because the training text was lowercased.

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

Model tree for hao0256/vit5-vietnamese-diacritics

Base model

VietAI/vit5-base
Finetuned
(112)
this model

Dataset used to train hao0256/vit5-vietnamese-diacritics

Space using hao0256/vit5-vietnamese-diacritics 1