TheoMoins commited on
Commit
36ae862
·
verified ·
1 Parent(s): 917f8da

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +310 -0
README.md ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ datasets:
4
+ - CATMuS/medieval
5
+ - magistermilitum/Tridis
6
+ metrics:
7
+ - cer
8
+ - wer
9
+ pipeline_tag: image-to-text
10
+ tags:
11
+ - htr
12
+ - handwritten-text-recognition
13
+ - manuscripts
14
+ - medieval
15
+ - vision-language-model
16
+ - catmus
17
+ - qwen
18
+ ---
19
+
20
+ # MEDUSA 0.2 — 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/).
24
+
25
+ This repository contains the `0.2` variants of MEDUSA, which extend the [0.1 release](https://huggingface.co/ENC-PSL/Medusa0.1Line-9B) with an explicit
26
+ **Silver pre-training stage** on synthetic line images rendered from text-only historical corpora.
27
+
28
+ > **Note on versioning.** The `0.1` variants correspond to the models submitted to the ICDAR 2026 competition, trained exclusively on Gold and Platinum image–text pairs.
29
+ > The `0.2` variants add a prior Silver stage using 500,000 synthetic lines, improving coverage of under-resourced languages.
30
+
31
+ ---
32
+
33
+ ## System report
34
+
35
+ For full details on data, training procedure, and results, see the [accompanying system report](https://enc.hal.science/hal-05600991).
36
+
37
+ ---
38
+
39
+ ## Languages and scripts
40
+
41
+ MEDUSA was trained on a corpus of over **640k lines + 500k generated lines** spanning more than twenty repositories, covering the following language families and scripts:
42
+
43
+ - **Romance / Latin**: Old French (`fro`), Occitan (`pro`), Old Italian (`ita`), Old Spanish (`osp`), Catalan (`cat`), Old Portuguese (`opor`), Navarrese (`nav`), Latin (`lat`), Venetian (`vec`), Galician (`glg`)
44
+ - **Germanic**: Middle High German (`gmh`), Middle Low German (`gml`), Old Icelandic (`ice`), Middle English (`enm`), Middle Dutch (`dum`), Old English (`ang`), Old Norwegian (`non`), Swedish (`swe`)
45
+ - **Celtic**: Welsh (`wlm`), Old Irish (`gle`)
46
+ - **Slavic**: Old Czech (`cze`), Old Polish (`pol`)
47
+
48
+ Manuscripts dated roughly from the 9th to the 15th century.
49
+
50
+ ---
51
+
52
+ ## Training data and curriculum
53
+
54
+ MEDUSA 0.2 is trained in three successive stages:
55
+
56
+ ### Stage 1 — Silver (synthetic)
57
+
58
+ The Silver stage uses **text-only historical corpora** to generate **500,000 synthetic line images**, providing lexical and script coverage for languages that are absent or scarce in the image–text tiers. Text is sampled from over 20 million words across medieval languages, rendered onto real manuscript background patches with stochastic ink, scan, and document degradation effects.
59
+
60
+ The synthetic lines are available as a separate dataset: [ENC-PSL/MEDUSA-synthetic-lines](https://huggingface.co/datasets/ENC-PSL/MEDUSA-synthetic-lines).
61
+
62
+ The underlying text-only corpora are listed below.
63
+
64
+ | Dataset | Language | Reference |
65
+ |---|---|---|
66
+ | Helsinki Corpus | Old English / Middle English | [[1]](#ref-helsinki) |
67
+ | Floris and Blancheflour | Old English | [[2]](#ref-floris) |
68
+ | Diakorp | Old Czech | [[3]](#ref-diakorp) |
69
+ | Hadewijch | Middle Dutch | [[4]](#ref-hadewijch) |
70
+ | CELT | Old Irish / Middle Irish | [[5]](#ref-celt) |
71
+ | Referenzkorpus Altdeutsch | Old High German | [[6]](#ref-altdeutsch) |
72
+ | Referenzkorpus Mittelhochdeutsch | Middle High German | [[7]](#ref-mhd) |
73
+ | Referenzkorpus Mittelniederdeutsch | Middle Low German | [[8]](#ref-mnd) |
74
+ | CTA | Old / Middle Portuguese | [[9]](#ref-cta) |
75
+ | CIPM | Old / Middle Portuguese | [[10]](#ref-cipm) |
76
+ | CODEA | Old Castilian | [[11]](#ref-codea) |
77
+ | OSTA | Old Castilian | [[12]](#ref-osta) |
78
+ | Biblia Medieval | Old Castilian | [[13]](#ref-biblia) |
79
+ | Milione | Venetian | [[14]](#ref-milione) |
80
+ | BFM | Old / Middle French | [[15]](#ref-bfm) |
81
+ | Chrétien de Troyes | Old / Middle French | [[16]](#ref-chretien) |
82
+ | Geste | Old / Middle French | [[17]](#ref-geste) |
83
+ | Otinel | Old / Middle French | [[18]](#ref-otinel) |
84
+ | Menota | Old Norse / Icelandic | [[19]](#ref-menota) |
85
+ | EAE | Old Norse / Icelandic | [[20]](#ref-eae) |
86
+ | Flores och Blanzeflor | Old Swedish | [[21]](#ref-flores) |
87
+ | Italian Paleography | Old Italian | [[22]](#ref-italpal) |
88
+ | CLTK Latin Library | Latin | [[23]](#ref-cltk) |
89
+ | Medieval Latin | Latin | [[24]](#ref-medlat) |
90
+ | Kochanowski | Old Polish | [[25]](#ref-kochanowski) |
91
+
92
+ ### Stage 2 — GoldMEDUSA was trained on a corpus of over 640,000 lines spanning more than twenty repositories, covering the following language families and scripts:
93
+
94
+ Romance / Latin: Old French (fro), Occitan (pro), Old Italian (ita), Old Spanish (osp), Catalan (cat), Old Portuguese (opor), Navarrese (nav), Latin (lat), Venetian (vec), Galician (glg)
95
+ Germanic: Middle High German (gmh), Middle Low German (gml), Old Icelandic (ice), Middle English (enm), Middle Dutch (dum), Old English (ang), Old Norwegian (non), Swedish (swe)
96
+ Celtic: Welsh (wlm), Old Irish (gle)
97
+ Slavic: Old Czech (cze), Old Polish (pol)
98
+
99
+ Mnuscripts dated roughly from the 9th to the 15th century.
100
+
101
+ Paired image–text data following heterogeneous transcription conventions, used for visual adaptation across manuscript styles and editorial traditions (~423,000 lines). See the [MEDUSA 0.1 model card](https://huggingface.co/ENC-PSL/Medusa0.1Line-9B) for the full dataset table.
102
+
103
+ ### Stage 3 — Platinum
104
+
105
+ Image–text pairs aligned with the [CATMuS](https://catmus-guidelines.github.io/) diplomatic transcription guidelines, used for final specialization toward the target task (~222,000 lines). See the [MEDUSA 0.1 model card](https://huggingface.co/ENC-PSL/Medusa0.1Line-9B) for the full dataset table.
106
+
107
+ ---
108
+
109
+ ### Silver-stage references
110
+
111
+ <a id="ref-helsinki"></a>[1] *Helsinki Corpus TEI XML Edition* (2011). Designed by Alpo Honkapohja et al. Based on The Helsinki Corpus of English Texts (1991).
112
+
113
+ <a id="ref-floris"></a>[2] Draschner, M., Edlich-Muth, M. *Raw text edition of the Middle English 'Floris and Blancheflour' in Edinburgh, National Library of Scotland, MS Advocates 19.2.1* (Jan 2026). https://doi.org/10.5281/zenodo.18244892
114
+
115
+ <a id="ref-diakorp"></a>[3] Kučera, K., Řehořková, A., Stluka, M. *Diakorp v6: Diachronic Corpus of Czech*. LINDAT/CLARIAH-CZ (2015). http://hdl.handle.net/11234/1-5413
116
+
117
+ <a id="ref-hadewijch"></a>[4] Haverals, W., Kestemont, M. *From exemplar to copy: the scribal appropriation of a Hadewijch manuscript computationally explored*. JDMDH 23. https://doi.org/10.46298/jdmdh.10206
118
+
119
+ <a id="ref-celt"></a>[5] Ó Corráin, D. et al. *CELT: Corpus of Electronic Texts* (1997). http://www.ucc.ie/celt
120
+
121
+ <a id="ref-altdeutsch"></a>[6] Donhauser, K. et al. *Referenzkorpus Altdeutsch (750–1050)* (2022), version 1.2. https://www.deutschdiachrondigital.de/rea/
122
+
123
+ <a id="ref-mhd"></a>[7] Roussel, A. et al. *Referenzkorpus Mittelhochdeutsch (1050–1350)* (2024), version 2.1. https://www.linguistics.ruhr-uni-bochum.de/rem/
124
+
125
+ <a id="ref-mnd"></a>[8] ReN-Team. *Reference Corpus Middle Low German/Low Rhenish (1200–1650)* (2021), version 1.1. https://doi.org/10.25592/uhhfdm.9195
126
+
127
+ <a id="ref-cta"></a>[9] Sobral, C., Cardeira, E. *Corpus de Textos Antigos (CTA)*. http://teitok.clul.ul.pt/teitok/cta/
128
+
129
+ <a id="ref-cipm"></a>[10] Xavier, M.F. *O CIPM — Corpus Informatizado do Português Medieval*. In: Kabatek, J. (ed.), De Gruyter (2016). https://doi.org/10.1515/9783110462357-007
130
+
131
+ <a id="ref-codea"></a>[11] GITHE. *CODEA+ 2022. Corpus de documentos españoles anteriores a 1900* (2022). https://doi.org/10.37536/CODEA.2015
132
+
133
+ <a id="ref-osta"></a>[12] *Old Spanish Textual Archive (OSTA)* (2026). https://github.com/hispanicseminary/OSTA
134
+
135
+ <a id="ref-biblia"></a>[13] Enrique-Arias, A., Pueyo Mena, F.J. *Biblia Medieval* (2008). https://bibliamedieval.es
136
+
137
+ <a id="ref-milione"></a>[14] Burgio, E. et al. *Dei Viaggi di Messer Marco Polo [...]: Edizione digitale* (2015). https://risorse-esterne.edizionicafoscari.it/
138
+
139
+ <a id="ref-bfm"></a>[15] Guillot, C., Heiden, S., Lavrentiev, A. *Base de français médiéval*. Diachroniques 7, 168–184 (2018). https://shs.hal.science/halshs-01809581
140
+
141
+ <a id="ref-chretien"></a>[16] Kunstmann, P., Martineau, F. *Chrétien de Troyes sur le web* (2000). https://doi.org/10.16995/dscn.176
142
+
143
+ <a id="ref-geste"></a>[17] Camps, J.-B. et al. *Geste: un corpus de chansons de geste, 2016–...* (Apr 2019). https://doi.org/10.5281/zenodo.2630574
144
+
145
+ <a id="ref-otinel"></a>[18] Camps, J.-B. *La Chanson d'Otinel: édition complète du corpus manuscrit* (Dec 2017). https://doi.org/10.5281/zenodo.1116736
146
+
147
+ <a id="ref-menota"></a>[19] *Medieval Nordic Text Archive (Menota)*. https://clarino.uib.no/menota/home. Founded 2001, part of CLARIN since 2016.
148
+
149
+ <a id="ref-eae"></a>[20] The Arnamagnæan Institute, Copenhagen. *Editiones Arnamagnæanæ Electronicæ (EAE)*. https://eae.ku.dk/
150
+
151
+ <a id="ref-flores"></a>[21] Worrall, E., Edlich-Muth, M. *Raw text edition of the Old Swedish "Flores och Blanzeflor"* (Sep 2025). https://doi.org/10.5281/zenodo.17093371
152
+
153
+ <a id="ref-italpal"></a>[22] Magni, I., Markey, L., Signorini, M. *Italian Paleography* (2019). https://italian.newberry.t-pen.org/
154
+
155
+ <a id="ref-cltk"></a>[23] *Classical Language Toolkit (CLTK): lat_text_latin_library*. https://github.com/cltk/lat_text_latin_library. Texts in the public domain.
156
+
157
+ <a id="ref-medlat"></a>[24] Corbara, S. et al. *Two datasets for the computational authorship analysis of medieval Latin texts* (Jun 2020). https://doi.org/10.5281/zenodo.4298503
158
+
159
+ <a id="ref-kochanowski"></a>[25] Kochanowski, J. *Works of Jan Kochanowski*. Wikiźródła (Polish Wikisource). https://pl.wikisource.org/wiki/Autor:Jan_Kochanowski
160
+
161
+ ---
162
+
163
+ ## Intended use
164
+
165
+ These models are designed for **line-level HTR** on pre-segmented medieval manuscript images.
166
+ 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.
167
+
168
+ The models target **CATMuS transcription guidelines**, which govern abbreviation expansion, allograph normalisation, and the character set used.
169
+
170
+ ---
171
+
172
+ ## Usage with DocWorkflow
173
+
174
+ The recommended way to use MEDUSA is via **[DocWorkflow](https://github.com/Enceintes-Chartes/docworkflow)**,
175
+ the document analysis framework developed at the École nationale des chartes.
176
+
177
+ ### Installation
178
+
179
+ ```bash
180
+ git clone https://github.com/TheoMoins/DocWorkflow
181
+ cd docworkflow
182
+ pip install -e .
183
+ ```
184
+
185
+ ### Configuration file
186
+
187
+ ```yaml
188
+ run_name: "Medusa0.2Line-9B"
189
+ output_dir: "results"
190
+ device: "cuda"
191
+ save_image: true
192
+
193
+ data:
194
+ test: "path/to/your/alto/data"
195
+
196
+ tasks:
197
+ htr:
198
+ type: VLMLineHTR
199
+ config:
200
+ use_metadata: true
201
+ model_name: 'outputs/Medusa0.2Line-9B'
202
+ device_map: "auto"
203
+ max_new_tokens: 128
204
+ line_batch_size: 8
205
+ max_pixels: 401408
206
+
207
+ prompt: >
208
+ Transcribe the handwritten text in this line image.
209
+ Keep abbreviations as written, do not expand them.
210
+ Modernize word segmentation (split or join words following modern usage).
211
+ Use only u and i, never v and j, regardless of the original or modern usage.
212
+ Do not record allographic variants, use standard letter forms.
213
+ Output ONLY the transcription.
214
+ ```
215
+
216
+ ### Running inference
217
+
218
+ ```bash
219
+ docworkflow -c Medusa0.1Line-9B.yml predict -t htr -d test
220
+ ```
221
+
222
+ ## Direct usage with `transformers`
223
+
224
+ The models can also be used directly outside of DocWorkflow, though the CATMuS post-processing step will need to be applied manually if desired.
225
+
226
+ ```python
227
+ from transformers import AutoProcessor, AutoModelForImageTextToText
228
+ from PIL import Image
229
+
230
+ model_id = "ENC-PSL/Medusa0.1Line-9B"
231
+
232
+ processor = AutoProcessor.from_pretrained(model_id)
233
+ model = AutoModelForImageTextToText.from_pretrained(model_id, device_map="auto")
234
+
235
+ image = Image.open("path/to/line_image.jpg").convert("RGB")
236
+
237
+ prompt = "Transcribe the handwritten text in this line image.\nOutput ONLY the transcription."
238
+
239
+ messages = [
240
+ {
241
+ "role": "user",
242
+ "content": [
243
+ {"type": "text", "text": prompt},
244
+ {"type": "image", "image": image},
245
+ ],
246
+ }
247
+ ]
248
+
249
+ inputs = processor.apply_chat_template(
250
+ [messages],
251
+ tokenize=True,
252
+ add_generation_prompt=True,
253
+ return_dict=True,
254
+ enable_thinking=False,
255
+ return_tensors="pt",
256
+ ).to(model.device)
257
+
258
+ with torch.no_grad():
259
+ generated_ids = model.generate(**inputs, max_new_tokens=128, do_sample=False)
260
+
261
+ trimmed = generated_ids[0][inputs["input_ids"].shape[1]:]
262
+ transcription = processor.decode(trimmed, skip_special_tokens=True).strip()
263
+ print(transcription)
264
+ ```
265
+
266
+ > **Important.** The model is optimised for the prompt given above. Results may degrade if the prompt is modified.
267
+ > The model outputs raw text; to enforce CATMuS compliance (character whitelist, allograph normalisation),
268
+ > apply the post-processing step provided in DocWorkflow (`src/tasks/htr/postprocessing.py`).
269
+
270
+ ---
271
+
272
+ ## CATMuS conventions
273
+
274
+ Transcriptions follow the [CATMuS guidelines](https://catmus-guidelines.github.io/).
275
+
276
+ ---
277
+
278
+ ## Citation
279
+
280
+ If you use MEDUSA in your research, please cite:
281
+
282
+ ```bibtex
283
+ @unpublished{moins:hal-05600991,
284
+ TITLE = {{MEDUSA 0.1: Medieval European Documents Unified System for Automated text recognition System Report for the ICDAR 2026 Competition on Multilingual Medieval Handwritten Text Recognition}},
285
+ AUTHOR = {Moins, Th{\'e}o and Cafiero, Florian and Camps, Jean-Baptiste and Conte, Lilla and Guidi, Emilie and Hensley, Brenna and Kapitan, Katarzyna and Macedo, Carolina and Peratello, Paola and Vermaas, Cecile and Vidal-Gor{\`e}ne, Chahan},
286
+ URL = {https://enc.hal.science/hal-05600991},
287
+ NOTE = {working paper or preprint},
288
+ YEAR = {2026},
289
+ MONTH = Apr,
290
+ PDF = {https://enc.hal.science/hal-05600991v1/file/MEDUSA__MEDieval_Universal_Script_Analysis-6.pdf},
291
+ HAL_ID = {hal-05600991},
292
+ HAL_VERSION = {v3},
293
+ }
294
+ ```
295
+
296
+ ---
297
+
298
+ ## Funding
299
+
300
+ 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
301
+ European Research Council. Neither the European Union nor the granting authority can be held responsible for them.
302
+
303
+ 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.
304
+
305
+ 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»).
306
+
307
+ 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.
308
+
309
+ This work was granted access to the HPC resources of IDRIS
310
+ under the allocation 2026-AD011015914R1 made by GENCI.