Nomeda OCR (tiny)
Tiny multilingual OCR with table structure extraction. Arabic-first (RTL), printed + handwritten, plus Latin, lines + tables, JSON / Markdown / CSV out. 7.28M parameters total (line/cell detector 2.45M + line reader 4.82M), runs on CPU.
Use
from huggingface_hub import snapshot_download
import sys; d = snapshot_download("nomeda-lab/nomeda-ocr-2"); sys.path.insert(0, d)
from nomeda_ocr.pipeline import TinyOCR
ocr = TinyOCR(d + "/detector", d + "/reader")
res = ocr.read("page.png") # dict: lines, tables, text
print(ocr.to_markdown(res)) # free text + tables as Markdown, in reading order
ocr.to_json(res, "page.json"); ocr.tables_csv(res, "tables/")
Needs: torch pillow numpy python-bidi huggingface_hub.
Output
{"page": {"width": 1200, "height": 900},
"lines": [{"id": 0, "text": "...", "box": [x0,y0,x1,y1], "conf": 0.97, "dir": "rtl", "table": null}],
"tables": [{"id": 0, "box": [..], "n_rows": 6, "n_cols": 4, "rtl": true,
"cells": [{"row": 0, "col": 0, "rowspan": 1, "colspan": 2, "bbox": [..], "text": "...", "conf": 0.95}],
"markdown": "| ... |"}],
"text": "free text outside tables, reading order"}
For right-to-left tables col 0 is the first logical column (right-most on the page); text is in logical order.
How it works
- CenterNet-style detector finds text lines and table cells (tiled multi-scale, any page size).
- CRNN+CTC reader reads each line (Arabic script incl. Persian/Urdu letters, Latin with accents, Arabic-Indic digits, currency symbols); bidi order is restored.
- Rule-based layout step turns cell boxes into rows / columns / spans, assigns lines to cells, and fixes RTL reading order.
Training data
Synthetic pages (30+ real fonts, tables, scans, pen-style handwriting) mixed with real data from the Hugging Face Hub:
aamijar/muharaf-public(licence: cc-by-nc-sa-4.0)johnlockejrr/KHATT_v1.0_dataset(licence: mit (original KHATT terms: research use))mohajesmaeili/Persian_Arabic_TextLine_Image_Ocr_Medium(licence: unspecified)docling-project/PubTables-1M_OTSL-v1.1(licence: other (PubTables-1M: CDLA-Permissive-2.0))
Limits (honest)
Handwriting: real data is Arabic (manuscripts + KHATT lines); Latin handwriting is synthetic only, so expect it to be weaker. Page-level handwriting line detection is trained mostly on synthetic notes.
Printed text only otherwise; no vertical text, no CJK/Cyrillic. Real tables in training are English scientific tables (PubTables-1M); Arabic table layouts come from synthetic data.
Tables are found from detected cell rectangles, so heavily skewed photos, curved pages and faint borderless tables are the weak spots. Evaluation numbers: see eval.json.
v2 vs v1 (PROMOTED: passed the gate)
Continued from nomeda-lab/nomeda-ocr; reader 9000 extra steps, detector 16000 extra steps, EMA weights.
Changes: robust table-grid builder, photo/sticker-style synthetic data, EMA, read-then-select photo inference (TinyOCR.read_photo). Details, ablations and limits: REVIEW.md.
| metric | baseline (v1) | candidate (v2) | delta | verdict |
|---|---|---|---|---|
| real hand CER | 0.2556 | 0.2287 | -0.0269 | better |
| real print CER | 0.0765 | 0.0721 | -0.0044 | better |
| synthetic Arabic CER | 0.0534 | 0.0527 | -0.0007 | better |
| synthetic Latin CER | 0.0268 | 0.0259 | -0.0009 | better |
| real table cell recall | 0.864 | 0.864 | +0.0 | same |
| real table grid shape ok | 0.005 | 0.01 | +0.005 | better |
| legacy line recall | 0.9744 | 0.9744 | +0.0 | same |
| legacy line CER | 0.1386 | 0.1365 | -0.0021 | better |
| legacy table struct exact | 0.0533 | 0.2568 | +0.2035 | better |
| legacy cell struct F1 | 0.3143 | 0.7528 | +0.4385 | better |
| photo-synth line recall | 0.961 | 0.9614 | +0.0004 | better |
| photo-synth line CER | 0.2467 | 0.2355 | -0.0112 | better |
Paired bootstrap, real CER (candidate - baseline): {"hand": {"diff": -0.026864193455205715, "lo": -0.033631351230266525, "hi": -0.02016139466273995}, "print": {"diff": -0.004391100702576117, "lo": -0.009593394094572, "hi": 0.00010474344135188131}}
Layout only (v1 weights, new grid builder) vs baseline:
| metric | baseline (v1) | candidate (v2) | delta | verdict |
|---|---|---|---|---|
| real hand CER | 0.2556 | 0.2556 | +0.0 | same |
| real print CER | 0.0765 | 0.0765 | +0.0 | same |
| synthetic Arabic CER | 0.0534 | 0.0534 | +0.0 | same |
| synthetic Latin CER | 0.0268 | 0.0268 | +0.0 | same |
| real table cell recall | 0.864 | 0.864 | +0.0 | same |
| real table grid shape ok | 0.005 | 0.01 | +0.005 | better |
| legacy line recall | 0.9744 | 0.9744 | +0.0 | same |
| legacy line CER | 0.1386 | 0.1386 | +0.0 | same |
| legacy table struct exact | 0.0533 | 0.2568 | +0.2035 | better |
| legacy cell struct F1 | 0.3143 | 0.7528 | +0.4385 | better |
| photo-synth line recall | 0.961 | 0.961 | +0.0 | same |
| photo-synth line CER | 0.2467 | 0.2467 | +0.0 | same |
The photo-synthetic rows are in-distribution for the candidate and are never used to promote. Real photos are measured only if PHOTO_DIR was given.