Moroccan Arabic OCR — CNN + BiLSTM + CTC
This repository contains the trained line-recognition checkpoint from the companion project moroccan-darija-ocr.
📖 Documentation détaillée en français : ouvrir le Space du projet. Il réunit 15 chapitres, la recherche, les commandes, des exemples interactifs CNN/CTC, les résultats audités et le cours PDF de 32 pages.
The model was trained on Arabic printed text-line images from the Moroccan Official Gazette. It is an Arabic baseline for later Moroccan Darija adaptation; it was not trained on Darija and should not be presented as a Darija benchmark result.
Checkpoint
best.pt is a PyTorch checkpoint containing the model, vocabulary, optimizer state, scheduler state, AMP scaler state, and training configuration. The architecture is a grayscale CNN followed by a two-layer bidirectional LSTM and a CTC classifier. CTC blank index is 0; the vocabulary is in vocab.json.
Configuration: height 64, maximum input width 1600, hidden size 128, CNN channels 32, 92 character classes plus the CTC blank. The checkpoint has 1,940,797 parameters.
Reported evaluation
On the fixed 1,212-line official test split:
- CER: 1.49%
- WER: 6.94%
- exact line accuracy: 51.65%
These are printed Arabic Gazette results, using greedy CTC decoding without a language model. They do not measure Darija performance. The full metrics and independent verification are included as metrics.json and verification.json.




Test visualization
The executable test-gallery notebook is available at notebooks/03_test_images_transcriptions.ipynb. It displays test images with reference transcriptions, model predictions, and per-line CER. A generated gallery is available at test_artifacts/test_images_transcriptions_gallery.png.
Loading
import torch
checkpoint = torch.load("best.pt", map_location="cpu", weights_only=False)
print(checkpoint["characters"])
print(checkpoint["config"])
For inference and preprocessing, use the source code in the GitHub repository. The model expects already-cropped line images. A full page needs line detection and reading-order reconstruction before recognition.
Intended next step: Darija
AtlasOCR is audited in the GitHub repository. Its public rows expose page or paragraph images with text and metadata, but the inspected version does not expose reliable line boxes or line-level transcriptions. The adaptation tools therefore require vetted one-line image/transcription pairs and reject multiline text. AtlasOCRBench must remain a held-out evaluation set.
Synthetic Darija pipeline smoke test
A first reproducible subset of 5,000 DODa Arabic-script sentences was rendered with Arabic fonts and split into
4,500 training lines and 500 validation lines. After three RTX 5070 epochs, the synthetic validation reached 2.21%
CER, 9.92% WER, and 61.4% exact-line accuracy. This experiment is stored under
experiments/darija_synthetic_v2 and is a pipeline check only; it is not a
real-document Darija benchmark.
A filtered Atlas-text run is also available under
experiments/atlas_synthetic_filtered. It uses 5,329 rendered lines after
foreign-script filtering and reaches 6.63% CER, 15.01% WER, and 15.20% exact-line accuracy after three RTX 5070
epochs. It is still synthetic pre-training data, not real-document evaluation.
Local demo and experiment audit
The companion repository now provides a shared line/page recognizer and an optional local Gradio interface. The usage guide covers installation, loading this repository's checkpoints, single-column page OCR and JSON/TXT exports. CPU and RTX 5070 inference and both Gradio modes were checked with the mixed checkpoint; a three-line composed fixture is a functional smoke test only, not a real-document benchmark.
An audit of historical experiments identified changing validation memberships between augmentation runs, shared Atlas source paragraphs across mixed train/validation, and omitted vowel marks in historical synthetic rendering. Historical Darija metrics are exploratory. The corrected generator groups source pages, fixes validation rendering and preserves vowel marks. These corrections apply to newly generated corpora; no existing checkpoint was retrained in this update.
French theory and implementation course
A complete French course explains CNNs, BiLSTMs, CTC alignment, Arabic rendering, data isolation, GPU training, evaluation and page inference using this project's actual code. The 32-page PDF includes 12 worked exercises and 10 interview questions. Historical experiment limitations are explained alongside the results.
Data and attribution
The baseline data source is the Moroccan Official Gazette line-image corpus, Zenodo DOI 10.5281/zenodo.21702529, announced under CC BY 4.0. See the GitHub repository for the complete audit, preparation code, limitations, and attribution details.