Instructions to use mschonhardt/CanonBerta-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mschonhardt/CanonBerta-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="mschonhardt/CanonBerta-v1")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("mschonhardt/CanonBerta-v1") model = AutoModelForMaskedLM.from_pretrained("mschonhardt/CanonBerta-v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
CanonBerta-v1: a medieval Latin encoder weighted towards canon law, for editing and analysing legal collections
CanonBerta-v1 is XLM-RoBERTa large with continued pre-training (masked language modelling) on about 236 million tokens of medieval Latin in which the canon-law material was upsampled. The model is intended as a domain-adapted encoder backbone for the editing and analysis of canon-law collections. Typical tasks are the restoration of boundaries in unpunctuated transcriptions, the reconstruction of text flow and initials, the tagging of citations and named entities, and retrieval. The companion model MediBerta was trained on the same documents without upsampling. The two models were built to test whether weighting the pre-training towards canon law improves downstream performance. In the experiments reported below, this is not the case.
The model was developed as part of the LOEWE project "Embedding the Past" (LOEWE-Exploration, TU Darmstadt, AdWL|Mainz), funded by HMWK Hessen, PI Prof. Dr. Michael Schonhardt. It was first presented at the International Medieval Congress, Leeds, on 8 July 2026 ("CanonBERT(a): Large Language Models for Editing and Analysing Medieval Canon Law Collections").
Training data
The sources are the same as for MediBerta. The text was lower-cased and stripped of punctuation, the form in which transcriptions of manuscripts and early prints are usually available.
| corpus | licence | link |
|---|---|---|
| Latin Text Archive (LTA) | CC BY 4.0 (CC BY-SA 4.0 for texts sourced from Corpus Corporum) | https://lta.bbaw.de |
| Corpus Corporum | CC BY-NC-SA 4.0 | https://mlat.uzh.ch |
| School of Salamanca | CC BY 4.0 | https://salamanca.school |
| Corpus Synodalium | CC BY 4.0 | https://corpus-synodalium.com |
| Decretum Burchardi (1548 print) | public domain | |
| Decretum Gratiani (ed. Friedberg 1879) | public domain | https://digitale-sammlungen.de (MDZ) |
| Bibliotheca Augustana (subcorpus) | public domain | https://www.hs-augsburg.de/~harsch/augustana.html |
The model weights are released under the Apache License 2.0. The source texts retain their own
licences and are not distributed with the model. For this reason the prepared training set on the Hub
(mschonhardt/CanonBerta) remains private.
For this run the 14,730 documents of the MediBerta set were assigned to five categories on the basis of corpus metadata. The legal and ecclesiastical categories were repeated in the training stream of 512-token sequences, and duplicates were not collapsed.
| category | distinct sequences | documents | factor | sequences in the stream | tokens |
|---|---|---|---|---|---|
| core canon law (Decretum Gratiani, Decretum Burchardi, canon-law collections) | 21,070 | 1,784 | x4 | 84,296 | 43.2 M |
| papal and ecclesiastical administration | 13,062 | 2,625 | x3 | 39,192 | 20.1 M |
| legal charters | 49,134 | 6,795 | x2 | 98,294 | 50.3 M |
| School of Salamanca | 53,240 | 47 | x2 | 106,480 | 54.5 M |
| general medieval Latin | 155,060 | 3,479 | x1 | 155,105 | 79.4 M |
| total | 291,566 | 14,730 | 483,367 | 247.5 M |
After one per cent of the documents had been held out, 476,522 sequences (236.0 million tokens) remained for training, 1.67 times the size of the baseline.
Training
Continued pre-training of FacebookAI/xlm-roberta-large with masked language modelling, using the same
script (train.py in this repository) and the same settings as MediBerta. Only the training set differs.
| setting | value |
|---|---|
| objective | MLM, masking probability 0.15 |
| sequence length | 512 tokens, paragraphs packed in document order into sequences that never cross a document boundary |
| tokenizer | XLM-R SentencePiece tokenizer, unchanged |
| held-out split | 1 % of the documents, stratified by category, held out as whole documents (3,933 validation sequences, 2.0 million tokens) |
| training set | 476,522 sequences, 236.0 million tokens |
| epochs | 10 (7,450 optimizer steps, 2.44 billion tokens seen) |
| batch | 40 sequences per device step (determined automatically), gradient accumulation 16, i.e. 640 sequences per update |
| optimizer | AdamW (fused), learning rate 1e-4, weight decay 0.01, betas 0.9/0.98, epsilon 1e-6, gradient clipping 1.0 |
| schedule | linear decay with 6 % warm-up |
| precision | bf16, SDPA attention |
| model selection | best validation loss (1.0779), evaluated every 500 steps |
| hardware and time | one NVIDIA RTX PRO 6000 Blackwell Server Edition (96 GB), 15.9 hours (57,226 s), 19 to 20 June 2026 |
The training script (train.py) and the logs are included in this repository: train.log,
training_log.jsonl, trainer_state.json, run_metadata.json (full configuration),
dataset_stats.json and tokenizer_diagnostics.json.
Evaluation
Intrinsic evaluation on the held-out documents after epoch 10 yields a validation loss of 1.080, a perplexity of 2.94 and a masked-token accuracy of 0.763 (MediBerta: 1.048, 2.85 and 0.770). The upsampled corpus is the more difficult target.
The downstream evaluation concerns segmentation. Each encoder was fine-tuned with the same segmentation head (SegmentBerta), which restores sentence and paragraph boundaries in unpunctuated, lower-cased medieval Latin. Evaluation used sliding windows on a held-out set.
| encoder | F1 | precision | recall |
|---|---|---|---|
| MediBerta | 0.665 | 0.717 | 0.619 |
| CanonBerta-v1 | 0.663 | 0.697 | 0.631 |
| XLM-R large (no domain adaptation) | 0.648 | 0.707 | 0.598 |
| LaBerta (external) | 0.604 | 0.669 | 0.551 |
The upsampling of canon law did not improve segmentation over the baseline. Both domain-adapted models outperform XLM-R large without adaptation and the external
- smaller - LaBerta model. The difference between the two adapted models, however, lies within the range of noise, with CanonBerta-v1 achieving slightly higher recall at the cost of precision. The comparison suggests that for editorial tasks the decisive factor is adaptation to editorial conventions, which the training editions carry, rather than adaptation to the subject matter of the sources.
Use
from transformers import AutoTokenizer, AutoModelForMaskedLM
tok = AutoTokenizer.from_pretrained("mschonhardt/CanonBerta-v1")
model = AutoModelForMaskedLM.from_pretrained("mschonhardt/CanonBerta-v1")
Input should be lower-cased medieval Latin without punctuation, in line with the pre-training data. The
tokenizer is the unchanged XLM-R SentencePiece model. For token or sequence classification, the model is
loaded with the corresponding AutoModelFor… head and fine-tuned.
Limitations
The model was trained on editions and a small number of prints, not on diplomatic transcriptions. Abbreviations, scribal spellings and OCR noise are therefore underrepresented. Since the pre-training text was lower-cased and unpunctuated, the model has not encountered capitals or punctuation in this domain. The training data are weighted towards canon law.
Environmental impact
The figure is an estimate. 15.9 GPU hours on a 600 W card at an assumed average draw of 400 W, multiplied by a factor of 1.4 for server and cooling, amount to about 8.9 kWh. At the German grid average of about 0.38 kg CO2e per kWh, this corresponds to roughly 4.9 kg CO2e.
Citation
Schonhardt, Michael: CanonBerta-v1: a medieval Latin encoder weighted towards canon law, for editing and analysing legal collections. Embedding the Past (LOEWE-Exploration, TU Darmstadt, AdWL|Mainz), 2026. https://huggingface.co/mschonhardt/CanonBerta-v1
@misc{schonhardt2026canonberta,
author = {Schonhardt, Michael},
title = {CanonBerta-v1: a medieval Latin encoder weighted towards canon law, for editing and analysing legal collections},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/mschonhardt/CanonBerta-v1}},
note = {Developed in the project Embedding the Past (LOEWE-Exploration, TU Darmstadt, AdWL|Mainz), funded by HMWK Hessen}
}
Related: MediBerta (baseline companion model), etp-latin-legal-references-ner, FacebookAI/xlm-roberta-large.
- Downloads last month
- 21
Model tree for mschonhardt/CanonBerta-v1
Base model
FacebookAI/xlm-roberta-large