Sarcasm Classifier

Description

Classify if a text contains sarcasm.

Predicted Entities

normal, sarcasm

Live Demo
Open in Colab
Download Copy S3 URI

How to use

documentAssembler = DocumentAssembler()\
.setInputCol("text")\
.setOutputCol("document")
use = UniversalSentenceEncoder.pretrained(lang="en") \
.setInputCols(["document"])\
.setOutputCol("sentence_embeddings")
document_classifier = ClassifierDLModel.pretrained('classifierdl_use_sarcasm', 'en') \
.setInputCols(["document", "sentence_embeddings"]) \
.setOutputCol("class")

nlpPipeline = Pipeline(stages=[documentAssembler, use, document_classifier])

light_pipeline = LightPipeline(nlp_pipeline.fit(spark.createDataFrame([['']]).toDF("text")))

annotations = light_pipeline.fullAnnotate('If I could put into words how much I love waking up at am on Tuesdays I would')

val documentAssembler = DocumentAssembler()
.setInputCol("text")
.setOutputCol("document")
val use = UniversalSentenceEncoder.pretrained(lang="en")
.setInputCols(Array("document"))
.setOutputCol("sentence_embeddings")
val document_classifier = ClassifierDLModel.pretrained("classifierdl_use_sarcasm", "en")
.setInputCols(Array("document", "sentence_embeddings"))
.setOutputCol("class")
val pipeline = new Pipeline().setStages(Array(documentAssembler, use, document_classifier))

val data = Seq("If I could put into words how much I love waking up at am on Tuesdays I would").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu

text = ["""If I could put into words how much I love waking up at am on Tuesdays I would"""]
sarcasm_df = nlu.load('classify.sarcasm.use').predict(text, output_level='document')
sarcasm_df[["document", "sarcasm"]]

Results

+--------------------------------------------------------------------------------------------------------+------------+
|document                                                                                                |class       |
+--------------------------------------------------------------------------------------------------------+------------+
|If I could put into words how much I love waking up at am on Tuesdays I would                           | sarcasm    |
+--------------------------------------------------------------------------------------------------------+------------+

Model Information

Model Name classifierdl_use_sarcasm
Model Class ClassifierDLModel
Spark Compatibility 2.5.3
Spark NLP Compatibility 2.4
License open source
Edition public
Input Labels [document, sentence_embeddings]
Output Labels [class]
Language en
Upstream Dependencies with tfhub_use

Data Source

This model is trained on the sarcam detection dataset. https://github.com/MirunaPislar/Sarcasm-Detection/tree/master/res/datasets/riloff

Benchmarking

Accuracy of label sarcasm with USE Embeddings is 0.84

precision    recall  f1-score   support

0       0.84      1.00      0.91       495
1       0.00      0.00      0.00        93

accuracy                           0.84       588
macro avg       0.42      0.50      0.46       588
weighted avg       0.71      0.84      0.77       588