Keywords

1 Introduction

The word Sarcasm is derived from the Latin word which means “to tear flesh”, and it has been called “hostility disguised as humor” and generally used to make fun of others by some people (Teh et al. 2018). Presence of sarcasm can completely change the meaning of a sentence. Hence it is important to identify the sarcasm in opinion mining and sentiment analysis. Sarcasm is considered to be an important aspect in the reviews because of the absence of face-to-face conversation. Since the growth of internet usage is getting higher over time and the volume of data generation is huge, the process of data analysis becomes a tedious task. Sarcasm leads to an additional complication in the text analysis process. Social media sites act as a platform for the users to express their views and opinions on various topics and events. When a customer tweets “Great multipurpose phone! Can be used as a phone and as a hot iron as well”, a review taken from a branded mobile contains positive sentiment words but the review is actually negative as it being mocked for over-heating. This results in the review to be wrongly classified into positive sentiment which will directly or indirectly affect the decision making for business development. This is why detection of sarcasm is important. Selecting and describing a set of features for identifying sarcasm at a linguistic level, especially in short texts created in social media such as Twitter postings or ‘‘tweets’’ is being followed widely. In the context of text classification, sarcasm detection is an important factor since it has many implications on various fields such as health, sales, politics, and many more (Sarsam et al. 2020). Sarcasm has a major effect on Sentiment analysis. But most of the research works ignored sarcasm detection due to its difficulty in finding. Numerous researches are being done in order to detect sarcasm with the help of the usage of words and various features in text data. There are also methods where models are built in order to extract sentiments and contextual information from the data. Supervised and Unsupervised approaches can be used for detecting sarcasm. Researches have been done using a lexicon-based, rule-based approach, corpus-based approach, statistical-based approach, and various machine learning approaches. The proposed work uses Naïve Bayes classification, a machine learning approach to detect sarcasm in tweets.

2 Literature Survey

Numerous studies and researches had been conducted on Sentiment Analysis. It was during the early 1990s that the research was started in the field of sentiment analysis. The term sentiment analysis along with opinion mining was first introduced in the year 2003 by Dave et al. (2003) during this time, the work was very much limited only to subjective detection, sentiment adjectives, and interpretation of metaphors and within 15 years the research interests in this area have increased manifold (Pang and Lee 2008; Kumar and Teeja 2012). Some remarkable studies mentioned that sarcasm in a sentence by conflict and contrast of sentiment polarity (Camp 2012; Riloff et al. 2013; Joshi et al. 2017). Kumar and Garg (2019) suggested that detection of sarcasm in natural language text is a well-accepted problem in the area of sentiment analysis.

Parveen and Pandey (2016) discussed the extraction process of sentiment from Twitter and they have analyzed the tweets to provide predictions on business intelligence using Naïve Bayes algorithm. Authors have used Hadoop Framework and worked on movie data from Twitter. The reviews of movies have been classified as positive, negative, and neutral sentiments. The proposed work proves that performance of the Naive Bayes algorithm increases by converting the emoticons into its equivalent word. A novel approach has been used (Khan et al. 2014) to classify the tweets into positive, negative, and neutral feelings using emoticon classifier, Bag-of-words, and SentiWordnet classifier and obtained increased classification accuracy. Authors (Samonte et al. 2018; Farías et al. 2018) mentioned Naive Bayes, Maximum Entropy, and Support Vector Machine are commonly used as the machine learning algorithms for the detection of sarcasm. Affective and structural features are employed (Mukherjee and Bala 2017) to predict irony with conventional machine learning classifiers such as Decision Tree, SVM, and Naïve Bayes. In a follow-up study by Farías et al. (2016) have used a knowledge-based k-NN classifier with a feature set that could capture a broad range of linguistic phenomena namely structural and emotional. Apart from machine learning algorithm, many research works are done using Deep learning networks. Saha et al. (2017) used Naïve Bayes and Support Vector Machine (SVM) classifiers to classify the data for sarcasm detection and also aim to differentiate between the accuracy, precision, recall, and F-score of Naïve Bayes and SVM classifier. Zhang et al. (2011) classified sentiment using Naïve Bayes and SVM for restaurant reviews written in Cantonese. The highest accuracy reported was 95.67% using Naïve Bayes. Kiilu et al. (2018) developed an approach for detecting and classifying hateful speech that uses content produced by self-identifying hateful communities from Twitter. Results from their experiments showed that Naive Bayes classifier achieved significantly better performance than existing methods in hate speech detection algorithms. The work is done by Van Hee et al. (2018) used a combination of lexical, semantic, and syntactic features and were implemented using Support Vector Machine Classifier and results showed that it outperformed Long short-term memory, deep neural network approaches. Potamias et al. (2020) employed advanced deep learning methodologies to tackle the problem of identifying the Figurative language forms. The performance was measured using the devised hybrid neural architecture and experimented with various datasets and contrasted with other appropriate state-of-the-art methodologies and systems. Irsoy and Cardie (2014) applied the deep Recurrent Neural Network (RNN) to the task of opinion expression extraction formulated as a token-level sequence labeling task. Experimental results show that deep, narrow RNNs outperform traditional shallow, wide RNNs with the same number of parameters.

Sarcasm detection becomes difficult without having adequate knowledge of the “context” of the situation, the particular topic, and the environment (Kumar and Garg 2019). Numerous researches are being done in order to detect sarcasm with the help of usage of the words and various features in text data. There are also methods where models are built in order to extract sentiments and contextual information from the data. Re-searches have been taken place using lexicon-based, rule-based approach, corpus-based approach, statistical-based approach, and various machine learning approaches. The recent work concentrates more on Deep learning approaches (Eke et al. 2020).

Though many researches have been done on Sarcasm detection, a comparison of accuracy level and the time required to complete the process using various tools like R and Python have not been done so far. Thereby the proposed work implemented Naive Bayes algorithm for the dataset using R and Python. Moreover, this work helps researchers to get an idea of the steps involved in the sarcasm detection process.

3 Methodology

3.1 Data Collection and Preprocessing

The dataset has been collected from Twitter using Twitter API. The collected data is noisy and it cannot be directly fed into the classifier as it will affect the working of the classification algorithm. RE (Regular Expressions) and NLTK (Natural Language Tool Kit) packages in Python were used to clean the data by removing new lines and tabs, punctuations, hashtagged words, emoticons, and emojis and the stop words. In total 1992 preprocessed tweets have been parsed into the system.

3.2 Training and Testing Phase

The collected tweets were divided into training and testing set. In the proposed work the dataset has been split into 70:30 ratio. The purpose of the training dataset is to provide the algorithm with “ground truth” data whereas the test dataset is used to check how well the algorithm was trained with the provided training dataset.

3.3 Implementation

The proposed work used Naïve Bayes approach since it is one among the well-known classification algorithms and it works based on Bayes’ Theorem. This algorithm makes use of conditional probability to predict the likelihood of future occurrence of events based on their historical information.

Bayes’ Theorem is mentioned as:

$$P\left( {A|B} \right) = P\left( A \right)P\left( {B|A} \right)P\left( B \right)$$
(1)

The implementation has been done using R programming and Python to check the difference in accuracy. Various libraries namely Readxl, tm, wordcloud, E1071, gmodels, and naiveBayes have included in R studio whereas Nltk and stopwords were used for implementation using python.

4 Results and Discussion

4.1 Implementation Using R

Naïve Bayes approach is used as the classification algorithm and with the support of various libraries the model has been implemented using R Studio. The given data has been classified as sarcastic and non-sarcastic tweets where the value 0 indicates non-sarcastic and the value 1 represents sarcastic and the same has been depicted in Fig. 1 and the performance of the model has been evaluated and the results obtained are represented in Fig. 2 respectively.

Fig. 1
figure 1

Classification of sarcastic and non-sarcastic tweets

Fig. 2
figure 2

Evaluation of model performance

4.2 Implementation Using Python

Dataset has been passed to the Naïve Bayes approach to check whether the given data is sarcastic or non-sarcastic. Nltk and stopwords were used for implementation using python. MultinominalNB has been used for the classification with discrete features such as word counts for classifying the text. Training and testing data has been split in the ratio of 70:30 where 70% of data has been passed for training the model whereas 30% of data has been passed for testing the model. Tweets have been classified as sarcastic and non-sarcastic and are represented in Fig. 3 and the accuracy obtained was 0.88 and it is depicted in Fig. 4.

Fig. 3
figure 3

Classification of sarcastic and non-sarcastic tweets

Fig. 4
figure 4

Evaluation of model performance

5 Conclusion

Sarcasm detection is considered as the challenging factor in sentiment analysis since it gives a gap between the intended meaning and the literal meaning of the sentences. This ambiguity poses challenges to the industries in making proper decisions. By doing sentiment analysis on the social media data, that gives a tremendous change in their way of making decisions. R and Python are open-source and widely used in the analytical process. Statistical analysis is the major purpose of using R whereas data science is the core idea of Python. Python is considered as the most robust language than R. However, R has more built-in analysis for summary statistics and Python works on the basis of packages. The main implications of the proposed work are to help to take decisions based on the reviews or comments written on social media platforms. As future research semantic tools can be used to detect sarcasm and an ontology model can be created to classify the texts accurately by reducing the problem of wrong classification of texts.