Medieval Latin Span-NER (Bi-Encoder Architecture)
A custom span-based NER model for Medieval Latin charters with 19 diplomatic entity types. Entities may be
nested or overlapping (e.g. a PER inside an ACTOR).
Which model is this? The weights on
mainare a later, stabilised variant, trained on 2026-03-16. It is a post-Table-4 variant of the model in Twenty's Plenty (NLP4DH 2026), not the model whose scores are reported in Table 4 of the paper. An earlier version of this card listed the paper's Table 4 scores (83.4 / 67.7) and ablation table for these weights; those numbers belong to a different run whose checkpoint was not preserved. For a documented, train-only retrain of the Table 4 configuration (as recorded in its training log, with the remaining settings from the training script saved immediately prior to that run) on the released split, use the branchtable4-clean-seed43.
Revisions in this repository
| Revision | What it is | Test scores (Zenodo v2 test split, 991 spans) | Matching |
|---|---|---|---|
main |
later stabilised variant of the paper's family (trained 2026-03-16 on a different split; 2 of the 91 test sentences were in its training data) | overlap 83.07 / exact 68.19 (t=0.50, T=1.35) | many-to-one (overlap_any) |
table4-clean-seed43 |
train-only retrain of the paper's Table 4 configuration on the released split; seed 43 chosen on dev | overlap 82.84 / exact 67.62 (t=0.40); 5 seeds at t=0.50: 82.0 ± 1.1 / 65.5 ± 2.1 | many-to-one (overlap_any) |
v13-nodapt-seed43 |
v13 architecture without LLRD/EMA; seed 43 chosen on dev; follow-up, not the paper's model | overlap 81.1 / exact 74.3 (5 seeds: 81.2 / 74.3; Macro 64.0 / 58.5) | one-to-one, dev threshold, same-label NMS IoU 0 |
v13-dapt-seed46 |
same as above on an XLM-R-large encoder adapted to MOM charter text (WWM MLM, perplexity 67.05 → 19.25); seed 46 chosen on dev | overlap 81.6 / exact 75.1 (5 seeds: 81.8 / 75.2; Macro 66.3 / 60.4); gain over v13-nodapt not significant |
one-to-one, dev threshold, same-label NMS IoU 0 |
The numbers of the first two rows and the last two rows are not comparable: many-to-one matching without NMS is more lenient than the one-to-one protocol with NMS on the strict metrics. Under the one-to-one protocol, GLiNER bi-large scores 75.8 / 69.2 and the Table 4 model family 80.3 / 70.2 (5 seeds). The corrected protocol, the erratum and the bootstrap results are in Zenodo v2 (https://doi.org/10.5281/zenodo.24681287). All splits are sentence-level (rows carry no charter id). Load a revision with revision="<name>" in hf_hub_download; the v13 revisions use span_ner_model_v13.py and their own README.
Architecture
- Text encoder:
FacebookAI/xlm-roberta-large. - Label encoder:
BAAI/bge-m3, frozen; encodes 19 English label descriptions. - Span representation:
max_width=80(all spans up to 80 tokens); 4-head attention pooling plus span-width embeddings. - Scoring: cosine similarity between span and label embeddings × learned scale; score = sigmoid(logit / T).
Training of these weights (stabilised variant)
Settings as recorded in the training log (the training script itself was not preserved):
| Setting | Value |
|---|---|
| Loss | "tamed" per-class Focal loss (max γ = 3.0) + Dice + hard-target InfoNCE |
| Hard negatives | 50 % of sampled negative spans |
| Prediction temperature during training/evaluation | T = 1.0 |
| Span width / attention heads / span hidden size | 80 / 4 / 512 |
| Optimisation | lr 1e-5 (encoder) / 2e-4 (heads), weight decay 0.05, batch 4 × grad-accum 8, max 30 epochs, patience 10 |
| Data | the 458-sentence dataset (Zenodo 10.5281/zenodo.19009430), split 298 / 69 / 91 sentences |
Note: span_ner_model.py sets PREDICT_TEMP = 1.35 (the value of the Table 4 configuration), while these
weights were trained and evaluated with T = 1.0. On the Zenodo v2 test split, switching between T = 1.0 and
T = 1.35 changes overlap and exact F1 by at most 0.2 points (t = 0.40–0.50).
Evaluation
| Test set | T | t | Overlap P / R / F1 | Exact P / R / F1 |
|---|---|---|---|---|
| Its own training-time test split (91 sentences, 1,036 spans) | 1.0 | 0.50 | 87.40 / 77.70 / 82.27 | 64.23 / 71.24 / 67.55 |
| Zenodo v2 test split (91 sentences, 991 spans)* | 1.35 | 0.50 | 87.94 / 78.71 / 83.07 | 64.73 / 72.05 / 68.19 |
* Caveat: these weights were trained on a different random split than the one released in Zenodo v2
(the paper's split). Its training set contains 2 of the 91 Zenodo v2 test sentences, so the second row
is slightly optimistic and not a clean held-out score. Use branch table4-clean-seed43 for clean numbers.
Metrics are token-level (regex \w+|[^\w\s]), with non-one-to-one matching, micro-averaged
(eval_snippet.py in the Zenodo record). Weakest labels: LEG (recall 23–25 %), PROP (0 %).
Metric note. The scores below use the paper's many-to-one matching (a gold span counts if any same-label prediction matches it). The corrected evaluation (one-to-one matching, dev-selected threshold, 5 seeds, same-label NMS, paired bootstrap) and the erratum are documented in Zenodo v2; one-to-one scores are lower and not directly comparable to the numbers below. The splits are sentence-level (rows carry no charter id).
Usage
Download span_ner_model.py together with the weights; the model cannot be loaded with pipeline().
import torch, importlib.util
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo = "ERCDiDip/medieval-latin-span-ner"
spec = importlib.util.spec_from_file_location("span_ner_model", hf_hub_download(repo, "span_ner_model.py"))
snm = importlib.util.module_from_spec(spec); spec.loader.exec_module(snm)
cfg = snm.Config()
model = snm.SpanNERModel(cfg)
model.load_state_dict(torch.load(hf_hub_download(repo, "pytorch_model.bin"), map_location="cpu"))
device = torch.device("cuda" if torch.cuda.is_available() else "cpu"); model.to(device)
ents = model.predict("Ego Heinricus comes de Hals dedi ecclesie Sancti Petri ...",
AutoTokenizer.from_pretrained(cfg.LABEL_MODEL), AutoTokenizer.from_pretrained(cfg.TEXT_MODEL),
threshold=0.5, flat_ner=False, device=device)
predict processes 512 words per window; for long charters, split the text into windows of ~150 words first
(the encoder truncates at 512 sub-words).
Labels
PER person name · ACTOR person phrase (name + title/origin) · TITLE rank or office · REL kinship ·
LOC place · INS institution · NAT natural feature · EST plot of land · PROP property description ·
LEG legal clause · TRANS transaction verb · TIM time period · DAT date · MON money · TAX tax or toll ·
COM commodity · NUM number · MEA measure · RELIC sacred object.
Related
- Distilled flat token-classification student (no nested spans):
ERCDiDip/medieval-latin-ner. - Dataset: Consolo, G., Kovács, T., Vogeler, G. (2026). Zenodo. https://doi.org/10.5281/zenodo.19009430
- Paper: Kovács, T., Consolo, G., Vogeler, G. (2026). Twenty's Plenty: Semantic Scaffolding and Span Architecture for 19-Label NER in Medieval Latin Charters. Proceedings of NLP4DH 2026, pp. 236–241.
Model tree for ERCDiDip/medieval-latin-span-ner
Base model
FacebookAI/xlm-roberta-large