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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- hr
|
| 4 |
+
- chu
|
| 5 |
+
tags:
|
| 6 |
+
- handwritten-text-recognition
|
| 7 |
+
- htr
|
| 8 |
+
- ocr
|
| 9 |
+
- historical-documents
|
| 10 |
+
- glagolitic
|
| 11 |
+
- croatian
|
| 12 |
+
- medieval
|
| 13 |
+
- crnn-ctc
|
| 14 |
+
- crnn
|
| 15 |
+
- ctc
|
| 16 |
+
license: apache-2.0
|
| 17 |
+
library_name: custom
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# Croatian Glagolitic HTR Model (Puigcerver CRNN)
|
| 21 |
+
|
| 22 |
+
A Handwritten Text Recognition (HTR) model for **14th–15th century Croatian Glagolitic manuscripts**,
|
| 23 |
+
based on the CNN + BiLSTM + CTC architecture introduced in
|
| 24 |
+
[Puigcerver (2017)](https://www.jpuigcerver.net/pubs/jpuigcerver_icdar2017.pdf) and used as
|
| 25 |
+
the backbone of [PyLaia](https://github.com/jpuigcerver/PyLaia) and Transkribus.
|
| 26 |
+
|
| 27 |
+
> **Important**: This model reads Glagolitic handwriting and outputs **Latin script transliteration**,
|
| 28 |
+
> not Glagolitic Unicode characters. It handles ligatures and resolves the most common abbreviations.
|
| 29 |
+
|
| 30 |
+
This is a **clean-room PyTorch reimplementation** of that published architecture (PyLaia-inspired).
|
| 31 |
+
It does *not* use the PyLaia Python package and is not loadable by it —
|
| 32 |
+
training and inference run via plain PyTorch (see Usage below).
|
| 33 |
+
|
| 34 |
+
## Model Details
|
| 35 |
+
|
| 36 |
+
- **Architecture**: CNN encoder [12, 24, 48, 48 filters] + 3-layer Bidirectional LSTM (256 units) + CTC decoder ([Puigcerver 2017](https://www.jpuigcerver.net/pubs/jpuigcerver_icdar2017.pdf))
|
| 37 |
+
- **Input**: Grayscale line images, normalized to 128 px height with aspect ratio preserved
|
| 38 |
+
- **Output**: Latin script transliteration of Croatian Glagolitic text
|
| 39 |
+
- **Vocabulary**: 76 symbols (`symbols.txt`)
|
| 40 |
+
- **Framework**: Pure PyTorch — clean-room reimplementation of the Puigcerver (2017) architecture (PyLaia-inspired); the PyLaia package is not required
|
| 41 |
+
|
| 42 |
+
## Performance
|
| 43 |
+
|
| 44 |
+
| Metric | Value |
|
| 45 |
+
|--------|-------|
|
| 46 |
+
| Validation CER | **5.33%** |
|
| 47 |
+
| Training epochs | 42 |
|
| 48 |
+
| Training lines | 23,203 |
|
| 49 |
+
| Validation lines | 1,361 |
|
| 50 |
+
|
| 51 |
+
## Training Data
|
| 52 |
+
|
| 53 |
+
Trained on Glagolitic handwriting images transcribed and exported from
|
| 54 |
+
[Transkribus](https://www.transkribus.org/) (see the corresponding
|
| 55 |
+
[Transkribus model page](https://app.transkribus.org/models/public/text/glagolitic-handwritten-14th-and-15th-century)).
|
| 56 |
+
The dataset covers 14th–15th century Croatian Glagolitic handwriting.
|
| 57 |
+
|
| 58 |
+
**Source manuscripts:**
|
| 59 |
+
- Cod. Vind. Slav. 3 (*Breviary of Vid of Omišalj*)
|
| 60 |
+
- *II. beramski brevijar*
|
| 61 |
+
|
| 62 |
+
Ground truth data was kindly provided by Sanja Zubčić (Rijeka) and Jagoda and Guido Kappel (Vienna).
|
| 63 |
+
Model trained and curated by Achim Rabus (Slavic Department, University of Freiburg).
|
| 64 |
+
The Transkribus collection comprises 531 training pages and 31 validation pages (~31,035 lines in total).
|
| 65 |
+
Our CRNN-CTC model was trained on 23,203 lines (training) and 1,361 lines (validation) from this export.
|
| 66 |
+
|
| 67 |
+
## Usage
|
| 68 |
+
|
| 69 |
+
### Requirements
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
pip install torch torchvision pillow
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### Inference
|
| 76 |
+
|
| 77 |
+
Download `best_model.pt`, `symbols.txt`, and `model_config.json` from this repository,
|
| 78 |
+
then use the inference script from [polyscriptor](https://github.com/achimrabus/polyscriptor):
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
from inference_pylaia_native import PyLaiaInference
|
| 82 |
+
from PIL import Image
|
| 83 |
+
|
| 84 |
+
# Load model
|
| 85 |
+
model = PyLaiaInference(
|
| 86 |
+
checkpoint_path="best_model.pt",
|
| 87 |
+
syms_path="symbols.txt"
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
# Transcribe a line image
|
| 91 |
+
image = Image.open("line_image.jpg")
|
| 92 |
+
text = model.transcribe(image)
|
| 93 |
+
print(text) # Output: Latin script transliteration
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
> **Note**: Input should be a single **text line image**, not a full page.
|
| 97 |
+
> Preprocessing (grayscale conversion, height normalization, aspect ratio preservation) is handled
|
| 98 |
+
> automatically by `inference_pylaia_native.py`.
|
| 99 |
+
|
| 100 |
+
For full-page inference with automatic line segmentation, use `batch_processing.py`:
|
| 101 |
+
|
| 102 |
+
```bash
|
| 103 |
+
python batch_processing.py \
|
| 104 |
+
--engine crnn-ctc \
|
| 105 |
+
--model-path best_model.pt \
|
| 106 |
+
--input-folder images/ \
|
| 107 |
+
--output-folder output/
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
### GUI Usage
|
| 111 |
+
|
| 112 |
+
[polyscriptor](https://github.com/achimrabus/polyscriptor) also ships graphical interfaces that handle
|
| 113 |
+
full-page processing without requiring pre-segmented line images:
|
| 114 |
+
|
| 115 |
+
**Interactive single-page GUI** — loads raw page images, performs automatic line segmentation,
|
| 116 |
+
and can export results as PAGE XML:
|
| 117 |
+
```bash
|
| 118 |
+
python transcription_gui_plugin.py
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
**Batch processing GUI** — processes entire folders; auto-detects existing PAGE XML files
|
| 122 |
+
(e.g. from Transkribus) and uses them for segmentation when available:
|
| 123 |
+
```bash
|
| 124 |
+
python polyscriptor_batch_gui.py
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
## Intended Use
|
| 128 |
+
|
| 129 |
+
- Transcription of 14th–15th century Croatian Glagolitic manuscripts
|
| 130 |
+
- Digital humanities research on medieval Croatian texts
|
| 131 |
+
|
| 132 |
+
## Limitations
|
| 133 |
+
|
| 134 |
+
- Trained on two manuscript sources (Cod. Vind. Slav. 3 and II. beramski brevijar); may underperform on other hands or periods
|
| 135 |
+
- Output is Latin script transliteration, not Glagolitic Unicode
|
| 136 |
+
- Full-page segmentation quality depends on the segmentation method used upstream
|
| 137 |
+
|
| 138 |
+
## Citation
|
| 139 |
+
|
| 140 |
+
If you use this model in your research, please cite the architecture paper, the publication describing
|
| 141 |
+
the training data and recognition system, and this model:
|
| 142 |
+
|
| 143 |
+
```bibtex
|
| 144 |
+
@article{rabus2022glagolitic,
|
| 145 |
+
title = {Handwritten Text Recognition for Croatian Glagolitic},
|
| 146 |
+
author = {Rabus, Achim},
|
| 147 |
+
journal = {Slovo: časopis Staroslavenskoga instituta u Zagrebu},
|
| 148 |
+
volume = {72},
|
| 149 |
+
pages = {181--192},
|
| 150 |
+
year = {2022},
|
| 151 |
+
doi = {10.31745/s.72.5},
|
| 152 |
+
url = {https://doi.org/10.31745/s.72.5}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
@article{puigcerver2017multidimensional,
|
| 156 |
+
title = {Are Multidimensional Recurrent Layers Really Necessary for Handwritten Text Recognition?},
|
| 157 |
+
author = {Puigcerver, Joan},
|
| 158 |
+
journal = {Proceedings of the 14th IAPR International Conference on Document Analysis and Recognition (ICDAR)},
|
| 159 |
+
year = {2017},
|
| 160 |
+
url = {https://www.jpuigcerver.net/pubs/jpuigcerver_icdar2017.pdf}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
@misc{rabus2026polyscriptor,
|
| 164 |
+
title = {Polyscriptor: Multi-Engine HTR Training \& Comparison Tool},
|
| 165 |
+
author = {Rabus, Achim},
|
| 166 |
+
year = {2026},
|
| 167 |
+
url = {https://github.com/achimrabus/polyscriptor}
|
| 168 |
+
}
|
| 169 |
+
```
|