CoolFace
Datasetpublic

medyas/arabic-ocr-printed-500k

Arabic Printed OCR Lines — Synthetic, 500k A general-purpose printed Arabic text-line recognition corpus: 500,000 train + 2,000 val line images with labels, built to fine-tune line-recognition models (PaddleOCR PP-OCR rec CTC/MultiHead, TrOCR, etc.). Real line-crop printed-Arabic data does not exist at this scale on the Hub, so this corpus is rendered synthetically with diverse fonts + real Arabic text and a documented label/decoding contract. Why this exists… See the full description on the dataset page: https://huggingface.co/datasets/medyas/arabic-ocr-printed-500k.

sourceHugging Facecc-by-sa-4.0updated 3mo agoView on Hugging Face
0likes43downloads
Dataset Card

Arabic Printed OCR Lines — Synthetic, 500k

A general-purpose printed Arabic text-line recognition corpus: 500,000 train + 2,000 val line images with labels, built to fine-tune line-recognition models (PaddleOCR PP-OCR rec CTC/MultiHead, TrOCR, etc.). Real line-crop printed-Arabic data does not exist at this scale on the Hub, so this corpus is rendered synthetically with diverse fonts + real Arabic text and a documented label/decoding contract.

Why this exists

Public "Arabic OCR" line datasets are scarce, narrow, or mislabeled: the largest "real" one is itself synthetic with a fixed height and no digits/punctuation/diacritics, and Persian-mixed sets are ~half Persian after naive filtering. This corpus targets a full Arabic charset (letters + Western digits + punctuation), 15 typeface families, and realistic scan degradations, so a model trained on it generalizes to real printed Arabic.

Contents (inside arabic_ocr_printed_v1.tar)

images/                 # 502,000 line JPEGs (train_*.jpg, val_*.jpg)
train_list.txt          # "images/<f>.jpg\t<visual_label>"  (500,000 lines)
val_list.txt            # same format                        (2,000 lines)
gt_logical.jsonl        # {"path","logical_gt","decode_mirror"} per image
manifest.json           # full generation config + counts
samples/                # a few rendered samples + a round-trip table

manifest.json is also provided unpacked at the repo root for quick inspection.

Label contract (read before training) — IMPORTANT

Arabic is RTL; CTC alignment is monotonic with image columns (left→right). So labels are stored in VISUAL order, and a logical sidecar is kept for scoring:

  • logical_gt — the natural typed string (base Unicode). Score against this.
  • visual_labelpython_bidi.get_display(logical_gt, base_dir="R") (base forms, visual order). This is what's in train_list.txt / val_list.txt and what the model learns to emit.
  • image — rendered in the same visual order as the label (libraqm/RAQM shapes & reorders from base logical text with direction="rtl"; HarfBuzz, so any font works, no presentation-form gate).

At inference, a decoder that restores logical order (e.g. PaddleOCR CTCLabelDecode with an Arabic dict, which applies pred_reverse) converts the model's visual output back to logical. Empirically (overfit order-test): visual-order labels give CER 0.011 vs 0.88 for logical-order labels (the logical arm comes out mirror-reversed — the CTC-monotonic signature).

Known decode limitation — decode_mirror

PaddleOCR's pred_reverse LTR class excludes Arabic-Indic (U+0660–0669) and Extended/Persian (U+06F0–06F9) digits and reverses LTR runs group-wise, so multi-digit numbers adjacent to Arabic can mirror at decode. This corpus uses Western digits (round-trip cleanly + match Maghreb/Tunisian print). Lines whose round-trip is affected are flagged decode_mirror: true in gt_logical.jsonl — report CER with and without those lines.

Generation

  • Text: ~85% Arabic Wikipedia (wikimedia/wikipedia, 20231101.ar, CC-BY-SA 4.0) + ~15% generated general numerics/dates/measures/percent/ranges. Lengths 4–25 chars.
  • Normalization: NFKC + strip-tashkeel + drop-tatweel; digit classes kept distinct. Bidi control/format chars (U+200E/200F/061C/202A–202E/2066–2069) stripped before layout (ZWNJ/ZWJ kept). OOV chars (vs the PP-OCRv5 Arabic dict, ~1050 chars) gated out.
  • Fonts (15, OFL): Amiri, Scheherazade New, Noto Naskh/Kufi Arabic, Lateef, Reem Kufi, Aref Ruqaa, Cairo, Tajawal, Almarai, El Messiri, Changa, IBM Plex Sans Arabic, Markazi Text, Harmattan — Naskh / Kufi / Ruqaa / modern-sans coverage. Random size 30–44, dark-gray ink, variable padding & line height.
  • Augmentation (≈50% of images, real-scan): Gaussian blur, Gaussian + salt-and-pepper noise, brightness drop, JPEG recompression (q35–70), ±3° rotation.
  • Render engine: libraqm/RAQM (HarfBuzz shaping from base text).

See manifest.json for exact counts (incl. wiki_oov_dropped, bidi_dropped).

Quick start

python
import tarfile
tarfile.open("arabic_ocr_printed_v1.tar").extractall("corpus")
# corpus/images/, corpus/train_list.txt (path<TAB>visual_label), corpus/gt_logical.jsonl

For PaddleOCR rec: point Train.dataset.data_dir=corpus, Train.dataset.label_file_list=[corpus/train_list.txt], use an Arabic char dict (dict filename containing "arabic" so decode applies pred_reverse).

Limitations & roadmap

  • Backgrounds are clean/near-white (real scans have paper texture/color) — a v2 augmentation gap.
  • No handwritten text (separate, harder track).
  • Eastern/Arabic-Indic digit support is decode-limited (see decode_mirror); Western digits recommended.

License & attribution

CC-BY-SA 4.0 (inherited from Arabic Wikipedia source text). Attribution: Arabic Wikipedia (wikimedia/wikipedia 20231101.ar), CC BY-SA 4.0. Fonts are SIL OFL (cover the font files, not rendered output). Generated numeric lines are unencumbered.