Detect Person, Organization and Location in Turkish text

Description

This model is imported from Hugging Face-models. This model is the fine-tuned version of “xlm-roberta-base” (a multilingual version of RoBERTa) using a reviewed version of well known Turkish NER dataset (https://github.com/stefan-it/turkish-bert/files/4558187/nerdata.txt)

Predicted Entities

PER, LOC, ORG

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 = XlmRoBertaForTokenClassification.pretrained("xlm_roberta_base_token_classifier_ner", "tr"))\
.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 = """Benim adım Cesur Yurttaş ve İstanbul'da yaşıyorum."""
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 = XlmRoBertaForTokenClassification.pretrained("xlm_roberta_base_token_classifier_ner", "tr"))
.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["Benim adım Cesur Yurttaş ve İstanbul'da yaşıyorum."].toDS.toDF("text")

val result = pipeline.fit(example).transform(example)
import nlu
nlu.load("tr.ner.xlm_roberta").predict("""Benim adım Cesur Yurttaş ve İstanbul'da yaşıyorum.""")

Results

+-------------+---------+
|chunk        |ner_label|
+-------------+---------+
|Cesur Yurttaş|PER      |
|İstanbul'da  |LOC      |
+-------------+---------+

Model Information

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

Data Source

https://huggingface.co/akdeniz27/xlm-roberta-base-turkish-ner

Benchmarking

accuracy: 0.9919343118732742

f1: 0.9492100796448622

precision: 0.9407349896480332

recall: 0.9578392621870883