AraELECTRA Arabic OCR error detector

Answers one question per word: is this word an OCR error?

Stage A of a two-model post-OCR correction pipeline, and also Stage D — the same model is reused to audit the corrector's repairs.

Why AraELECTRA specifically

ELECTRA is pretrained on replaced token detection: a corrupter swaps some tokens and the model learns to spot which ones were swapped. That is almost exactly this task, so the pretrained discriminator head is kept rather than replaced with a randomly initialised classifier. Two epochs were enough to reach F1 93.9.

Results

Held-out data. threshold is a logit, not a probability — 0.0 is p=0.5.

threshold precision recall false-alarm rate
0.0 93.8% 89.8% 6.2%
0.5 95.3% 87.7% 4.7%
1.0 96.6% 85.5% 3.4%

Validation F1 91.9 against 88.4 on books never seen in training. That 3.5-point gap is almost entirely precision, and it is the model's honest generalisation number.

Usage

Intended to be used through arabic-postocr:

from arabic_postocr import Detector

detector = Detector.from_pretrained("g3ida/araelectra-arabic-ocr-detector")
flags = detector.flags(["سنن این ماجه"], threshold=0.5)   # [[0, 1, 0]]

Directly:

from transformers import AutoModelForPreTraining, AutoTokenizer

tok = AutoTokenizer.from_pretrained("g3ida/araelectra-arabic-ocr-detector")
model = AutoModelForPreTraining.from_pretrained("g3ida/araelectra-arabic-ocr-detector")

Logits are per token. A word is flagged if any of its subword tokens fires, which requires mapping token offsets back to word spans — Detector.flags does this for you.

Input expectations

Feed it OCR text with shadda removed and everything else intact. It was trained on that view; fully stripping diacritics is a domain shift for no gain. Words past the 512-token truncation point cannot fire and default to "clean" — a miss rather than a false alarm, which is the safe direction.

Limitations

  • Finds corruption, not wrongness. A garbled word it catches; a real word in the wrong place it does not. Measured: it re-flags fluent-but-wrong text under 15% of the time.
  • Tuned for a pipeline, not standalone use. The threshold default of 0.5 sits above the model's own F1 peak because a downstream corrector pays for a false alarm twice and a miss only once.
  • Trained on scanned Arabic books (classical and modern). Other domains are untested.
Downloads last month
-
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for g3ida/araelectra-arabic-ocr-detector

Finetuned
(5)
this model