DeBERTa Token Classification Large - NER OntoNotes (deberta_v3_large_token_classifier_ontonotes)

Description

DeBertaForTokenClassification can load DeBERTA Models v2 and v3 with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for Named-Entity-Recognition (NER) tasks.

deberta_v3_large_token_classifier_ontonotes is a fine-tuned DeBERTa model that is ready to be used for Token Classification task such as Named Entity Recognition and it achieves state-of-the-art performance.

We used TFDebertaV2ForTokenClassification to train this model and used DeBertaForTokenClassification annotator in Spark NLP 🚀 for prediction at scale! This model has been trained to recognize four types of entities: CARDINAL, DATE, EVENT, FAC, GPE, LANGUAGE, LAW, LOC, MONEY, NORP, ORDINAL, ORG, PERCENT, PERSON, PRODUCT, QUANTITY, TIME, and WORK_OF_ART.

Download Copy S3 URI

How to use


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

tokenizer = Tokenizer()\ 
.setInputCols(['document'])\ 
.setOutputCol('token') 

tokenClassifier = DeBertaForTokenClassification.pretrained("deberta_v3_large_token_classifier_ontonotes", "en")\ 
.setInputCols(["document", "token"])\ 
.setOutputCol("ner")\ 
.setCaseSensitive(True)\ 
.setMaxSentenceLength(512) 

# since output column is IOB/IOB2 style, NerConverter can extract entities
ner_converter = NerConverter()\ 
.setInputCols(['document', 'token', 'ner'])\ 
.setOutputCol('entities') 

pipeline = Pipeline(stages=[
document_assembler,
tokenizer,
tokenClassifier,
ner_converter
])

example = spark.createDataFrame([['I really liked that movie!']]).toDF("text")
result = pipeline.fit(example).transform(example)

val document_assembler = new DocumentAssembler()
.setInputCol("text")
.setOutputCol("document")

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

val tokenClassifier = DeBertaForTokenClassification.pretrained("deberta_v3_large_token_classifier_ontonotes", "en")
.setInputCols("document", "token")
.setOutputCol("ner")
.setCaseSensitive(true)
.setMaxSentenceLength(512)

// since output column is IOB/IOB2 style, NerConverter can extract entities
val ner_converter = NerConverter() 
.setInputCols("document", "token", "ner") 
.setOutputCol("entities")

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

val example = Seq("I really liked that movie!").toDS.toDF("text")

val result = pipeline.fit(example).transform(example)
import nlu
nlu.load("en.ner.debertav3_large.ontonotes").predict("""I really liked that movie!""")

Model Information

Model Name: deberta_v3_large_token_classifier_ontonotes
Compatibility: Spark NLP 3.4.4+
License: Open Source
Edition: Official
Input Labels: [token, document]
Output Labels: [ner]
Language: en
Size: 1.5 GB
Case sensitive: true
Max sentence length: 512

References

https://huggingface.co/datasets/conll2003