Skip to main content

thairom

PyPI Python License: MIT

Accurate Thai and Lao/Isan romanization for real-world text -- song lyrics, colloquial speech, and dialects.

Installation

pip install thairom

Quick Start

from thairom import romanize

# Thai
print(romanize('สวัสดีครับ'))       # sawatdee krap
print(romanize('ขอบคุณมาก'))       # khop khun mak
print(romanize('หัวใจ'))           # hua jai

# Lao/Isan
print(romanize('ฮักเจ้าหลาย', lang='lo'))  # hak jao laai
print(romanize('ม่วนคัก', lang='lo'))       # muan khak

Features

  • Thai romanization from a curated word map plus a rule-based syllable transliterator for everything else (pythainlp's royin engine is available behind royin=True, off by default: it writes ขนมปัง as "khnmpang")
  • knows(word) tells you whether an answer came from the map or an unambiguous rule, so an app can route the guesses to a second romanizer
  • Lao/Isan dialect support for Thai-script Isan text with proper pronunciation rules (r-to-l substitution, etc.)
  • Word correction maps that fix common pythainlp errors on colloquial vocabulary, song lyrics, and everyday phrases
  • Handles real-world text -- tested against song lyrics, spoken Thai, and Isan dialect ground truth data
  • Clean output -- strips leaked Thai/Lao characters and normalizes whitespace

Why thairom instead of pythainlp alone?

pythainlp's royin romanization engine is solid for formal Thai, but it struggles with colloquial speech, song lyrics, and regional dialects. thairom builds on pythainlp and fixes these gaps:

Thai Text pythainlp (royin) thairom Correct
หัวใจ hua chai hua jai hua jai
น้ำตา nam ta nam dta nam dta
เข้าใจ khao chai khao jai khao jai
ก็ ko kaw kaw
เวลา wela welaa welaa
ตลอดเวลา talot wela talod welaa talod welaa
ขอบคุณ khop khun khop khun khop khun
ฮักเจ้าหลาย (no Isan support) hak jao laai hak jao laai

thairom also handles Isan/Lao dialect written in Thai script, which pythainlp does not support at all.

API Reference

romanize(text, lang='th', royin=None)

Top-level convenience function. Dispatches to romanize_thai or romanize_lao based on lang.

Parameters:

  • text (str): Text to romanize.
  • lang (str): 'th' for Thai (default), 'lo' for Lao/Isan.

Returns: Lowercase romanized string.

romanize_thai(text)

Romanize Thai text using pythainlp with word-level corrections from THAI_WORD_MAP.

Parameters:

  • text (str): Thai text to romanize.

Returns: Lowercase romanized string.

romanize_lao(text)

Romanize Isan/Lao text written in Thai script. Applies Lao pronunciation rules (e.g., initial r becomes l) and word corrections from LAO_WORD_MAP.

Parameters:

  • text (str): Isan/Lao text in Thai script.

Returns: Lowercase romanized string.

Word Maps

The correction maps are available as importable dictionaries for inspection or extension:

from thairom.maps import THAI_WORD_MAP, LAO_WORD_MAP

Contributing

Contributions are welcome, especially additions to the word correction maps. The maps were developed using an autoresearch pipeline that scores romanization output against ground truth data. If you find a word that romanizes incorrectly:

  1. Add the word and its correct romanization to THAI_WORD_MAP or LAO_WORD_MAP in src/thairom/maps.py.
  2. Add a test case to tests/test_romanize.py.
  3. Run pytest to verify.
  4. Submit a pull request.

Auditing a flashcard catalog

Install the optional reviewer and run a small calibration batch first:

pip install -e ".[review]"
thairom-review review cards.json review-results.jsonl --limit 100
thairom-review summarize review-results.jsonl review-summary

Only change results at or above 0.95 confidence enter review-summary/changes.json. Ambiguous spelling, names, dialect, and lower confidence decisions go to review-summary/uncertain.json for human review. Nothing updates thairom maps or flashcard data automatically; accepted patterns must become map entries plus regression tests before release.

For the full catalog, generate a resumable OpenAI Batch API file (50% lower API cost than synchronous review):

thairom-review batch cards.json thairom-review-batch.jsonl

After downloading the completed batch output, flatten and classify it:

thairom-review import-batch thairom-review-batch.jsonl batch-output.jsonl reviews.jsonl
thairom-review summarize reviews.jsonl review-summary

License

MIT

Metadata

Release files for thairom 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for thairom 0.1.8
File Size Uploaded
thairom-0.1.8.tar.gz 49.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for thairom 0.1.8
File Interpreter ABI Platform
thairom-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 87.3 kB

Release files / thairom-0.1.8.tar.gz

Download URL thairom-0.1.8.tar.gz
Size 49.5 kB
Tags Source
SHA-256 checksum
How to use checksums
abd63563a3d5a8492e918ed5c1bddb4828096aa27da04a10cbf411f1df52982c
BLAKE2b-256 checksum
How to use checksums
fed8e5730ff622d209a1e1248cdd37d6e1c185bcec9ec13669e296555bc72766
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.6

Release files / thairom-0.1.8-py3-none-any.whl

Download URL thairom-0.1.8-py3-none-any.whl
Size 37.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97e14409ad9a9bdd32cd3015e217448588744ebb58361b24f739da0ccb3dfd95
BLAKE2b-256 checksum
How to use checksums
4f984472341fc621bea1163287e02f0709f5d14266e00178380cec0d60a26602
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page