A DenseNet121-Transformer Architecture with Synthetic Paragraph Generation
This repository contains the source code, trained models, and vocabularies for end-to-end Kurdish handwritten paragraph recognition without explicit line segmentation, with cross-script evaluation on Arabic (KHATT) and cross-dataset transfer to an external Kurdish dataset (DASNUS).
Repository Structure
KHPR/
├── DASTNUS-Kurdish-ParagraphHTR/ # Best Kurdish paragraph model
│ ├── model.safetensors # Model weights
│ ├── config.json # Architecture configuration
│ ├── vocab.json # Character vocabulary (char → index)
│ ├── idx_to_char.json # Reverse vocabulary (index → char)
│ └── README.md # Model card
│
├── DASNUS-Kurdish-ParagraphHTR/ # Model fine-tuned on external Kurdish dataset
│ ├── model.safetensors
│ ├── config.json
│ ├── vocab.json
│ ├── idx_to_char.json
│ └── README.md
│
├── KHATT-Arabic-ParagraphHTR/ # Model fine-tuned on KHATT Arabic dataset
│ ├── model.safetensors
│ ├── config.json
│ ├── vocab.json # KHATT Arabic vocabulary (143 tokens)
│ ├── idx_to_char.json
│ └── README.md
│
├── Scripts/
│ ├── pretrain.py # Pre-training on synthetic paragraphs
│ ├── finetune.py # Fine-tuning on real handwritten paragraphs
│ ├── inference.py # Single image and batch inference
│ └── generate_paragraphs.py # Synthetic paragraph generation
│
├── Sample/
│ ├── sample_paragraph.tif # Example Kurdish handwritten paragraph
│ └── sample_paragraph.txt # Corresponding ground truth
│
├── requirements.txt
└── README.md
Architecture
Component
Details
CNN Backbone
DenseNet-121 (ImageNet pre-trained)
Encoder
3 Transformer encoder layers
Decoder
6 Transformer decoder layers
Attention Heads
8
Hidden Size
256
Feed-Forward Dim
2048
Positional Encoding
2D sinusoidal (encoder) + 1D sinusoidal (decoder)
Total Parameters
22.7M
The model processes full paragraph images end-to-end and outputs the complete multi-line text, including line break positions, without any explicit line segmentation.
Synthetic paragraphs were generated from DASTNUS line sources using the generate_paragraphs.py script, combining unique handwritten lines, Fixed handwrwritten lines and recipe-based synthetic handwritten lines with single-writer consistency, zero duplicate text orderings, and source-level isolation between splits.
KHATT Model
Data Source
Training
Validation
Testing
Reconstructed KHATT paragraphs
1,193
144
150
Synthetic paragraphs (pre-training)
10,201
1,199
—
Synthetic paragraphs for KHATT pre-training were generated by combining KHATT handwritten lines with Kurdish line sources from DASTNUS to provide richer visual diversity across handwriting styles within the same Arabic script family.
Hardware
Experiments were conducted on a workstation equipped with an Intel Core i9-14900K processor, 128 GB RAM, and an NVIDIA GeForce RTX 5090 GPU with 32 GB VRAM.
Citation
[]
License
This repository is released for non-commercial scientific research purposes only under the CC-BY-NC-4.0 license. The data used in this research is available upon request for non-commercial scientific research purposes only.