Persian Named Entity Recognition (from HooshvareLab)

Description

Pretrained Named Entity Recognition model, uploaded to Hugging Face, adapted and imported into Spark NLP. roberta-fa-zwnj-base-ner is a Persian model orginally trained by HooshvareLab.

Predicted Entities

PRO, PCT, PER, ORG, DAT, TIM, EVE, FAC, LOC, MON

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 = RoBertaForTokenClassification.pretrained("roberta_ner_roberta_fa_zwnj_base_ner","fa") \
.setInputCols(["sentence", "token"]) \
.setOutputCol("ner")

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

data = spark.createDataFrame([["من عاشق جرقه nlp هستم"]]).toDF("text")

result = pipeline.fit(data).transform(data)
val documentAssembler = new DocumentAssembler() 
.setInputCol("text") 
.setOutputCol("document")

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

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

val tokenClassifier = RoBertaForTokenClassification.pretrained("roberta_ner_roberta_fa_zwnj_base_ner","fa") 
.setInputCols(Array("sentence", "token")) 
.setOutputCol("ner")

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

val data = Seq("من عاشق جرقه nlp هستم").toDF("text")

val result = pipeline.fit(data).transform(data)
import nlu
nlu.load("fa.ner.roberta_fa_zwnj_base_ner").predict("""من عاشق جرقه nlp هستم""")

Model Information

Model Name: roberta_ner_roberta_fa_zwnj_base_ner
Compatibility: Spark NLP 3.4.2+
License: Open Source
Edition: Official
Input Labels: [document, token]
Output Labels: [ner]
Language: fa
Size: 442.7 MB
Case sensitive: true
Max sentence length: 128

References

  • https://huggingface.co/HooshvareLab/roberta-fa-zwnj-base-ner
  • https://github.com/HaniehP/PersianNER
  • http://nsurl.org/2019-2/tasks/task-7-named-entity-recognition-ner-for-farsi/
  • https://elisa-ie.github.io/wikiann/
  • https://github.com/hooshvare/parsner/issues