CoolFace
Modelpublic

crabz/slovakbert-ner

sourceHugging Facemitupdated 3y agoView on Hugging Face
2likes999downloads
Model Card

Named Entity Recognition based on SlovakBERT

This model is a fine-tuned version of gerulata/slovakbert on the Slovak wikiann dataset. It achieves the following results on the evaluation set:

  • —Loss: 0.1600
  • —Precision: 0.9327
  • —Recall: 0.9470
  • —F1: 0.9398
  • —Accuracy: 0.9785

Intended uses & limitations

Supported classes: LOCATION, PERSON, ORGANIZATION

from transformers import pipeline


ner_pipeline = pipeline(task='ner', model='crabz/slovakbert-ner')
input_sentence = "Minister financií a líder mandátovo najsilnejšieho hnutia OĽaNO Igor Matovič upozorňuje, že následky tretej vlny budú na Slovensku veľmi veľké."
classifications = ner_pipeline(input_sentence)

with displaCy:

import spacy
from spacy import displacy


ner_map = {0: '0', 1: 'B-OSOBA', 2: 'I-OSOBA', 3: 'B-ORGANIZÁCIA', 4: 'I-ORGANIZÁCIA', 5: 'B-LOKALITA', 6: 'I-LOKALITA'}

entities = []
for i in range(len(classifications)):
    if classifications[i]['entity'] != 0:
        if ner_map[classifications[i]['entity']][0] == 'B':
            j = i + 1
            while j < len(classifications) and ner_map[classifications[j]['entity']][0] == 'I':
                j += 1
            entities.append((ner_map[classifications[i]['entity']].split('-')[1], classifications[i]['start'],
                             classifications[j - 1]['end']))

nlp = spacy.blank("en")  # it should work with any language

doc = nlp(input_sentence)

ents = []
for ee in entities:
    ents.append(doc.char_span(ee[1], ee[2], ee[0]))

doc.ents = ents

options = {"ents": ["OSOBA", "ORGANIZÁCIA", "LOKALITA"],
           "colors": {"OSOBA": "lightblue", "ORGANIZÁCIA": "lightcoral", "LOKALITA": "lightgreen"}}
displacy_html = displacy.render(doc, style="ent", options=options)

<div class="entities" style="line-height: 2.5; direction: ltr">Minister financií a líder mandátovo najsilnejšieho hnutia <mark class="entity" style="background: lightcoral; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;"> OĽaNO <span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem">ORGANIZÁCIA</span> </mark>

<mark class="entity" style="background: lightblue; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;"> Igor Matovič <span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem">OSOBA</span> </mark> upozorňuje, že následky tretej vlny budú na <mark class="entity" style="background: lightgreen; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;"> Slovensku <span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem">LOKALITA</span> </mark> veľmi veľké.</div>

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • —learning_rate: 5e-05
  • —trainbatchsize: 32
  • —evalbatchsize: 8
  • —seed: 42
  • —optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • —lrschedulertype: linear
  • —num_epochs: 15.0

Training results

Training LossEpochStepValidation LossPrecisionRecallF1Accuracy
0.23421.06250.12330.88910.90760.89820.9667
0.11142.012500.10790.91180.92690.91930.9725
0.08173.018750.10930.91730.93150.92430.9747
0.04384.025000.10760.91880.93530.92700.9743
0.0285.031250.12300.91430.93870.92640.9744
0.02566.037500.12040.92460.94230.93340.9765
0.0187.043750.13320.92920.94160.93530.9770
0.01078.050000.13390.92800.94270.93530.9769
0.00799.056250.13680.93260.94420.93830.9785
0.006510.062500.14900.92840.94450.93640.9772
0.006111.068750.15660.93280.94330.93800.9778
0.003112.075000.15550.93390.94730.94060.9787
0.002413.081250.15480.93490.94620.94050.9787
0.001514.087500.15620.93300.94690.93990.9788
0.001315.093750.16000.93270.94700.93980.9785

Framework versions

  • —Transformers 4.13.0.dev0
  • —Pytorch 1.10.0+cu113
  • —Datasets 1.15.1
  • —Tokenizers 0.10.3