TinyOCRkhmer: Khmer & LaTeX Math Text-Line Recognition (PARSeq)
TinyOCRkhmer is a specialized Vision Transformer (ViT) and Autoregressive Sequence model based on the PARSeq (Permutation Autoregressive Sequence) architecture. It is purpose-built to recognize single-line crops containing mixed Khmer Unicode text and complex LaTeX mathematical formulas from Cambodian national textbooks with state-of-the-art accuracy.
🚀 What's New in v4.0 (Clean Data Release, 50 Epochs, SOTA CER 17.20%)
- 🏆 State-Of-The-Art Accuracy: Character Error Rate (CER) dropped dramatically to 17.20% (an absolute reduction of -4.15% from 21.35%), setting a new benchmark for Khmer Math OCR!
- 📐 Upgraded High-Resolution Architecture:
- Image input resolution expanded to
64 x 256 pixels (512 patches) to cleanly separate delicate subscript consonants (ជើងអក្សរ), diacritics, and nested fraction radicals without blur or downsampling distortion.
- Model embedding dimension doubled to
d_model = 384 with 6 Attention Heads and 12 ViT layers (24.3M parameters).
- Sequence block size expanded to 193 tokens.
- 🔤 478-Token Khmer + LaTeX Hybrid Tokenizer:
- Full support for multi-character LaTeX bracket groups (
\left(, \right), \left\{, \right\}), environments (\pmatrix, \cases), functions (\dfrac, \lim, \int), and Greek symbols (\alpha, \beta, \theta).
- Native support for Chuon Nath orthography, Khmer Unicode numerals, and Unicode mathematical symbols (
∈, ∉, ⊂, ∪, ∩, ∫, √, ∞).
- 🧹 Crated Clean-Data Training: Trained on curated, noise-filtered MoEYS curriculum line crops with balanced distribution across Algebra, Calculus, Trigonometry, and Geometry.
- 💾 Latest Checkpoint: Added
best_khmer_parseq_model_clean_data_V4_cer17.20%.pt and updated default model.pt.
📊 Model Checkpoints Comparison
⚙️ Model Architecture & Specifications (v4.0)
⚡ Quickstart Python Usage
1. Installation
pip install torch torchvision timm pillow huggingface_hub
2. Run Inference on Any Khmer / Math Line Crop
from huggingface_hub import hf_hub_download
import importlib.util
# 1. Download model code and the latest SOTA weights
model_file = hf_hub_download("krotreaksmey/TinyOCRkhmer", "model.py")
weights_file = hf_hub_download(
"krotreaksmey/TinyOCRkhmer",
"best_khmer_parseq_model_clean_data_V4_cer17.20%.pt"
)
# 2. Dynamically import model definition
spec = importlib.util.spec_from_file_location("model", model_file)
model_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(model_module)
# 3. Load the model (Auto-detects architecture and tokenizer)
model = model_module.load_model(weights_file)
# 4. Transcribe a line image crop
predicted_text = model.predict_image("path/to/math_line_crop.png")
print("Recognized Text & LaTeX:")
print(predicted_text)
📁 Repository Contents
krotreaksmey/TinyOCRkhmer/
├── best_khmer_parseq_model_clean_data_V4_cer17.20%.pt # Current SOTA weights (CER: 17.20%, 24.3M params)
├── best_khmer_parseq_model_101K_cer21.35%.pt # v3.0 weights (101K dataset, CER: 21.35%)
├── best_khmer_parseq_model_60K_50epoch_cer_23.31%.pt # v2.0 weights (60K dataset, CER: 23.31%)
├── best_khmer_parseq_model _50epoch.pt # Intermediate 50 epoch weights
├── best_khmer_parseq_model_30epoch.pt # Baseline 30 epoch weights
├── model.pt # Standard PyTorch weights (points to v4 SOTA)
├── model.py # Universal PyTorch PARSeq & Tokenizer definition
├── inference.py # Ready-to-use CLI inference script
├── config.json # Model hyperparameters & architecture configuration
├── tokenizer.json # 478-token vocabulary mapping
└── README.md # Documentation & Model Card
🔗 Related Projects & Resources
📖 Citation
@misc{tinyocr_khmer_2026,
title={TinyOCRkhmer: Khmer & LaTeX Math Text-Line Recognition Model (PARSeq)},
author={krotreaksmey},
year={2026},
publisher={Hugging Face},
url={https://huggingface.co/krotreaksmey/TinyOCRkhmer}
}