Bina 0.4 Rizeh
Bina 0.4 Rizeh is the small, fast member of the Bina 0.4 Persian OCR family. It reads whole pages (printed text, handwriting, forms, screenshots, letters, newspapers and simple math). Its core is about 71M parameters: a 38.5M line detector (fine-tuned Surya text detector) and a 32.8M CTC line recognizer distilled from Bina 0.4 Koochik. They run inside a page pipeline:
- Layout: Surya layout (
datalab-to/surya_layout2, pinned revision, downloaded on first run). - Lines: fine-tuned Surya-architecture line detectors (body text, printed layer, handwriting page path).
- Reading: the 95k-step Indra CTC student for body text, plus specialist readers with the same architecture: printed/form labels, short form cells, numeric and math, and degraded scans.
- Assembly: row consolidation, column and table ordering, printed-label admission and page-level ordering.
This repository bundles the production recognizers, specialist weights, calibration data and runtime code. The 2026-11-24 public-runner repair restores omitted crop/table helpers and exposes the input modes used by the historical pipeline. The reproducible original193 result below was measured with the repaired public image-only pipeline.
Quick run
hf download Reza2kn/Bina-0.4-Rizeh --local-dir Bina-0.4-Rizeh
cd Bina-0.4-Rizeh
pip install -r requirements.txt # Python 3.10, NVIDIA GPU recommended
python setup_table_runtime.py # isolated CPU table helper; pinned weights
python rizeh.py examples/demo.png --out results
python rizeh.py scan1.jpg scan2.png document.pdf --out results
The first run binds the bundled paths to your checkout (it edits the bundled text files in place, and reruns automatically if you move the folder) and downloads the pinned Surya layout model. For each page you get <name>.txt with the page text in reading order, and <name>.json with every line's text, box, layer (printed / handwriting / body) and confidence. PDFs are rendered at 200 dpi.
From Python:
from PIL import Image
from rizeh import Rizeh
ocr = Rizeh("cuda")
result = ocr(Image.open("page.jpg").convert("RGB"))
print(result["text"])
Reproduce the public 193-crop result (2026-11-24)
On Reza2kn/persian-ocr-bench-submitted10-bbox-crops revision 906b97fb1225d77003584e8f082da6f41d1a0618, the repaired public pipeline completed 193/193 with 87.55% mean normalized similarity, 21.27% corpus CER and 36.83% corpus WER. The earlier archived development predictions, rescored with the same original references/scorer, were 87.52%, 21.43% and 37.14% respectively. The unrepaired public page-only run scored 80.04% similarity. These numbers compare OCR pipelines; the recognizer and specialist weights are unchanged.
python benchmark_submitted10.py --device cuda --out submitted10-results
The script verifies every original PNG against benchmark_manifest.jsonl, runs all 193 inputs with crop mode, automatic pixel-derived table routing and automatic column ordering, then downloads reference text only after inference completes. It uses the original gold labels, original normalizer, and unclipped corpus CER/WER. It never reads benchmark categories, reference boxes, archived predictions, or filename hints for inference. validation/submitted10-public-repair.json and validation/submitted10-public-predictions.jsonl contain the receipt and predictions. This repeatedly used development benchmark is not an untouched held-out test set.
For cropped regions in your own documents:
python rizeh.py region.png --input-type crop --out results
--input-type auto is the new default; page preserves explicit whole-page handling. --content-type newspaper|table|text|math and --table-column-order ltr|rtl|auto are optional caller-supplied settings for known document types/conventions. The reported public score uses content-type auto and table-column-order auto uniformly, with no per-image metadata. Renaming an input does not change routing.
The restored dedicated table model uses Surya 0.17.0 / Transformers 4.57.1 on CPU, isolated from the main Surya 0.22.1 / Transformers 5 runtime. Its model files are downloaded from the publisher and SHA-256 checked before loading. Missing or broken helpers now raise a clear error; successful results include table-call and routing diagnostics. Helpers require Python 3.10-3.12; if your shell uses another version, run python setup_table_runtime.py --python python3.10. Runtime/model downloads happen during setup or first use; OCR itself runs locally. The table checkpoint retains its publisher's CC-BY-NC-SA-4.0 license; the layout model retains its publisher terms.
Historical internal-gate scores
The historical gate below used corrected-v3 references, convention transforms and clipped per-crop errors for the 193-crop view. Its 9.39% CER is not the original193 corpus CER and must not be mixed into the public comparison above. Other gates retain their original evaluation contracts. Lower CER is better.
| Gate | CER |
|---|---|
| 193 cropped regions, overall | 9.39 |
| · forms | 3.80 |
| · screenshots | 4.65 |
| · prose | 9.15 |
| · math | 12.09 |
| · newspaper | 13.49 |
| · tables | 19.63 |
| 50 handwriting pages, handwritten body only | 3.97 |
| 50 handwriting pages, full page incl. printed form text | 10.89 |
| 338 printed lines | 1.76 |
| 7 real scanned documents (printed regions) | 10.61 |
| Scanned official letter | 2.12 |
Persian OCR Triple Threat, same 95k recognizer, measured 2026-11-03 before the final assembly fixes (lower is better):
| Split | Rows | WER | CER | S³ | Triple Threat |
|---|---|---|---|---|---|
| Printed | 6,669 | 4.70 | 1.37 | 5.88 | 4.74 |
| Handwriting | 6,669 | 18.48 | 13.01 | 15.19 | 15.41 |
| Equal-split overall | 13,338 | 11.59 | 7.19 | 10.54 | 10.08 |
Limitations
- Historical manuscripts do not work. On HPHD (historical nastaliq and shekasteh manuscripts) the recognizer is at 67% CER even on oracle line crops, and full pages come out as fluent-looking nonsense. Do not use it for manuscripts.
- Tables are weak (about 20% CER), especially dense or low-resolution tables with handwriting over the cells.
- Reading order on busy layouts (multi-column newspapers, exam sheets with many labels) is the largest remaining error source; the characters are usually right but lines can come out in a different order.
- Faint or coloured printed labels (light-blue Nastaliq on forms) are often missed.
- The pipeline has many stages tuned together. Swapping one component (for example a newer recognizer) without retuning the stages after it makes results worse; this was measured, not assumed.
- Persian-first. Latin text and digits are read, but other languages were not a goal.
- Confidences are model scores, not calibrated probabilities.
Training and provenance
- Recognizer: Indra CTC, 32,796,250 parameters, 20 blocks, 1,617-symbol vocabulary; 95,000 training steps, distilled from Bina 0.4 Koochik checkpoint 18,404.
- Specialist readers (printed labels, form cells, numeric/math, degraded scans) are 32.8M fine-tunes of the same recognizer; the two line detectors are 38.5M fine-tunes of Surya's text detector, and the printed-text head adds 0.39M.
- Checkpoint selection used internal development sets only; the gates above were never used to pick weights.
model.safetensorsholds the two core networks (recognizer.*, 32.8M, andline_detector.*, 38.5M) in safetensors form for reuse and fine-tuning.rizeh.pyruns from the original files understallion/, which contain the same weights.MANIFEST.jsonlists every bundled file with its original location and size. Understallion/the files are organized by experiment directory exactly as they ran in production;rizeh.pyis the entry point.
License
Bina recognizer weights and code: CC BY-NC 4.0, matching the non-commercial training data. Line-detector weights are fine-tunes of Surya (datalab) detection weights, and the Surya layout model is downloaded from datalab; both stay under Surya's model license, which limits commercial use.
فارسی
بینا ۰٫۴ ریزه عضو کوچک و سریع خانواده OCR فارسی بینا ۰٫۴ است. یک مدل CTC با ۳۲٫۸ میلیون پارامتر که از بینا ۰٫۴ کوچیک تقطیر شده، درون یک خطلوله کامل صفحه کار میکند: چیدمان صفحه، تشخیص خط، خواندن متن چاپی و دستنویس، فرمها، اعداد و چیدن متن به ترتیب خواندن.
pip install -r requirements.txt
python setup_table_runtime.py
python rizeh.py page.jpg --out results
محدودیت مهم: روی نسخههای خطی تاریخی (نستعلیق و شکسته قدیمی) قابل استفاده نیست، و جدولها و ترتیب خواندن صفحههای شلوغ هنوز ضعیفاند.