Emotion Detection Classifier

Description

This model was imported from Hugging Face and it’s been fine-tuned on emotion dataset, leveraging Bert embeddings and BertForSequenceClassification for text classification purposes.

Predicted Entities

sadness, joy, love, anger, fear, surprise

Download Copy S3 URI

How to use

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

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

sequenceClassifier = BertForSequenceClassification \
.pretrained('bert_sequence_classifier_emotion', 'en') \
.setInputCols(['token', 'document']) \
.setOutputCol('class')

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

example = spark.createDataFrame([["What do you mean? Are you kidding me?"]]).toDF("text")

result = pipeline.fit(example).transform(example)
val document_assembler = DocumentAssembler() 
.setInputCol("text") 
.setOutputCol("document")

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

val tokenClassifier = BertForSequenceClassification.pretrained("bert_sequence_classifier_emotion", "en")
.setInputCols(Array("document", "token"))
.setOutputCol("class")

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

val example = Seq.empty["What do you mean? Are you kidding me?"].toDS.toDF("text")

val result = pipeline.fit(example).transform(example)
import nlu
nlu.load("en.classify.emotion.bert").predict("""What do you mean? Are you kidding me?""")

Results

['anger']

Model Information

Model Name: bert_sequence_classifier_emotion
Compatibility: Spark NLP 3.3.4+
License: Open Source
Edition: Official
Input Labels: [document, token]
Output Labels: [class]
Language: en
Size: 410.1 MB
Case sensitive: true
Max sentence length: 128

Data Source

https://huggingface.co/datasets/viewer/?dataset=emotion

Benchmarking

NOTE: The author didn’t share Precision / Recall / F1, only Validation Accuracy was shared as Evaluation Results.

Validation Accuracy: 0.931