CoolFace
Modelpublic

mrrtmob/kiri-ocr

sourceHugging Faceapache-2.0updated 7mo agoView on Hugging Face
11likes1.5kdownloads
Model Card

Kiri OCR Model

Kiri OCR is a lightweight OCR library for English and Khmer documents. It provides document-level text detection, recognition, and rendering capabilities in a compact package.

✨ Key Features

  • Lightweight: Compact model optimized for speed and efficiency
  • Bilingual: Native support for English and Khmer (including mixed text)
  • Document Processing: Automatic text line and word detection
  • Hybrid Decoding: CTC + Attention decoder with language model fusion

🏗️ Architecture

ComponentDetails
TypeTransformer Encoder-Decoder with CTC
Encoder4 layers, 8 heads, 256 dim, 1024 FFN
Decoder3 layers, 8 heads, 256 dim, 1024 FFN
CNN BackboneConvStem (4 conv layers with BatchNorm + SiLU)
DecodingBeam search with CTC fusion + LM fusion
Input Size48 × 640 px (height × width)
FrameworkPyTorch

Model Diagram

Input Image (48×640)
       ↓
   ConvStem (CNN)
       ↓
  2D Positional Encoding
       ↓
  Transformer Encoder (4L)
       ↓
   ┌───┴───┐
   ↓       ↓
CTC Head   Transformer Decoder (3L)
   ↓       ↓
   └───┬───┘
       ↓
  Beam Search + CTC Fusion + LM Fusion
       ↓
    Output Text

📊 Dataset

The model is trained on the mrrtmob/khmer_english_ocr_image_line dataset, containing 12 million synthetic images of Khmer and English text lines.

💻 Usage

Installation

bash
pip install kiri-ocr

Python API

python
from kiri_ocr import OCR

# Initialize (downloads from Hugging Face automatically)
ocr = OCR()

# Extract text from document
text, results = ocr.extract_text("document.jpg")
print(text)

# Access detailed results
for result in results:
    print(f"Text: {result.text}")
    print(f"Confidence: {result.confidence:.2%}")

CLI Tool

bash
# Basic usage
kiri-ocr predict path/to/document.jpg

# With output directory
kiri-ocr predict path/to/document.jpg --output results/

📈 Benchmarks

Results on synthetic test images (10 popular fonts):

[image]

[image]

⚙️ Configuration

Default inference parameters:

ParameterValueDescription
beam_width4Beam search width
ctc_fusion_alpha0.5CTC score fusion weight
lm_fusion_alpha0.35Language model fusion weight
max_length260Maximum output sequence length

📁 Model Files

kiri-ocr/
├── config.json          # Model configuration
├── vocab.json           # Character vocabulary
├── model.safetensors    # Model weights
└── README.md            # This file

🔗 Links

**Join our Discord Community**](https://discord.gg/Vcrw274RVC)

📄 License

This model is released under the Apache 2.0 License.