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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
- vision-language-model
|
| 16 |
- catmus
|
| 17 |
- qwen
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# MEDUSA 0.1 — Medieval European Documents Unified System for Automated text recognition
|
| 21 |
+
|
| 22 |
+
MEDUSA is a family of Vision Language Models (VLMs) fine-tuned for **multilingual medieval handwritten text recognition (HTR)** at the **line level**.
|
| 23 |
+
These models were developed at the [École nationale des chartes – PSL](https://www.chartes.psl.eu/) and submitted
|
| 24 |
+
to the [ICDAR 2026 Competition on Multilingual Medieval Handwritten Text Recognition (CMMHWR)](https://cmmhwr26.inria.fr/).
|
| 25 |
+
|
| 26 |
+
This repository contains two model variants:
|
| 27 |
+
|
| 28 |
+
| Model | Base | Version | Notes |
|
| 29 |
+
|---|---|---|---|
|
| 30 |
+
| `MEDUSA-4B-0.1` | Qwen3.5-4B | 0.1 | Model used at competition submission |
|
| 31 |
+
| `MEDUSA-9B-0.1` | Qwen3.5-9B | 0.1 | Best model at competition submission |
|
| 32 |
+
| `MEDUSA-4B-0.2` | Qwen3.5-4B | 0.2 | Improved post-competition iteration |
|
| 33 |
+
| `MEDUSA-9B-0.2` | Qwen3.5-9B | 0.2 | Improved post-competition iteration |
|
| 34 |
+
|
| 35 |
+
> **Note on versioning.** The `0.1` variants correspond exactly to the models evaluated in the ICDAR 2026 competition.
|
| 36 |
+
> The `0.2` variants incorporate additional training iterations and yield slightly better results.
|
| 37 |
+
> We release both to ensure full reproducibility of competition results.
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
+
## System report
|
| 42 |
+
|
| 43 |
+
For full details on data, training procedure, and results, see the accompanying system report:
|
| 44 |
+
|
| 45 |
+
> Moins, T., Cafiero, F., Camps, J.-B., Conte, L., Guidi, E., Hensley, B., Kapitan, K., Macedo, C., Peratello, P., Vermaas, C., & Vidal-Gorène, C. (2026).
|
| 46 |
+
> *MEDUSA 0.1: Medieval European Documents Unified System for Automated text recognition —
|
| 47 |
+
> System Report for the ICDAR 2026 Competition on Multilingual Medieval Handwritten Text Recognition.* École nationale des chartes – PSL.
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## Languages and scripts
|
| 52 |
+
|
| 53 |
+
MEDUSA was trained on a corpus of over **640,000 lines** spanning more than twenty repositories, covering the following language families and scripts:
|
| 54 |
+
|
| 55 |
+
- **Romance / Latin**: Old French (`fro`), Old Occitan (`pro`), Provençal, Old Spanish, Catalan (`ca`), Italian (`it`), Navarrese-Aragonese, Latin (`la`), Venetian
|
| 56 |
+
- **Germanic**: Middle High German (`gmh`), Middle Dutch (`dum`), Old English (`ang`), Old Norse (`non`), Swedish
|
| 57 |
+
- **Celtic**: Welsh (`wlm`)
|
| 58 |
+
- **Slavic**: Old Czech (`cs`), Old Polish
|
| 59 |
+
|
| 60 |
+
Scripts covered include Caroline minuscule, Gothic textualis, Gothic cursive, and humanistic hands, across manuscripts dated roughly from the 9th to the 15th century.
|
| 61 |
+
|
| 62 |
+
---
|
| 63 |
+
|
| 64 |
+
## Results (ICDAR 2026 CMMHWR)
|
| 65 |
+
|
| 66 |
+
Unweighted average CER (%) and WER (%) on internal and official competition test sets. Lower is better.
|
| 67 |
+
|
| 68 |
+
| Model | Internal CER | Internal WER | Task 1 CER | Task 2 CER | Task 3 CER |
|
| 69 |
+
|---|---|---|---|---|---|
|
| 70 |
+
| kraken-CATMuS 1.6.0 *(baseline)* | 17.3 | 53.5 | 9.29 | 7.91 | 25.9 |
|
| 71 |
+
| **MEDUSA-4B 0.1** | **14.7** | **44.5** | 8.15 | 5.60 | 12.0 |
|
| 72 |
+
| **MEDUSA-9B 0.1** | **13.2** | **42.6** | 8.03 | **5.24** | **10.8** |
|
| 73 |
+
|
| 74 |
+
MEDUSA-9B improves over the kraken-CATMuS 1.6.0 baseline by **1.2% on Task 1**, **2.9% on Task 2**, and **15% on Task 3**. Both MEDUSA variants use a single, unified set of weights across all three competition tasks.
|
| 75 |
+
|
| 76 |
+
---
|
| 77 |
+
|
| 78 |
+
## Intended use
|
| 79 |
+
|
| 80 |
+
These models are designed for **line-level HTR** on pre-segmented medieval manuscript images.
|
| 81 |
+
They are **not** page-level OCR systems: they expect a cropped image of a single text line as input and return the transcription of that line.
|
| 82 |
+
|
| 83 |
+
The models target **CATMuS transcription guidelines**, which govern abbreviation expansion, allograph normalisation, and the character set used.
|
| 84 |
+
|
| 85 |
+
---
|
| 86 |
+
|
| 87 |
+
## Usage with DocWorkflow
|
| 88 |
+
|
| 89 |
+
The recommended way to use MEDUSA is via **[DocWorkflow](https://github.com/Enceintes-Chartes/docworkflow)**,
|
| 90 |
+
the document analysis framework developed at the École nationale des chartes.
|
| 91 |
+
DocWorkflow handles ALTO XML input/output, line image extraction, batching, CATMuS post-processing, and scoring in a unified pipeline.
|
| 92 |
+
|
| 93 |
+
### Installation
|
| 94 |
+
|
| 95 |
+
```bash
|
| 96 |
+
git clone https://github.com/TheoMoins/DocWorkflow
|
| 97 |
+
cd docworkflow
|
| 98 |
+
pip install -e .
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
### Configuration file
|
| 102 |
+
|
| 103 |
+
Create a YAML config file (e.g., `medusa_inference.yml`):
|
| 104 |
+
|
| 105 |
+
```yaml
|
| 106 |
+
run_name: "Medusa0.1Line-9B"
|
| 107 |
+
output_dir: "results"
|
| 108 |
+
device: "cuda"
|
| 109 |
+
save_image: true
|
| 110 |
+
|
| 111 |
+
data:
|
| 112 |
+
test: "path/to/your/alto/data" # directory with ALTO XML + image pairs
|
| 113 |
+
|
| 114 |
+
tasks:
|
| 115 |
+
htr:
|
| 116 |
+
type: VLMLineHTR
|
| 117 |
+
config:
|
| 118 |
+
use_metadata: true
|
| 119 |
+
model_name: 'outputs/Medusa0.1Line-9B'
|
| 120 |
+
device_map: "auto"
|
| 121 |
+
max_new_tokens: 128
|
| 122 |
+
line_batch_size: 8
|
| 123 |
+
max_pixels: 401408
|
| 124 |
+
|
| 125 |
+
prompt: >
|
| 126 |
+
Transcribe the handwritten text in this line image.
|
| 127 |
+
Keep abbreviations as written, do not expand them.
|
| 128 |
+
Modernize word segmentation (split or join words following modern usage).
|
| 129 |
+
Use only u and i, never v and j, regardless of the original or modern usage.
|
| 130 |
+
Do not record allographic variants, use standard letter forms.
|
| 131 |
+
Output ONLY the transcription.
|
| 132 |
+
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
> **Tip.** If your dataset follows dataset-specific transcription conventions, you can provide a `conventions.yml` file alongside your ALTO data.
|
| 136 |
+
> DocWorkflow will automatically inject the conventions into the prompt via a `{conventions}` placeholder.
|
| 137 |
+
|
| 138 |
+
### Running inference
|
| 139 |
+
|
| 140 |
+
```bash
|
| 141 |
+
docworkflow -c Medusa0.1Line-9B.yml predict -t htr -d test
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
## Direct usage with `transformers`
|
| 145 |
+
|
| 146 |
+
The models can also be used directly outside of DocWorkflow, though the CATMuS post-processing step will need to be applied manually if desired.
|
| 147 |
+
|
| 148 |
+
```python
|
| 149 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 150 |
+
from PIL import Image
|
| 151 |
+
|
| 152 |
+
model_id = "ENC-PSL/MEDUSA-9B-0.1"
|
| 153 |
+
|
| 154 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 155 |
+
model = AutoModelForImageTextToText.from_pretrained(model_id, device_map="auto")
|
| 156 |
+
|
| 157 |
+
image = Image.open("path/to/line_image.jpg").convert("RGB")
|
| 158 |
+
|
| 159 |
+
prompt = "Transcribe the handwritten text in this line image.\nOutput ONLY the transcription."
|
| 160 |
+
|
| 161 |
+
messages = [
|
| 162 |
+
{
|
| 163 |
+
"role": "user",
|
| 164 |
+
"content": [
|
| 165 |
+
{"type": "text", "text": prompt},
|
| 166 |
+
{"type": "image", "image": image},
|
| 167 |
+
],
|
| 168 |
+
}
|
| 169 |
+
]
|
| 170 |
+
|
| 171 |
+
inputs = processor.apply_chat_template(
|
| 172 |
+
[messages],
|
| 173 |
+
tokenize=True,
|
| 174 |
+
add_generation_prompt=True,
|
| 175 |
+
return_dict=True,
|
| 176 |
+
enable_thinking=False,
|
| 177 |
+
return_tensors="pt",
|
| 178 |
+
).to(model.device)
|
| 179 |
+
|
| 180 |
+
with torch.no_grad():
|
| 181 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128, do_sample=False)
|
| 182 |
+
|
| 183 |
+
trimmed = generated_ids[0][inputs["input_ids"].shape[1]:]
|
| 184 |
+
transcription = processor.decode(trimmed, skip_special_tokens=True).strip()
|
| 185 |
+
print(transcription)
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
> **Important.** The model is optimised for the prompt given above. Results may degrade if the prompt is modified.
|
| 189 |
+
> The model outputs raw text; to enforce CATMuS compliance (character whitelist, allograph normalisation),
|
| 190 |
+
> apply the post-processing step provided in DocWorkflow (`src/tasks/htr/postprocessing.py`).
|
| 191 |
+
|
| 192 |
+
---
|
| 193 |
+
|
| 194 |
+
## CATMuS conventions
|
| 195 |
+
|
| 196 |
+
Transcriptions follow the [CATMuS guidelines](https://catmus-guidelines.github.io/).
|
| 197 |
+
|
| 198 |
+
---
|
| 199 |
+
|
| 200 |
+
## Training details
|
| 201 |
+
|
| 202 |
+
| Parameter | Value |
|
| 203 |
+
|---|---|
|
| 204 |
+
| Base models | Qwen3.5-4B and Qwen3.5-9B |
|
| 205 |
+
| Fine-tuning method | LoRA (via Unsloth) |
|
| 206 |
+
| LoRA rank | 64 |
|
| 207 |
+
| Training data levels | Gold + Platinum (mixed), then Platinum only |
|
| 208 |
+
| Training epochs | 3 (mixed) + 1–3 (Platinum only) |
|
| 209 |
+
| Max sequence length | 512 |
|
| 210 |
+
| Max pixels per image | 401,408 |
|
| 211 |
+
| Batch size | 32 (effective) |
|
| 212 |
+
| Learning rate | 5 × 10⁻⁵ |
|
| 213 |
+
| Framework | DocWorkflow + Unsloth |
|
| 214 |
+
|
| 215 |
+
Total training data: ~643,000 lines across Gold, Platinum, and original data (see system report for full dataset list).
|
| 216 |
+
|
| 217 |
+
---
|
| 218 |
+
|
| 219 |
+
## Citation
|
| 220 |
+
|
| 221 |
+
If you use MEDUSA in your research, please cite:
|
| 222 |
+
|
| 223 |
+
```bibtex
|
| 224 |
+
@techreport{medusa2026,
|
| 225 |
+
author = {Moins, Théo and Cafiero, Florian and Camps, Jean-Baptiste and
|
| 226 |
+
Conte, Lilla and Guidi, Emilie and Hensley, Brenna and
|
| 227 |
+
Kapitan, Katarzyna and Macedo, Carolina and Peratello, Paola and
|
| 228 |
+
Vermaas, Cecile and Vidal-Gorène, Chahan},
|
| 229 |
+
title = {{MEDUSA 0.1}: Medieval European Documents Unified System for
|
| 230 |
+
Automated text recognition — System Report for the {ICDAR} 2026
|
| 231 |
+
Competition on Multilingual Medieval Handwritten Text Recognition},
|
| 232 |
+
institution = {École nationale des chartes -- {PSL}},
|
| 233 |
+
year = {2026},
|
| 234 |
+
}
|
| 235 |
+
```
|
| 236 |
+
|
| 237 |
+
---
|
| 238 |
+
|
| 239 |
+
## Funding
|
| 240 |
+
|
| 241 |
+
Funded by the European Union (ERC, LostMA, 101117408). Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the
|
| 242 |
+
European Research Council. Neither the European Union nor the granting authority can be held responsible for them.
|
| 243 |
+
|
| 244 |
+
This work has received support under the Major Research Program of PSL Research University ``CultureLab'' launched by PSL Research University and implemented by ANR with the references ANR-10-IDEX-0001.
|
| 245 |
+
|
| 246 |
+
Ce travail a bénéficié d'une aide de l’État gérée par l'Agence Nationale de la Recherche au titre de France 2030 portant la référence « ANR-23-IACL-0008»).
|
| 247 |
+
|
| 248 |
+
Biblissima+ bénéficie d’une aide de l'Etat gérée par l'ANR au titre du Programme d’investissements d’avenir intégré à France 2030, portant la référence ANR-21-ESRE-0005.
|
| 249 |
+
|
| 250 |
+
This work was granted access to the HPC resources of IDRIS
|
| 251 |
+
under the allocation 2026-AD011015914R1 made by GENCI.
|
| 252 |
+
|