File size: 2,286 Bytes
1a3cc45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---

language:
  - ar
license: cc-by-nc-4.0
tags:
  - handwritten-text-recognition
  - paragraph-recognition
  - ar
  - densenet
  - transformer
  - pytorch
  - safetensors
datasets:
  - KHATT
metrics:
  - cer
  - wer
pipeline_tag: image-to-text
---


# KHATT-Arabic: DenseNet121-Transformer Paragraph HTR

## Model Description
Arabic handwritten paragraph recognition model evaluated on the KHATT dataset for cross-script generalisation accessed through: https://www.kaggle.com/datasets/iraqyomar/khatt-arabic-hand-written-lines/code. Pre-trained on 12,000 synthetic paragraphs combining KHATT Arabic lines with Kurdish lines from DASTNUS, then fine-tuned on 1,193 reconstructed KHATT paragraphs. Achieves CER of 0.1394, surpassing a reimplemented state-of-the-art baseline under identical conditions.

## Architecture
- **CNN Backbone:** DenseNet-121 (pretrained on ImageNet)
- **Horizontal Upsample:** Yes
- **Encoder:** 3 Transformer encoder layers
- **Decoder:** 6 Transformer decoder layers
- **Attention Heads:** 8
- **Hidden Size:** 256
- **Feed-Forward Dim:** 2048
- **Vocabulary Size:** 143
- **Parameters:** 22,760,778

## Performance on KHATT
| Metric | Value |
|--------|-------|
| CER (greedy) | 0.1394 |
| WER (greedy) | 0.5075 |

## Input Format
- **Image size:** 600 x 1235 pixels
- **Preprocessing:** Aspect-ratio-preserving resize, right-aligned on white canvas (RTL)
- **Normalization:** ImageNet mean/std

## Training
- **Pre-training:** 12,000 synthetic paragraph images with curriculum learning
- **Fine-tuning:** Real handwritten paragraphs from KHATT
- **Two-stage strategy:** Encoder frozen for first 10 epochs during fine-tuning

## Usage
```python

from safetensors.torch import load_file

import json



# Load model weights

state_dict = load_file("model.safetensors")



# Load config

with open("config.json", "r") as f:

    config = json.load(f)



# Load vocabulary

with open("vocab.json", "r") as f:

    vocab = json.load(f)



# Load reverse mapping

with open("idx_to_char.json", "r") as f:

    idx_to_char = json.load(f)

```

## Citation
```

[Citation to be added upon publication]

```

## License
This model is released under CC-BY-NC-4.0 for non-commercial research purposes only.