XLM-RoBERTa Sequence Classification Multilingual - AlloCine (xlm_roberta_base_sequence_classifier_allocine)

Description

XLM-RoBERTa Model with sequence classification/regression head on top (a linear layer on top of the pooled output) e.g. for multi-class document classification tasks.

xlm_roberta_base_sequence_classifier_allocine is a fine-tuned XLM-RoBERTa model that is ready to be used for Sequence Classification tasks such as sentiment analysis or multi-class text classification and it achieves state-of-the-art performance.

We used TFXLMRobertaForSequenceClassification to train this model and used XlmRoBertaForSequenceClassification annotator in Spark NLP 🚀 for prediction at scale!

Predicted Entities

neg, pos

Download Copy S3 URI

How to use

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

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

sequenceClassifier = XlmRoBertaForSequenceClassification \
.pretrained('xlm_roberta_base_sequence_classifier_allocine', 'fr') \
.setInputCols(['token', 'document']) \
.setOutputCol('class') \
.setCaseSensitive(True) \
.setMaxSentenceLength(512)

pipeline = Pipeline(stages=[
document_assembler,
tokenizer,
sequenceClassifier
])

example = spark.createDataFrame([['j'ai bien aime le film harry potter!']]).toDF("text")
result = pipeline.fit(example).transform(example)
val document_assembler = DocumentAssembler()
.setInputCol("text")
.setOutputCol("document")

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

val tokenClassifier = XlmRoBertaForSequenceClassification.pretrained("xlm_roberta_base_sequence_classifier_allocine", "fr")
.setInputCols("document", "token")
.setOutputCol("class")
.setCaseSensitive(true)
.setMaxSentenceLength(512)

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

val example = Seq("j'ai bien aime le film harry potter!").toDS.toDF("text")

val result = pipeline.fit(example).transform(example)
import nlu
nlu.load("fr.classify.xlm_roberta.allocine").predict("""Put your text here.""")

Results

* +--------------------+
* |result              |
* +--------------------+
* |[neg, neg]          |
* |[pos, pos, pos, pos]|
* +--------------------+

Model Information

Model Name: xlm_roberta_base_sequence_classifier_allocine
Compatibility: Spark NLP 3.4.0+
License: Open Source
Edition: Official
Input Labels: [token, document]
Output Labels: [ner]
Language: fr
Size: 878.5 MB
Case sensitive: true
Max sentense length: 512

Data Source

https://huggingface.co/datasets/allocine

Benchmarking

{
	"eval_loss": 0.129339799284935,
	"eval_accuracy": 0.96915,
	"eval_f1": 0.96915,
	"eval_precision": 0.96915,
	"eval_recall": 0.96915,
	"eval_runtime": 256.0691,
	"eval_samples_per_second": 78.104,
	"eval_steps_per_second": 4.881,
	"epoch": 2.0
}