DeepLearning LabManual24!25!41 52
DeepLearning LabManual24!25!41 52
BY
Amey Bhavsar (62)
Ankita Upadhyay (73)
Deepanshu Yadav (74)
Guide
Prof.Neelam Phadnis
2
3
Abstract
Detecting sarcasm is a complex problem in natural language processing due to the challenges
associated with understanding the nuances of language and contextual cues. Sarcasm can be
difficult to detect, even for humans, as it often involves a speaker saying the opposite of what they
mean, or using irony or humor to convey a different meaning. It is especially challenging in
written text, as there are no visual or auditory cues to help identify the speaker's intention.
Despite the challenges, there is a growing need for sarcasm detection in various domains,
including social media monitoring, customer service, and sentiment analysis. Identifying sarcasm
can help businesses and organizations understand customer sentiment better, respond more
effectively to feedback, and improve communication with customers. Therefore, developing
accurate and reliable models for sarcasm detection is crucial.
In this project, we focused on developing a deep learning model for detecting sarcasm in news
headlines. We collected a dataset of news headlines from various sources, including satirical news
websites, and used a supervised learning approach to train our model. We chose a neural network-
based approach as it has shown promising results in other natural language processing tasks.
4
List of Figures
Fig. 2: Tokenizer
Fig. 7: Accuracy
5
Introduction
Detecting sarcasm in natural language is a challenging problem in natural language processing
due to its subjective nature and the contextual cues required to identify it accurately. Sarcasm
often involves speakers saying the opposite of what they mean, using irony or humor to convey
a different meaning, or relying on cultural references and shared knowledge. Sarcasm detection
has important applications in various domains, including social media monitoring, customer
service, and sentiment analysis. Identifying sarcasm can help organizations understand
customer sentiment better, respond more effectively to feedback, and improve communication
with customers.
In recent years, deep learning techniques have shown promising results in various natural
language processing tasks, including sarcasm detection. These techniques involve training
neural network models on large datasets to learn patterns and features that enable them to
identify sarcasm accurately. However, sarcasm detection remains a challenging problem, and
there is a need for developing more accurate and reliable models for this task.
In this project, we aimed to develop a deep learning model for detecting sarcasm in news
headlines using a supervised learning approach. We collected a dataset of news headlines from
various sources, including satirical news websites, and trained a neural network to predict the
probability of a sentence being sarcastic or not. Our project involved several steps, including
data preprocessing, feature engineering, and hyperparameter tuning. We evaluated the model's
accuracy and F1-score on a separate test dataset and performed a comprehensive analysis of its
performance.
Objective
1. To develop a deep learning model for detecting sarcasm in news headlines.
2. To collect a dataset of news headlines from various sources to use for training and testing the
model.
3. To preprocess the text data to convert the text into numerical features for the model.
4. To use supervised learning techniques to train the model on the dataset of news headlines.
5. To fine-tune the hyperparameters of the model to optimize its performance.
6. To evaluate the model's accuracy and F1-score on a separate test dataset.
7. To analyze the model's performance using a confusion matrix and examine its most significant
misclassifications.
8. To compare the performance of the developed model with existing sarcasm detection models.
9. To identify the limitations of the developed model and suggest areas for further improvement.
6
10. To provide insights into the sarcasm detection problem in natural language processing and its
practical applications in sentiment analysis, social media monitoring, and customer service.
Literature Review
Understanding users' opinions on various topics or events on social media requires understanding
both literal and figurative meanings. Detecting sarcastic posts on social media has received a lot of
attention recently, especially because sarcastic tweets frequently include positive words that
represent negative or undesirable characteristics. To comprehend the application of various machine
learning algorithms for sarcasm detection in Twitter, the Preferred Reporting Items for Systematic
Reviews and Meta-Analyses (PRISMA) statement was used. The combination of Convolutional
Neural Network (CNN) and SVM was discovered to provide high prediction accuracy. Furthermore,
our findings show that lexical, pragmatic, frequency, and part-of-speech tagging can improve SVM
performance, whereas both lexical and personal features can improve CNN-SVM performance.
III Multimodal Sarcasm Detection: A Deep Learning Approach [3] Santosh Kumar Bharti,
Rajeev Kumar Gupta
In this paper, we proposed a hybrid model for detecting sarcasm in conversational data. To detect
sarcasm, this method combines text and audio features. Three models were developed: the text
model, which only works with textual features, the audio model, which only works with audio
features, and the hybrid model, which works with both text and audio features. The hybrid model's
text and audio features were obtained as latent vectors from the other two models. Based on the
results, it is clear that the hybrid model outperforms the other two models. This is due to text and
audio features compensating for each other's flaws. As a result, these findings support our hypothesis
that combining text and audio increases the likelihood of detecting sarcasm.
7
Implementation
Fig. 1
We use a dataset that contains headline, article_link and is_sarcastic label for various news
headlines scraped from the internet.
2. Tokenization
Fig. 2
To convert words to sequences and then sequences to padded ones, we use tokenizer class to
fit the words on a given size of vocabulary. Padding appends extra characters at the end of
the sentence to make each of them that same length.
3. Model declaration
Fig. 3
Using Sequential class from tf.keras, we define a neural network with Embedding to receive
text sequences as input and end with a single neuron to get probability for sarcasm. The
sigmoid function returns a value between 0 to 1 and binary cross entropy is used since only
two classes are being compared, [Sarcastic, NOT Sarcastic].
4. Fit the model and perform predictions
Fig. 4
8
Fig. 5
Proposed System
The proposed system for detecting sarcasm in news headlines uses a deep learning model based on
a sequential neural network architecture. The model consists of several layers, including an
embedding layer, a global average pooling layer, and two dense layers.
The embedding layer converts the input text data into a numerical representation that the model can
process. The layer uses an embedding matrix with a fixed vocabulary size to map each word in the
input sentence to a corresponding vector representation. In this model, the embedding layer has 16
output dimensions.
The global average pooling layer computes the average of the embeddings for each word in the input
sentence to obtain a single vector representation of the sentence. This layer reduces the
dimensionality of the data and helps prevent overfitting.
The two dense layers are fully connected layers that perform nonlinear transformations on the input
data. The first dense layer has 24 output dimensions and uses the ReLU activation function, while
the second dense layer has a single output neuron with a sigmoid activation function. The sigmoid
function outputs a probability value between 0 and 1, representing the model's confidence that the
input sentence is sarcastic or not.
The model has a total of 160,433 parameters, all of which are trainable. During training, the model
adjusts its parameters to minimize the loss function between the predicted and actual labels for the
training data. Once trained, the model can be used to predict the sarcasm probability for new input
sentences.
Overall, this proposed system provides a simple and efficient approach to sarcasm detection using a
neural network architecture that has shown promising results in previous natural language processing
tasks.
9
Fig. 6
Results
Fig. 7
We collected a dataset of news headlines from various sources, including satirical news websites, and
trained our model on this dataset. Our model achieved an accuracy of 97% on training data and 81%
on validation data demonstrating its effectiveness in identifying sarcasm in news headlines.
Conclusion
In this project, we developed a deep learning model for detecting sarcasm in news headlines using a
supervised learning approach. Our model was based on a sequential neural network architecture and
10
used an embedding layer, global average pooling layer, and two dense layers to make predictions
about the sarcasm probability of the input sentences.
Through our project, we highlighted the importance of developing sophisticated models to solve the
sarcasm detection problem and the potential of deep learning techniques in this domain. Our approach
provides a simple and efficient way of identifying sarcasm in text, which has important applications
in sentiment analysis, social media monitoring, and customer service.
However, we also identified some limitations of our model, including its reliance on textual data and
the potential for bias in the training dataset. We suggest that future research should explore the use of
multimodal data and more diverse datasets to improve the performance and generalization of sarcasm
detection models. Overall, this project provides valuable insights into the sarcasm detection problem
in natural language processing and highlights the potential for deep learning techniques to improve
the accuracy and reliability of sarcasm detection models.
References
[1] A., K. and D., T. (no date) Sarcasm identification and detection in conversion context
using Bert, ACL Anthology. Available at: https://aclanthology.org/2020.figlang-1.10/
(Accessed: April 6, 2023).
[2] SARCASM detection using machine learning algorithms in ... - sage journals (no
date). Available at: https://journals.sagepub.com/doi/full/10.1177/1470785320921779
(Accessed: April 6, 2023).
[3] Bharti, S.K. et al. (2022) Multimodal Sarcasm Detection: A deep learning approach,
Wireless Communications and Mobile Computing. Hindawi. Available at:
https://www.hindawi.com/journals/wcmc/2022/1653696/ (Accessed: April 6, 2023).
[4] https://github.com/ashwaniYDV/sarcasm-detection-tensorflow/blob/main/sarcasm.json
11
12