Sarcasm Classifier - Spark NLP 2.7.1+

Description

Classify if a text contains sarcasm.

Predicted Entities

normal, sarcasm

Live Demo Open in Colab Download

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')

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
Compatibility: Spark NLP 2.7.1+
License: Open Source
Edition: Official
Input Labels: [sentence_embeddings]
Output Labels: [class]
Language: en
Dependencies: tfhub_use

Data Source

http://www.cs.utah.edu/~riloff/pdfs/official-emnlp13-sarcasm.pdf

Benchmarking

              precision    recall  f1-score   support

      normal       0.98      0.89      0.93       495
     sarcasm       0.60      0.91      0.73        93

    accuracy                           0.89       588
   macro avg       0.79      0.90      0.83       588
weighted avg       0.92      0.89      0.90       588