CoolFace
Modelpublic

Kansallisarkisto/finbert-ner

sourceHugging Facemitupdated 5mo agoView on Hugging Face
3likes3.3kdownloads
Model Card

Finnish named entity recognition

The model performs named entity recognition from text input in Finnish. It was trained by fine-tuning bert-base-finnish-cased-v1, using 10 named entity categories. Training data contains for instance the Turku OntoNotes Entities Corpus, the Finnish part of the NewsEye dataset as well as an annotated dataset consisting of Finnish document data from the 1970s onwards, digitized by the National Archives of Finland. Since the latter dataset contains also sensitive data, it has not been made publicly available.

An example of how the model can be used for named entity recognition is provided in this Colab notebook.

Motivations behind model development and the data selection and annotation processes have been described in more detail in the article Making sense of bureaucratic documents – Named entity recognition for state authority archives.

Intended uses & limitations

The model has been trained to recognize the following named entities from a text in Finnish:

  • PERSON (person names)
  • ORG (organizations)
  • LOC (locations)
  • GPE (geopolitical locations)
  • PRODUCT (products)
  • EVENT (events)
  • DATE (dates)
  • JON (Finnish journal numbers (diaarinumero))
  • FIBC (Finnish business identity codes (y-tunnus))
  • NORP (nationality, religious and political groups)

Some entities, like EVENT and LOC, are less common in the training data than the others, which means that recognition accuracy for these entities also tends to be lower.

Most of the training data is relatively recent, so that the model might face difficulties when the input contains for example old names or writing styles.

How to use

The easiest way to use the model is by utilizing the Transformers pipeline for token classification:

python
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline

model_checkpoint = "Kansallisarkisto/finbert-ner"
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = AutoModelForTokenClassification.from_pretrained(model_checkpoint)

token_classifier = pipeline(
  "token-classification",
  model=model,
  tokenizer=tokenizer,
  aggregation_strategy="simple",
)

predictions = token_classifier("Helsingistä tuli Suomen suuriruhtinaskunnan pääkaupunki vuonna 1812.")
print(predictions)

Running the code requires installing Transformers and PyTorch libraries.

Training data

Some of the entities (for instance WORKOFART, LAW, MONEY) that have been annotated in the Turku OntoNotes Entities Corpus dataset were filtered out from the dataset used for training the model. On the other hand, entities that were missing from the NewsEye dataset were added during the annotation process. The different data sources used in model training, validation and testing are listed below:

DatasetPeriod covered by the textsText typePercentage of the total data
Turku OntoNotes Entities Corpus2000sOnline texts23%
NewsEye dataset1850-1950OCR'd digitized newspaper articles3%
Diverse document data from Finnish public administration1970s - 2000sOCR'd digitized documents69%
Finnish senate documents1916Part manually transcribed, part HTR'd digitized documents3%
Finnish books from Project GutenbergEarly 20th centuryOCR'd texts1%
Theses from Finnish polytechnic universities2000sOCR'd texts1%

The number of entities belonging to the different entity classes contained in training, validation and test datasets are listed below:

Number of entity types in the data

DatasetPERSONORGLOCGPEPRODUCTEVENTDATEJONFIBCNORP
Train20211457221321193879571161623642246023842529
Val25255517130251212172403047306247283
Test24145577179244510971832838272374356

Training procedure

This model was trained using a NVIDIA RTX A6000 GPU with the following hyperparameters:

  • learning rate: 2e-05
  • train batch size: 24
  • epochs: 10
  • optimizer: AdamW with betas=(0.9,0.999) and epsilon=1e-08
  • scheduler: linear scheduler with numwarmupsteps=round(len(traindataloader)/5) and numtrainingsteps=len(traindataloader)*epochs
  • maximum length of data sequence: 512
  • patience: 2 epochs
  • classifier dropout: 0.3

In the preprocessing stage, the input texts were split into chunks with a maximum length of 300 tokens, in order to avoid the tokenized chunks exceeding the maximum length of 512. Tokenization was performed using the tokenizer for the bert-base-finnish-cased-v1 model.

The training code with instructions is available in GitHub.

Evaluation results

Evaluation results using the test dataset are listed below:

PrecisionRecallF1-score
PERSON0.900.910.90
ORG0.840.870.86
LOC0.840.860.85
GPE0.910.910.91
PRODUCT0.730.770.75
EVENT0.690.730.71
DATE0.900.920.91
JON0.830.950.89
FIBC0.950.990.97
NORP0.910.950.93

The metrics were calculated using the seqeval library.

Acknowledgements

The model was developed in an ERDF-funded project "Using Artificial Intelligence to Improve the Quality and Usability of Digital Records" (Dalai) in 2021-2023. The purpose of the project was to develop the automation of the digitisation of cultural heritage materials and the automated description of such materials through artificial intelligence. The main target group comprises memory organisations, archives, museums and libraries that digitise and provide digital materials to their customers, as well as companies that develop services related to digitisation and the processing of digital materials.

Project partners were the National Archives of Finland, Central Archives for Finnish Business Records (Elka), South-Eastern Finland University of Applied Sciences Ltd (Xamk) and Disec Ltd.

The selection and definition of the named entity categories, the formulation of the annotation guidelines and the annotation process have been carried out in cooperation with the FIN-CLARIAH research infrastructure / University of Jyväskylä.