<jupyter_start><jupyter_text>![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/nlu/blob/master/examples/colab/component_examples/classifiers/sarcasm_classification.ipynb) Sarcasm Classification with NLU![](https://camo.githubusercontent.com/0a466b438cfd4f2bc5248f5029cde1fb66dbdefc/68747470733a2f2f6d656d657362616d732e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031372f31312f7368656c646f6e2d7361726361736d2d6d656d652e6a7067)             Knowing the difference between when somebody is serious or sarcastic can yield inisghts about users of social media plattforms like  Twitter, Reddit, Facebook, etc..     NLU provides a classifier pretrained on [sarcasm dataset](https://arxiv.org/abs/1704.05579) consisting of 1.3 million sarcastic comments from the internet forum Reddit. The Sarcasm classifier model uses universal sentence embeddings and is trained with the classifierdl algorithm provided by Spark NLP.            https://www.kaggle.com/danofer/sarcasm<jupyter_code>import os
! apt-get update -qq > /dev/null   
# Install java
! apt-get install -y openjdk-8-jdk-headless -qq > /dev/null
os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-8-openjdk-amd64"
os.environ["PATH"] = os.environ["JAVA_HOME"] + "/bin:" + os.environ["PATH"]
! pip install nlu pyspark==2.4.7 > /dev/null    
# Download the dataset 
! wget -N https://s3.amazonaws.com/auxdata.johnsnowlabs.com/public/resources/en/sarcasm/train-balanced-sarcasm.csv -P /tmp
import nlu
sarcasm_pipe  = nlu.load('en.classify.sarcasm')
sarcasm_pipe.predict('gotta love the teachers who give exams on the day after halloween')
import pandas as pd
df = pd.read_csv('/tmp/train-balanced-sarcasm.csv')

sarcasm_pipe  = nlu.load('en.classify.sarcasm')
df['text'] = df['comment']
sarcasm_predictions = sarcasm_pipe.predict(df['text'].iloc[0:1000])
sarcasm_predictions
sarcasm_predictions.sarcasm.value_counts().plot.bar(title='Counts of Normal and Sarcasm predicted sentences')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11633428300094967, 'fraction_numerical': 0.07597340930674264, 'mean_word_length': 5.667721518987341, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 7, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '376544', 'license': 'Apache-2.0', 'n_tokens_mistral': 855, 'n_tokens_neox': 753, 'n_words': 138, 'path': 'examples/colab/component_examples/classifiers/sarcasm_classification.ipynb', 'repo_name': 'UPbook-innovations/nlu', 'size': '2106'}