NER Model for 6 Scandinavian Languages

Description

This model was imported from Hugging Face and it’s been fine-tuned for 6 Scandinavian languages (Danish, Norwegian-Bokmål, Norwegian-Nynorsk, Swedish, Icelandic, Faroese), leveraging Bert embeddings and BertForTokenClassification for NER purposes.

Predicted Entities

PER, ORG, LOC, MISC

Live Demo Open in Colab Download Copy S3 URI

How to use

documentAssembler = DocumentAssembler()\
.setInputCol("text")\
.setOutputCol("document")

sentenceDetector = SentenceDetectorDLModel.pretrained("sentence_detector_dl", "xx")\
.setInputCols(["document"])\
.setOutputCol("sentence")

tokenizer = Tokenizer()\
.setInputCols(["sentence"])\
.setOutputCol("token")

tokenClassifier = BertForTokenClassification.pretrained("bert_token_classifier_scandi_ner", "xx"))\
.setInputCols(["sentence",'token'])\
.setOutputCol("ner")

ner_converter = NerConverter()\
.setInputCols(["sentence", "token", "ner"])\
.setOutputCol("ner_chunk")

nlpPipeline = Pipeline(stages=[documentAssembler, sentenceDetector, tokenizer, tokenClassifier, ner_converter])

empty_data = spark.createDataFrame([[""]]).toDF("text")

model = nlpPipeline.fit(empty_data)
text = """Hans er professor ved Statens Universitet, som ligger i København, og han er en rigtig københavner."""
result = model.transform(spark.createDataFrame([[text]]).toDF("text"))
val documentAssembler = DocumentAssembler()
.setInputCol("text")
.setOutputCol("document")

val sentenceDetector = SentenceDetectorDLModel.pretrained("sentence_detector_dl", "xx")
.setInputCols(Array("document"))
.setOutputCol("sentence")

val tokenizer = Tokenizer()
.setInputCols(Array("sentence"))
.setOutputCol("token")

val tokenClassifier = BertForTokenClassification.pretrained("bert_token_classifier_scandi_ner", "xx"))
.setInputCols(Array("sentence","token"))
.setOutputCol("ner")

ner_converter = NerConverter()
.setInputCols(Array("sentence", "token", "ner"))
.setOutputCol("ner_chunk")

val pipeline = new Pipeline().setStages(Array(documentAssembler, sentenceDetector, tokenizer, tokenClassifier, ner_converter))

val example = Seq.empty["Hans er professor ved Statens Universitet, som ligger i København, og han er en rigtig københavner."].toDS.toDF("text")

val result = pipeline.fit(example).transform(example)
import nlu
nlu.load("xx.ner.scandinavian").predict("""Hans er professor ved Statens Universitet, som ligger i København, og han er en rigtig københavner.""")

Results

+-------------------+---------+
|chunk              |ner_label|
+-------------------+---------+
|Hans               |PER      |
|Statens Universitet|ORG      |
|København          |LOC      |
|københavner        |MISC     |
+-------------------+---------+

Model Information

Model Name: bert_token_classifier_scandi_ner
Compatibility: Spark NLP 3.3.2+
License: Open Source
Edition: Official
Input Labels: [sentence, token]
Output Labels: [ner]
Language: xx
Size: 666.9 MB
Case sensitive: true
Max sentense length: 256

Data Source

https://huggingface.co/saattrupdan/nbailab-base-ner-scandi

Benchmarking

languages :  F1 Score:
----------   --------
Danish       0.8744
Bokmål       0.9106
Nynorsk      0.9042
Swedish      0.8837
Icelandic    0.8861
Faroese      0.9022