DeBERTa Token Classification Xsmall - NER CoNLL (deberta_v3_xsmall_token_classifier_conll03)

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_xsmall_token_classifier_conll03 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: location (LOC), organizations (ORG), person (PER), and Miscellaneous (MISC).

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_xsmall_token_classifier_conll03", "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_xsmall_token_classifier_conll03", "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_xsmall.conll03").predict("""I really liked that movie!""")

Model Information

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

References

https://huggingface.co/datasets/conll2003