TinyOCRkhmer: Khmer & LaTeX Math Text-Line Recognition

TinyOCRkhmer is an ultra-fast, state-of-the-art Vision Transformer (ViT) and Autoregressive Sequence model based on the (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 unmatched precision.
What's New in v4.0 (Clean Data Release, SOTA CER 11.11% & WER 24.94%)
- All-Time SOTA Accuracy: Verified on test set evaluation reaching Character Error Rate (CER) of 11.11% and Word Error Rate (WER) of 24.94%, establishing the official state-of-the-art benchmark for Cambodian Mathematics OCR!
- Upgraded High-Resolution Architecture:
- Image input resolution expanded to
64 x 256 pixels (512 patches).
- Model embedding dimension doubled to
d_model = 384 with 6 Attention Heads and 12 ViT blocks (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 (
∈, ∉, ⊂, ∪, ∩, ∫, √, ∞).
- Curated Clean-Data Training: Trained on curated, noise-filtered MoEYS curriculum line crops with balanced distribution across Algebra, Calculus, Trigonometry, and Geometry.
- Latest SOTA Checkpoint: Checkpoint
best_khmer_parseq_model_clean_data_V4.pt (also deployed directly as standard model.pt).
Model Checkpoints Comparison
| Checkpoint File | Training Data | Input Size | Params | CER | WER | Status |
|---|
best_khmer_parseq_model_clean_data_V4.pt (or model.pt) | 52,549 line Clean Data | 64 x 256 | 24.3M | 11.11% | 24.94% | Current All-Time SOTA (Recommended) |
best_khmer_parseq_model_101K_cer21.35%.pt | 101,463 lines | 48 x 192 | 6.1M | 21.35% | 37.67% | v3.0 Checkpoint |
best_khmer_parseq_model_60K_50epoch_cer_23.31%.pt | 66,259 lines | 48 x 192 | 6.1M | 23.31% | ~42.0% | v2.0 Checkpoint |
best_khmer_parseq_model _50epoch.pt | ~45,000 lines | 48 x 192 | 6.1M | ~26.0% | ~46.5% | Intermediate Checkpoint |
best_khmer_parseq_model_30epoch.pt | ~41,900 lines | 48 x 192 | 6.1M | ~34.8% | ~54.0% | Baseline v1.0 |
Model Architecture & Specifications (v4.0 SOTA)
| Parameter | Value |
|---|
| Model Type | PARSeq (Vision Transformer Encoder + Autoregressive Decoder) |
| Total Parameters | 24,335,326 (~24.3M Parameters) |
| Encoder Parameters | 21,570,048 (~21.57M, ViT-12 Blocks) |
| Decoder Parameters | 2,765,278 (~2.76M, Autoregressive Attention) |
| Image Resolution | 64 x 256 pixels (RGB, 512 patches) |
| Patch Size | 4 x 8 |
| Embedding Dimension | 384 |
| Attention Heads | 6 heads (Encoder) / 6 heads (Decoder) |
| Vocabulary Size | 478 unique tokens (Multi-char LaTeX + Khmer + Math) |
| Block Size (Sequence Length) | 193 tokens |
| Weights File Size | ~93 MB (.pt) |
| Character Error Rate (CER) | 11.11% |
| Word Error Rate (WER) | 24.94% |
| Training Epochs | 50 Epochs |
| Training Dataset | krotreaksmey/khmer-math-textbook |
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 definition 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.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 v4 architecture and 478 tokenizer)
model = model_module.load_model(weights_file, device="cpu")
# 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.pt # Current SOTA weights (CER: 11.11%, WER: 24.94%, ~93 MB)
├── 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 Clean Data 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
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}
}