Downloads · 30 days
14
13% of all-time downloads
phenningsson/sdhk-ner-old-swedish-v2
sdhk-ner-old-swedish-v2 is a token classification model from phenningsson. Use it when you need labels on individual words, such as names. It is set up for transformers. The card lists the license as gpl-3.0.
This model performs Named Entity Recognition (NER) on Old Swedish charter digital editions from the Svenskt Diplomatariums Huvudkartotek (SDHK), the main catalogue of the Swedish Diplomatarium maintained by the Swedis…
Downloads · 30 days
14
13% of all-time downloads
All-time downloads
107
Public
Parameters
559M
2.3 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors2.2 GB · 99%
From the Hugging Face model README
This model performs Named Entity Recognition (NER) on Old Swedish charter digital editions from the Svenskt Diplomatariums Huvudkartotek (SDHK), the main catalogue of the Swedish Diplomatarium maintained by the Swedish National Archives (Riksarkivet). The model identifies Person and Location entities, with Organisations collapsed into the Location category.
This model is fine-tuned for NER through token classification on a manually verified corpus of Old Swedish charters from 1380-1382 produced by a three-signal entity projection pipeline. The base language model is an XLM-RoBERTa-Large model which was first domain-adapted to Old Swedish through continued Masked Language Modelling (MLM) on the full SDHK Old Swedish corpus, and then fine-tuned for token classification on the manually verified training dataset of Old Swedish charters from 1380-1382.
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("phenningsson/sdhk-ner-old-swedish-v2", add_prefix_space=True)
model = AutoModelForTokenClassification.from_pretrained("phenningsson/sdhk-ner-old-swedish-v2")
# Use aggregation_strategy="first" to properly combine subword tokens
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="first")
text = "Alla thøm thetta breff høra eller sea helsar husfru Jngeburg Thordsdotter af Liliostadhum æwerdhelika medh Gudhi ."
results = ner_pipeline(text)
for entity in results:
# entity['word'] can corrupt multi-byte UTF-8 chars; use start/end offsets instead
word = text[entity['start']:entity['end']]
print(f"{word}: {entity['entity_group']} ({entity['score']:.3f})")
Expected output:
Jngeburg Thordsdotter: Person (1.000)
Liliostadhum: Location (1.000)
| Signal | Source |
|---|---|
| Signal 1 — NER projection | KB-BERT (KBLab/bert-base-swedish-cased-ner) run on each charter's modern Swedish summary, then projected onto the Old Swedish edition via progressive string matching. |
| Signal 2 — Gazetteer lookup | Exact + fuzzy matching of Old Swedish tokens against TORA + Diplomatarium Fennicum (Locations) and Sveriges medeltida personnamn (Persons), with Latin and Old Swedish stoplists. |
| Signal 3 — Capitalisation heuristic | Capitalised tokens are investigated as potential entities using heuristics. |
A voting function combines the three signals into the final entity projection. The output is then manually verified by creator of this model, and an initial NER model is trained. The initial NER model is then applied to a set of unannotated charters from 1380-1382, and the model predictions are then manually corrected, and then used as training data. This process results in the data/1380_1382_dataset/. More information is available at the companion repository.
Training set statistics (80/10/10 split, seed = 42):
| Split | Files | Tokens | Person | Location | Total entities |
|---|---|---|---|---|---|
| Train | 333 | 92,068 | 4,008 | 3,707 | 7,715 |
| Val | 41 | 12,125 | 508 | 524 | 1,032 |
| Test (internal) | 43 | 11,830 | 550 | 542 | 1,092 |
Evaluation sets:
| Set | Files | Tokens | Person | Location | Total entities |
|---|---|---|---|---|---|
| Internal test test (held-out 43 charters) | 43 | 11,830 | 550 | 542 | 1,092 |
| Expert annotated test test (independently annotated) | 75 | 20,609 | 849 | 890 | 1,739 |
The expert test set was produced independently by expert annotators working on the original SDHK charter digital editions, with adjudication of the 10 charters shared between the annotators and used to calculate the inter-annotator agreement (IAA).
Reported metrics are entity-level (exact span + type) via seqeval, computed on the 75-charter expert test set:
| Metric | Score |
|---|---|
| F1 (micro) | 0.9764 |
| Precision (micro) | 0.9764 |
| Recall (micro) | 0.9764 |
Per-class results:
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| Person | 0.9789 | 0.9859 | 0.9824 | 849 |
| Location | 0.9740 | 0.9674 | 0.9707 | 890 |
Inter-annotator agreement (10 shared charters across domain expert annotators, computed via NLTK AnnotationTask):
| Metric | Score |
|---|---|
| Token-level Krippendorff's α (IO labels) | 0.9812 |
| Mean pairwise entity-level F1 (exact span + type) | 0.9672 |
The model uses BIO tagging with the following labels:
| Label | Description |
|---|---|
O | Outside any entity |
B-Person | Beginning of a person name |
I-Person | Inside/continuation of a person name |
B-Location | Beginning of a location name |
I-Location | Inside/continuation of a location name |
The backbone of this NER model is phenningsson/sdhk-mlm-pretrained-full, which in turn is a model based on XLM-RoBERTa-Large that has been domain adapted using the full SDHK Old Swedish corpus (all SDHK charters whose edition text is in Swedish). Domain adaptation was carried out prior to NER fine-tuning in order to familiarise the model with Old Swedish orthography, morphology, and charter vocabulary that is not represented in the multilingual XLM-RoBERTa pre-training data.
MLM hyperparameters:
xlm-roberta-largeNER is framed as a token classification task, with a classification head added on top of the domain-adapted XLM-RoBERTa-large model. To eliminate truncation of entity spans in long charter sentences, training uses O-boundary chunking: sequences that exceed the subword budget are split only at tokens labelled O, so every entity span remains intact and every token is seen during training.
NER hyperparameters:
Class imbalance handling:
O class and 5.0 for the entity classes, to compensate for the ~10:1 token-level imbalance in the training corpus.If you use this model, please cite:
@mastersthesis{Henningsson2086552,
author = {Henningsson, Pontus},
institution = {Linnaeus University, Department of Cultural Sciences},
pages = {84},
school = {Linnaeus University, Department of Cultural Sciences},
title = {Old Swedish Entities: Developing Named Entity Recognition for Medieval Charters Written in Old Swedish},
keywords = {named entity recognition, Old Swedish, natural language processing, medieval Scandinavian, digital humanities},
abstract = {The Old Swedish charters stored in the Swedish National Archives' Svenskt Diplomatariums huvudkartotek (SDHK) represent some of the most important source collections for studies of medieval Sweden, yet no dedicated open source Named Entity Recognition (NER) model exists for Old Swedish. This thesis evaluates whether such a model can be developed using SDHK charters through entity projection and NER training. An entity projection pipeline is created to automatically annotate entities in Old Swedish charters from 1380-1382. The automated annotations are subsequently manually verified, resulting in an entity-annotated corpus of 417 charters used to train the NER model. Both the pipeline and model are evaluated using F1 scores on a test set of 75 charters from 1375-1382 annotated by domain experts. Inter-annotator agreement is calculated using Krippendorff's alpha and pairwise F1 to evaluate the reliability of the expert annotations and thereby validate the test set. The pipeline and NER model achieve F1 scores of 0.6987 and 0.9764 respectively, and the inter-annotator agreement reaches a Krippendorff's alpha of 0.9812 and pairwise F1 of 0.967, which indicates very high annotator agreement. Beyond these results, the thesis discusses the nature of annotation and mediation of Old Swedish entities, where the developed resources of the thesis are best understood as the result of a chain of mediation and interpretation of the Old Swedish charter texts. This thesis contributes an openly available NER model, entity projection pipeline, and entity-annotated corpus for Old Swedish, while demonstrating how entity annotation and extraction are tinged with interpretative decisions that ultimately reflect what, and how, Old Swedish entities can be represented. },
year = {2026},
url = {https://urn.kb.se/resolve?urn=urn:nbn:se:lnu:diva-148739}
}
For more information about the code, data, and pipeline, see the companion GitHub repository. The thesis describing this work is available below.
Sincere gratitude is extended to the excellent resources and their contributors below, which has made it possible for this academic research and development of open source NER models for Old Swedish to be conducted. Special thanks is given to the expert annotators who graciously annotated Person and Location entities in the 75 charters that form the expert gold test set used for evaluation in this project.
This model is released under the GNU General Public License v3.0 (GPL-3.0).
For questions or issues, please open an issue on the GitHub repository or contact: [email protected]