Thai-English Bi-directional Thai Name Transliteration T5
A compact character-level T5 model that transliterates Thai proper names between Thai and Latin script, in both directions, with one shared model.
Proper-name transliteration writes a name in a different script while keeping how it sounds. Thai names are hard to transliterate both ways:
- Many-to-one: distinct Thai spellings can share one romanization. For example, "Sirikarn" can be ศิริกานต์, สิริกาญจน์, or สิรีกานต์.
- One-to-many: one Thai name can have several accepted Latin spellings. For example, สิรีกานต์ can be "Sirikarn", "Sireekan", or "Sireekarn".
Earlier systems mostly target standardized Thai-to-Latin romanization under RTGS (Charoenporn et al., 1999; Aroonmanakun & Rivepiboon, 2004; Chiu et al., 2007). Personal names, however, often follow spellings people choose themselves rather than RTGS.
This model treats both directions as one unified task. It is trained on two datasets:
- a small gold-standard set of natural romanizations written by a native Thai speaker;
- a large silver-standard set of noisy, phonetically aligned name pairs, filtered by a learned trust score.
This is the final ("Small") model from the paper Thai Proper Name Transliteration with Encoder-Decoder Models Augmented with Phonetically-Aligned Data.
Model description
- Architecture: original T5 encoder–decoder (Raffel et al., 2020) with ReLU feed-forward layers, trained from scratch (
T5ForConditionalGeneration)- 4 encoder layers, 4 decoder layers
- Hidden size 256, FFN size 1024
- 4 attention heads
- Tied input/output embeddings
- ~7.6M parameters
- Tokenizer & vocabulary:
- Character-level: one token per Unicode code point. This avoids out-of-vocabulary words and needs no Thai word segmenter.
- One shared vocabulary of 234 tokens: special tokens, the direction tokens, 64 Thai and 24 Latin base characters, and other characters that occur at least 5 times in the silver data. Rarer characters map to
<unk>.
- Special task tokens:
<2en>: Thai → Latin (romanization)<2th>: Latin → Thai (transliteration to Thai)
- Directionality: both directions are trained. Each Thai–Latin pair becomes one TH–EN example and one EN–TH example.
Intended use
Primary use cases
- Thai → Latin romanization of Thai personal names, for cross-lingual information retrieval, entity linking, and data pipelines that need Latin-script names.
- Latin → Thai recovery of Thai spellings from romanized names, for back-transliteration, record linkage, and deduplication across systems. The n-best list gives plausible Thai spellings to choose from.
What the model is not for
- General Thai–English translation
- Transliteration of full sentences or arbitrary text
- High-stakes decisions without human review, for example official documents or passports
Input and output format
Very important: you must prepend a direction token to the input.
Thai → Latin (romanization)
- Input:
<2en>followed by a Thai name - Example input string:
"<2en>อรรถพล" - Output (top candidate):
"atthaphon"(top 3:atthaphon,atphon,attapon)
Latin → Thai
- Input:
<2th>followed by a Latin-script name, lowercased (see Lowercase input only) - Example input string:
"<2th>attapol" - Output (top candidate):
"อรรถพล"
The tokenizer appends <eos> automatically. Latin output is lowercase, matching the training data. Names are short, and generation is capped at 24 output tokens (characters).
Lowercase input only
The model only understands lowercase Latin letters. It was trained on lowercase romanizations, and uppercase letters (apart from a stray A and B) are not in its vocabulary. An uppercase letter becomes <unk>, so the model effectively never sees it:
| Input given to the model | What the model actually reads | Top output |
|---|---|---|
Thikhumporn (not lowercased) | <unk>hikhumporn, i.e. "hikhumporn" | หิคุมพร ✗ |
thikhumporn (lowercased) | thikhumporn | ทิฆัมพร ✓ |
Every uppercase letter must be lowercased before the name enters the model. The tokenizer in this repo does this for you: it includes a Lowercase normalizer, so Thikhumporn, THIKHUMPORN, and thikhumporn all give the same result. If you use the raw checkpoint, a different tokenizer, or your own preprocessing, call name.lower() first. Lowercasing has no effect on Thai characters.
Quickstart
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model_id = "Sira-D/thai-english-bidirectional-thai-name-transliteration-t5"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id).eval()
def translit_thai_to_latin(name_thai: str) -> str:
inputs = tokenizer("<2en>" + name_thai.strip(), return_tensors="pt")
with torch.no_grad():
output = model.generate(**inputs, num_beams=5, num_return_sequences=1,
length_penalty=0.7, max_new_tokens=24)
return tokenizer.decode(output[0], skip_special_tokens=True)
def translit_latin_to_thai(name_latin: str) -> str:
inputs = tokenizer("<2th>" + name_latin.strip().lower(), return_tensors="pt")
with torch.no_grad():
output = model.generate(**inputs, num_beams=5, num_return_sequences=1,
length_penalty=0.7, max_new_tokens=24)
return tokenizer.decode(output[0], skip_special_tokens=True)
print(translit_thai_to_latin("อรรถพล")) # atthaphon
print(translit_latin_to_thai("attapol")) # อรรถพล
print(translit_latin_to_thai("Thikhumporn")) # ทิฆัมพร (lowercased to "thikhumporn" first)
Getting ranked alternatives
Many romanizations map to several valid Thai spellings, so it helps to ask for several candidates. The paper reports top-3 accuracy with beam search: 5 beams, top 3 returned, length penalty 0.7. These are also the defaults in generation_config.json.
def ranked_transliterations(name: str, direction: str = "<2th>", k: int = 3):
text = direction + (name.strip().lower() if direction == "<2th>" else name.strip())
inputs = tokenizer(text, return_tensors="pt")
with torch.no_grad():
outputs = model.generate(**inputs, num_beams=max(5, k), num_return_sequences=k,
length_penalty=0.7, max_new_tokens=24)
return tokenizer.batch_decode(outputs, skip_special_tokens=True)
print(ranked_transliterations("wongduean", "<2th>")) # ['วงศ์เดือน', 'วงษ์เดือน', 'วงเดือน']
print(ranked_transliterations("sirikan", "<2th>")) # ['ศิริกาญจน์', 'ศิริกานต์', 'สิริกาญจน์']
For Latin → Thai the gap between top-1 and top-3 accuracy is large (0.56 vs. 0.81). The correct spelling is usually among the candidates, but the Latin input often lacks the information needed to rank it first.
Data and quality scoring (summary)
The training data comes from two complementary corpora built from the same pool of names. Both corpora and the experiment code will be released when the paper is accepted.
Gold-standard corpus
- 3,269 Thai names. For each name, a native Thai annotator wrote up to three Latin spellings that a person with that name would likely use. This targets natural personal preference, not strict RTGS.
- Split 9:1 by unique Thai name:
- train: 2,944 rows, 6,595 name–romanization pairs, 13,190 directional examples;
- dev: 323 names for TH–EN, 747 pairs for EN–TH.
Silver-standard corpus
- Thai–Latin name pairs collected from:
- Thai government-announcement PDFs and social-media pages where people give their names in both scripts;
- automatic transliteration engines: Mondonomo's universal transliteration model, PyThaiNLP ROYIN (Phatthiyaphaibun et al., 2023), TLTK 1.2.1, Google Input Tools, and Microsoft Azure Translator.
- A random-forest classifier gives each pair a continuous trust score in [0, 1]. It has 500 trees, depth 10, and 0.85 accuracy on 3,079 hand-labelled pairs. Its features are:
- count_th / count_latin: how often the exact Thai and Latin forms occur in the scraped records;
- phonetic distance: PanPhon weighted feature edit distance (Mortensen et al., 2016) between the CharsiuG2P IPA forms (Zhu et al., 2022);
- RTGS similarity: Levenshtein distance to the RTGS romanization of the Thai name.
- After removing any pair whose Thai name appears in the gold set (to prevent dev leakage), 3,437,253 pairs remain.
Training pipeline (mixed → gold)
- Mixed pre-training for 10 epochs at learning rate 5e-4 on gold data plus silver pairs with trust score ≥ 0.3.
- Gold fine-tuning on gold data only. The learning rate and epoch count were picked from the grid {1e-4, 3e-4} × {5, 10, 15} by dev-set exact-match accuracy.
Other settings: AdamW (Loshchilov & Hutter, 2019), batch size 256, weight decay 0.01, label smoothing 0.1, gradient clipping 1.0, dropout 0.1, seed 42. Training ran on a single NVIDIA L4 GPU. The checkpoint's full training config is in training_config.json.
Evaluation
Results on the gold-standard dev split:
| Model | TH–EN CER | TH–EN acc | TH–EN acc@3 | EN–TH CER | EN–TH acc | EN–TH acc@3 |
|---|---|---|---|---|---|---|
| TLTK (RTGS) | 0.0366 | 0.8854 | – | – | – | – |
| GPT-5 (zero-shot) | – | – | – | 0.1791 | 0.4926 | 0.7390 |
| Gold-only baseline (Very Small) | 0.0388 | 0.8297 | 0.9102 | 0.2748 | 0.2878 | 0.5047 |
| Very Small, mixed → gold, thr 0.3 | 0.0125 | 0.9226 | 0.9845 | 0.1751 | 0.5207 | 0.7617 |
| This model (Small, mixed → gold, thr 0.3) | 0.0121 | 0.9350 | 0.9876 | 0.1463 | 0.5649 | 0.8086 |
| Medium, mixed → gold, thr 0.3 | 0.0181 | 0.9102 | 0.9752 | 0.1801 | 0.4670 | 0.7309 |
- TH–EN is scored once per Thai name against all of its annotated romanizations (multi-reference).
- EN–TH is scored against the single Thai spelling paired with each romanization.
- Accuracy@3 counts a hit if any of the top-3 beam outputs matches exactly.
Limitations
- Latin → Thai loses information. A romanization drops Thai orthographic detail: consonant choice (จ vs. ช), vowel length (-ชัน vs. -ชาญ), and silent letters (
์). Many outputs that the metric counts wrong are still valid Thai names. Prefer the ranked n-best list over the single top output. - Domain: the model is trained on Thai personal names. Expect worse results on common nouns, place names, foreign names, or phrases.
- Romanization style: outputs follow common personal-name spelling habits from the gold annotations. They do not follow RTGS or any other formal standard.
- Data noise and bias: the silver data comes from web scraping and automatic engines. It is filtered but still noisy, and its biases and coverage gaps may show up in the outputs.
- Evaluation scope: results come from one annotator's gold dev split of 323 names. Use human review for high-stakes or irreversible decisions.