CamemBERT Token Classification Base - French WikiNER (camembert_base_token_classifier_wikiner)

Description

CamemBertForTokenClassification can load CamemBERT Models 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.

camembert_base_token_classifier_wikiner is a fine-tuned CamemBERT 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 TFCamembertForTokenClassification to train this model and used CamemBertForTokenClassification annotator in Spark NLP 🚀 for prediction at scale! This model has been trained to recognize four types of entities: O, LOC, PER, MISC, and ORG.

Download Copy S3 URI

How to use

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

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

tokenClassifier = CamemBertForTokenClassification.pretrained("camembert_base_token_classifier_wikiner", "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 = CamemBertForTokenClassification.pretrained("camembert_base_token_classifier_wikiner", "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.camembert.base").predict("""I really liked that movie!""")

Model Information

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

References

https://huggingface.co/datasets/Jean-Baptiste/wikiner_fr

Benchmarking

root: "{"
eval_loss ": 0.0396629199385643, "
eval_precision ": 0.9283267457180501, "
eval_recall ": 0.9337809780447939, "
eval_f1 ": 0.9310458739841875, "
eval_accuracy ": 0.9896610647939648, "
eval_runtime ": 204.7064, "
eval_samples_per_second ": 65.508, "
eval_steps_per_second ": 4.099, "
epoch ": 3.0}"