TheoMoins commited on
Commit
b7a781e
·
verified ·
1 Parent(s): 2cb89da

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +309 -0
README.md ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ > **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.
26
+ > The `0.2` variants add a prior Silver stage using 500,000 synthetic lines, improving coverage of under-resourced languages.
27
+
28
+ ---
29
+
30
+ ## System report
31
+
32
+ For full details on data, training procedure, and results, see the [accompanying system report](https://enc.hal.science/hal-05600991).
33
+
34
+ ---
35
+
36
+ ## Languages and scripts
37
+
38
+ 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:
39
+
40
+ - **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`)
41
+ - **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`)
42
+ - **Celtic**: Welsh (`wlm`), Old Irish (`gle`)
43
+ - **Slavic**: Old Czech (`cze`), Old Polish (`pol`)
44
+
45
+ Manuscripts dated roughly from the 9th to the 15th century.
46
+
47
+ ---
48
+
49
+ ## Training data and curriculum
50
+
51
+ MEDUSA 0.2 is trained in three successive stages:
52
+
53
+ ### Stage 1 — Silver (synthetic)
54
+
55
+ 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.
56
+
57
+ The synthetic lines are available as a separate dataset: [ENC-PSL/MEDUSA-synthetic-lines](https://huggingface.co/datasets/ENC-PSL/MEDUSA-synthetic-lines).
58
+
59
+ The underlying text-only corpora are listed below.
60
+
61
+ | Dataset | Language | Reference |
62
+ |---|---|---|
63
+ | Helsinki Corpus | Old English / Middle English | [[1]](#ref-helsinki) |
64
+ | Floris and Blancheflour | Old English | [[2]](#ref-floris) |
65
+ | Diakorp | Old Czech | [[3]](#ref-diakorp) |
66
+ | Hadewijch | Middle Dutch | [[4]](#ref-hadewijch) |
67
+ | CELT | Old Irish / Middle Irish | [[5]](#ref-celt) |
68
+ | Referenzkorpus Altdeutsch | Old High German | [[6]](#ref-altdeutsch) |
69
+ | Referenzkorpus Mittelhochdeutsch | Middle High German | [[7]](#ref-mhd) |
70
+ | Referenzkorpus Mittelniederdeutsch | Middle Low German | [[8]](#ref-mnd) |
71
+ | CTA | Old / Middle Portuguese | [[9]](#ref-cta) |
72
+ | CIPM | Old / Middle Portuguese | [[10]](#ref-cipm) |
73
+ | CODEA | Old Castilian | [[11]](#ref-codea) |
74
+ | OSTA | Old Castilian | [[12]](#ref-osta) |
75
+ | Biblia Medieval | Old Castilian | [[13]](#ref-biblia) |
76
+ | Milione | Venetian | [[14]](#ref-milione) |
77
+ | BFM | Old / Middle French | [[15]](#ref-bfm) |
78
+ | Chrétien de Troyes | Old / Middle French | [[16]](#ref-chretien) |
79
+ | Geste | Old / Middle French | [[17]](#ref-geste) |
80
+ | Otinel | Old / Middle French | [[18]](#ref-otinel) |
81
+ | Menota | Old Norse / Icelandic | [[19]](#ref-menota) |
82
+ | EAE | Old Norse / Icelandic | [[20]](#ref-eae) |
83
+ | Flores och Blanzeflor | Old Swedish | [[21]](#ref-flores) |
84
+ | Italian Paleography | Old Italian | [[22]](#ref-italpal) |
85
+ | CLTK Latin Library | Latin | [[23]](#ref-cltk) |
86
+ | Medieval Latin | Latin | [[24]](#ref-medlat) |
87
+ | Kochanowski | Old Polish | [[25]](#ref-kochanowski) |
88
+
89
+ ### Stage 2 — Gold
90
+
91
+ MEDUSA was trained on a corpus of over 640,000 lines spanning more than twenty repositories, covering the following language families and scripts:
92
+
93
+ 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)
94
+ 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)
95
+ Celtic: Welsh (wlm), Old Irish (gle)
96
+ Slavic: Old Czech (cze), Old Polish (pol)
97
+
98
+ Mnuscripts dated roughly from the 9th to the 15th century.
99
+
100
+ 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.
101
+
102
+ ### Stage 3 — Platinum
103
+
104
+ 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.
105
+
106
+ ---
107
+
108
+ ### Silver-stage references
109
+
110
+ <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).
111
+
112
+ <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
113
+
114
+ <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
115
+
116
+ <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
117
+
118
+ <a id="ref-celt"></a>[5] Ó Corráin, D. et al. *CELT: Corpus of Electronic Texts* (1997). http://www.ucc.ie/celt
119
+
120
+ <a id="ref-altdeutsch"></a>[6] Donhauser, K. et al. *Referenzkorpus Altdeutsch (750–1050)* (2022), version 1.2. https://www.deutschdiachrondigital.de/rea/
121
+
122
+ <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/
123
+
124
+ <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
125
+
126
+ <a id="ref-cta"></a>[9] Sobral, C., Cardeira, E. *Corpus de Textos Antigos (CTA)*. http://teitok.clul.ul.pt/teitok/cta/
127
+
128
+ <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
129
+
130
+ <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
131
+
132
+ <a id="ref-osta"></a>[12] *Old Spanish Textual Archive (OSTA)* (2026). https://github.com/hispanicseminary/OSTA
133
+
134
+ <a id="ref-biblia"></a>[13] Enrique-Arias, A., Pueyo Mena, F.J. *Biblia Medieval* (2008). https://bibliamedieval.es
135
+
136
+ <a id="ref-milione"></a>[14] Burgio, E. et al. *Dei Viaggi di Messer Marco Polo [...]: Edizione digitale* (2015). https://risorse-esterne.edizionicafoscari.it/
137
+
138
+ <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
139
+
140
+ <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
141
+
142
+ <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
143
+
144
+ <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
145
+
146
+ <a id="ref-menota"></a>[19] *Medieval Nordic Text Archive (Menota)*. https://clarino.uib.no/menota/home. Founded 2001, part of CLARIN since 2016.
147
+
148
+ <a id="ref-eae"></a>[20] The Arnamagnæan Institute, Copenhagen. *Editiones Arnamagnæanæ Electronicæ (EAE)*. https://eae.ku.dk/
149
+
150
+ <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
151
+
152
+ <a id="ref-italpal"></a>[22] Magni, I., Markey, L., Signorini, M. *Italian Paleography* (2019). https://italian.newberry.t-pen.org/
153
+
154
+ <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.
155
+
156
+ <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
157
+
158
+ <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
159
+
160
+ ---
161
+
162
+ ## Intended use
163
+
164
+ These models are designed for **line-level HTR** on pre-segmented medieval manuscript images.
165
+ 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.
166
+
167
+ The models target **CATMuS transcription guidelines**, which govern abbreviation expansion, allograph normalisation, and the character set used.
168
+
169
+ ---
170
+
171
+ ## Usage with DocWorkflow
172
+
173
+ The recommended way to use MEDUSA is via **[DocWorkflow](https://github.com/Enceintes-Chartes/docworkflow)**,
174
+ the document analysis framework developed at the École nationale des chartes.
175
+
176
+ ### Installation
177
+
178
+ ```bash
179
+ git clone https://github.com/TheoMoins/DocWorkflow
180
+ cd docworkflow
181
+ pip install -e .
182
+ ```
183
+
184
+ ### Configuration file
185
+
186
+ ```yaml
187
+ run_name: "Medusa0.2Line-9B"
188
+ output_dir: "results"
189
+ device: "cuda"
190
+ save_image: true
191
+
192
+ data:
193
+ test: "path/to/your/alto/data"
194
+
195
+ tasks:
196
+ htr:
197
+ type: VLMLineHTR
198
+ config:
199
+ use_metadata: true
200
+ model_name: 'outputs/Medusa0.2Line-9B'
201
+ device_map: "auto"
202
+ max_new_tokens: 128
203
+ line_batch_size: 8
204
+ max_pixels: 401408
205
+
206
+ prompt: >
207
+ Transcribe the handwritten text in this line image.
208
+ Keep abbreviations as written, do not expand them.
209
+ Modernize word segmentation (split or join words following modern usage).
210
+ Use only u and i, never v and j, regardless of the original or modern usage.
211
+ Do not record allographic variants, use standard letter forms.
212
+ Output ONLY the transcription.
213
+ ```
214
+
215
+ ### Running inference
216
+
217
+ ```bash
218
+ docworkflow -c Medusa0.1Line-9B.yml predict -t htr -d test
219
+ ```
220
+
221
+ ## Direct usage with `transformers`
222
+
223
+ The models can also be used directly outside of DocWorkflow, though the CATMuS post-processing step will need to be applied manually if desired.
224
+
225
+ ```python
226
+ from transformers import AutoProcessor, AutoModelForImageTextToText
227
+ from PIL import Image
228
+
229
+ model_id = "ENC-PSL/Medusa0.1Line-9B"
230
+
231
+ processor = AutoProcessor.from_pretrained(model_id)
232
+ model = AutoModelForImageTextToText.from_pretrained(model_id, device_map="auto")
233
+
234
+ image = Image.open("path/to/line_image.jpg").convert("RGB")
235
+
236
+ prompt = "Transcribe the handwritten text in this line image.\nOutput ONLY the transcription."
237
+
238
+ messages = [
239
+ {
240
+ "role": "user",
241
+ "content": [
242
+ {"type": "text", "text": prompt},
243
+ {"type": "image", "image": image},
244
+ ],
245
+ }
246
+ ]
247
+
248
+ inputs = processor.apply_chat_template(
249
+ [messages],
250
+ tokenize=True,
251
+ add_generation_prompt=True,
252
+ return_dict=True,
253
+ enable_thinking=False,
254
+ return_tensors="pt",
255
+ ).to(model.device)
256
+
257
+ with torch.no_grad():
258
+ generated_ids = model.generate(**inputs, max_new_tokens=128, do_sample=False)
259
+
260
+ trimmed = generated_ids[0][inputs["input_ids"].shape[1]:]
261
+ transcription = processor.decode(trimmed, skip_special_tokens=True).strip()
262
+ print(transcription)
263
+ ```
264
+
265
+ > **Important.** The model is optimised for the prompt given above. Results may degrade if the prompt is modified.
266
+ > The model outputs raw text; to enforce CATMuS compliance (character whitelist, allograph normalisation),
267
+ > apply the post-processing step provided in DocWorkflow (`src/tasks/htr/postprocessing.py`).
268
+
269
+ ---
270
+
271
+ ## CATMuS conventions
272
+
273
+ Transcriptions follow the [CATMuS guidelines](https://catmus-guidelines.github.io/).
274
+
275
+ ---
276
+
277
+ ## Citation
278
+
279
+ If you use MEDUSA in your research, please cite:
280
+
281
+ ```bibtex
282
+ @unpublished{moins:hal-05600991,
283
+ 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}},
284
+ 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},
285
+ URL = {https://enc.hal.science/hal-05600991},
286
+ NOTE = {working paper or preprint},
287
+ YEAR = {2026},
288
+ MONTH = Apr,
289
+ PDF = {https://enc.hal.science/hal-05600991v1/file/MEDUSA__MEDieval_Universal_Script_Analysis-6.pdf},
290
+ HAL_ID = {hal-05600991},
291
+ HAL_VERSION = {v3},
292
+ }
293
+ ```
294
+
295
+ ---
296
+
297
+ ## Funding
298
+
299
+ 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
300
+ European Research Council. Neither the European Union nor the granting authority can be held responsible for them.
301
+
302
+ 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.
303
+
304
+ 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»).
305
+
306
+ 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.
307
+
308
+ This work was granted access to the HPC resources of IDRIS
309
+ under the allocation 2026-AD011015914R1 made by GENCI.