1 Introduction

Emotion detection from tweets is a comparatively new field compared to sentiment analysis using micro-blogs or tweets. The nature of twitter data and the versatility of human emotions make it difficult for automatic emotion detection from tweets. Sentiment detection, on the other hand, is a relatively easier process. Although the terms ‘emotion’ and ‘sentiment’ are considered synonymous to each other, they represent two different concepts in text analysis [1]. By definition, ‘emotion’ is “a strong feeling deriving from one’s circumstances, mood, or relationships with others” whereas ’sentiment’ is “a view or opinion that is held or expressed” [2]. Sentiments can be ‘Positive,’ ‘Negative,’ or ‘Neutral,’ but there exist lots of emotions with different expressions and names. ‘Anger,’ ‘Love,’ and ‘Admiration’ are few examples of emotions, while ‘Negative’ and ‘Positive’ are corresponding sentiments.

Sentiment analysis focuses on identifying and studying subjective information from human sentiments to find out the attitude of a person on some specific topic or the overall context of an event. Similarly, emotion analysis is an effective study of human emotions which tries to identify the proper emotion from context, and analyze it according to some predefined emotion class models.

Emotion analysis has many useful and practical applications. For instance, analyzing product reviews to find out emotions of consumers regarding a product can be used to improve business strategies. Emotions extracted from tweets or other social media posts on different personal, political, national, or international issues can be analyzed for personal public mood detection. For instance, a person whose posts reflect sadness, frustration, and depression may be immediately identified and referred to a specialist before something unpleasant like suicide might happen. Emotion analysis on social media posts about terrorism or terrorists can help law enforcement organizations to detect potential future terrorists. Analyzing emotions of a specific person over time can be an interesting tool for character analysis. Emotion analysis can also be applied in many other business, health, social, and political organizations to improve or modify their policies and approaches.

Detecting and analyzing emotion from text is a complicated task because of the diversity of human emotions. One small paragraph can contain multiple emotions with different polarities. Sometimes, emotions are not even expressed explicitly; a paragraph may direct to one or several subtle emotions which are implicit and therefore become more difficult to detect. For these reasons, tweets collected from Twitter can form a useful source for emotion analysis. Twitter is a social networking website which was created in 2006 and became very popular because of the lack of restrictions and frequencies of posts. Posts are called tweets and the maximum length of a tweet is only 140 characters. The length of the tweets makes the search space smaller which makes the emotion detection process comparatively easier. Extracting text from Twitter and analyzing tweets posted by people may give an idea of their emotional states and the reasons behind those emotions.

In this work, after extracting tweets on various topics, they were preprocessed and the words were divided into corresponding parts-of-speeches. After analyzing the words, they were classified into 32 emotion classes according to Robert Plutchik’s emotion classification model [3]. Emotions were then analyzed with respect to gender and location of the user and the time of the tweet. The analysis revealed some interesting outcomes and some new challenges.

The rest of this paper is outlined as follows. Some related works are summarized in Sect. 2. Section 3 describes the methodology of the emotion classification process. Section 4 shows experimental results and analysis of the results. Section 5 concludes the paper and outlines some possible future directions.

2 Literature Review

The research area of emotion detection and analysis from text focuses on different types of text such as articles, news, social media posts, product reviews, etc. However, lots of recent social media text emotion analysis works are based on twitter. Most of the existing works used five to twenty-eight emotion labels to classify the emotions extracted from tweets. Different machine learning techniques such as Support Vector Machine, Bayesian Network, K-Nearest Neighbor were used for automatic emotion detection. For instance, Emotex [4] is an emotion detection system which works with tweets and uses hashtags, unigrams, punctuations, and emoticons. Supervised classifiers like Nave Bayes, SVM, KNN, and Decision Tree were used to classify tweets into four emotion classes (Happy-Active, Happy-Inactive, Unhappy-Active, Unhappy-Inactive). Although they achieved 90% accuracy in classifying emotions, they used only the hashtag text and removed data with multiple emotions. On the other hand, 60% accuracy was achieved in another work with single emotion tweets where 28 emotion categories were used with supervised classifiers (SVM, Bayesian, Random, OneR, Majority Class) [5].

The work described in [6] proposed an Emotion-aware model which uses minimal set of domain-independent seed words as prior knowledge for constructing a domain specific lexicon related to predefined emotions, e.g., anger, disgust, fear, joy, sadness, and surprise. The work described in [7] developed and tested a generative unigram mixture model which is capable of learning a word-emotion association lexicon from an input document corpus. The work described in [8] developed dimensional and categorical models for emotion detection in text. The work described in [9] discusses emotion classified from twitter. The work described in [10] suggested a new hybrid model for detecting emotion from text based on ontology with keywords semantic similarity.

EmoGram [11], an emotion tracker was used to track emotion changes in cricket commentaries, characters in a play, and news articles about a specific topic. Their results were impressive, but they used only four emotions (happy, sad, anxious, and angry). Plexus [12] is an interactive visualization tool which works with five human emotions (happiness, sadness, fear, anger, and disgust); it is based on twitter text and shows people’s emotions on any two related topics with colors and emojis. Event-cause analysis for only Chinese language using event tree and binary classifier achieved almost 70% accuracy in [13]. But, they did not consider multiple emotions and used all possible permutations for event-cause analysis which increased the running time and required storage. A bilingual (English and Chinese) [14] emotion analysis model used multiple emotions and applied probabilistic joint factor graph model with natural language processing.

By closely analyzing existing works described in the literature, it can be easily realized that they suffer from some limitations. Most of them focused on a very limited number of human emotions. Further, they mostly detect and analyze emotions based only on hashtag words from tweets.

3 Methodology

The process for detecting emotions from tweets and analyzing them with respect to user’s gender and location involves several sequential steps. Tweets should be preprocessed before using them in the emotion analysis model. After that, parts-of-speech tagging is necessary to find out which words from the tweets to focus on. An emotion dictionary is required according to the chosen emotion class model. After detecting emotion unigrams, they should be classified into corresponding emotion classes.

3.1 Preprocessing

Collected tweets contain considerable amount of noises (e.g., extra and missing symbols, characters, spelling mistakes, etc.). The dataset was preprocessed by removing unnecessary parts in order to have more usable. First, @username (e.g., @mary), URLs (e.g., http://a.com/), and emoticons (e.g., “:-)”) were removed from the dataset. Then, multiple dots (e.g., ….), symbols (e.g., !!!), characters (e.g., happyyyyy) were also removed. Hashtag symbols were removed without removing the words associated with them (e.g., in the hashtag #sad—only # was removed, not “sad”). After removing these symbols the dataset was checked for redundancy. Finally, the filtered dataset had tweets with no emotions, hashtags, unnecessary multiple occurrences of one symbol or illegible words.

3.2 POS Tagging

A “parts-of-speech” tagger was used to tag each word of the tweets into corresponding parts-of-speech. In total, 36 parts-of-speech classes were used. They are Coordinating conjunction, Cardinal number, Determiner, Existential there, Foreign word, Preposition or subordinating conjunction, Adjective, Adjective—comparative, Adjective—superlative, List item marker, Modal, Noun—singular or mass, Noun—plural, Proper noun—singular, Proper noun—plural, Predeterminer, Possessive ending, Personal pronoun, Possessive pronoun, Adverb, Adverb—comparative, Adverb—superlative, Particle, Symbol, to, Interjection, Verb—base form, Verb—past tense, Verb—gerund or present participle, Verb—past participle, Verb—non 3rd person singular present, Verb—3rd person singular present, Wh determiner, Wh pronoun, Possessive wh pronoun, Wh adverb, and Others. Tweet words were tagged and each word was stored in one of those 37 (36 POS and Others) classes against user IDs.

3.3 Emotion Dictionary

Existing emotion detection systems use different emotion models according to their requirements. As described in the literature, Ekmans model [15], Johnson-laird and Oatley model [16], and Circumplex model [17] are the most used emotion classification models. But the limitation of these models is that they focus on only few basic emotions. The Circumplex model works with 28 emotions and it is a widely used emotion model. Another emotion model called “Plutchik’s Wheel of Emotion” defined 32 emotions. Emotion classification used in this work is Plutchik’s model with 32 emotions (as shown in Fig. 1)—Acceptance, Admiration, Aggressiveness, Amazement, Anger, Annoyance, Anticipation, Apprehension, Awe, Boredom, Contempt, Disapproval, Disgust, Distraction, Ecstasy, Fear, Grief, Interest, Joy, Loathing, Love, Optimism, Pensiveness, Rage, Remorse, Sadness, Serenity, Submission, Surprise, Terror, Trust, and Vigilance.

Fig. 1
figure 1

Plutchik’s wheel of emotion

Something interesting about tweets is that some of them did not express any specific emotion; they just expressed some facts or asked some questions. Some tweets represented taunts, requests, advices, suggestions, or sarcasms. Some tweets had words from multiple languages. Some tweets did not make any sense, they looked like just some random words put together. Those tweets were classified as Others.

The emotion dictionary was built based on these 32 emotions. Synonyms for each emotion word were collected from various online English dictionaries [18,19,20,21,22]. After inserting the synonyms from English dictionaries, we went one step further and some common synonymous words used in tweets were collected from some dictionaries based on tweet words only. Those words were also inserted into the emotion dictionary for each emotion [23, 24]. Finally some common acronyms used nowadays were extracted from different sources and were inserted for each emotion. After merging all these synonymous words and acronyms, the emotion dictionary had more than 20 synonyms for each emotion.

3.4 Unigram Selection and Dataset Annotation

After building the emotion dictionary, the dataset was annotated with emotions. To select emotion unigrams (one word), we removed unnecessary POSs from our dataset (i.e., articles, prepositions, etc.) and concentrated on the rest of the words to annotate each tweet with an emotion. Here, POSs that we mostly focused on were nouns, adjectives, and adverbs. For tweets in which multiple emotions existed, we considered the primary emotion and annotated the tweet accordingly. The emotion model used in this work has not been previously applied in any other work, so no automated system for data annotation exists according to this model. Therefore, the dataset annotation was completed manually.

3.5 Emotion Classification

The final step for emotion detection was emotion classification by a classifier using the emotion dictionary. Different supervised classifiers like KNN, Naive Bayes classifier, and Decision tree have been used in literature for emotion classification. In most cases, the Naive Bayes classifier produced the most accurate results. Accordingly, Naive Bayes classifier was used for emotion classification in this paper.

(1)
(2)

Equations (1) and (2) represent the Naive Bayes classifier. Here C k is the emotion class. We have 32 emotion classes. So for this case, k varies from 1 to 32 and x i ’s are the unigrams used for emotion detection from each tweet. Finally, 70% of the annotated data was used as a training set and the rest 30% data acted as the test set for the classifier.

4 Experimental Results

Every step of the methodology—preprocessing, parts-of-speech tagging, creating emotion dictionary, implementing Naive Bayes classifier, classifying tweets according to their emotions and analyzing the results was implemented and tested using different packages of R for networks, graphs, matrices, Natural Language Processing, words, parts-of-speech, and synonyms. Several data matrices and data frames were used for the intermediate calculations.

4.1 Dataset

The dataset used in this experiment was collected from the tweets of 26 October 2015 [25]. The user ID, tweet location (city or some local information), user gender, and time of the tweets were extracted from the dataset . Almost 30% of the tweets had to be removed because those tweets were advertisement tweets for different products or websites. Retweets and illegible tweets were deleted from the rest of the tweets. The location of each tweet was replaced with corresponding country name based on the given city name or local information. Finally, each data in the dataset had a user ID, tweet text, gender of the user, location of the user (country), and time of the tweet expressed in “hh:mm” format.

4.2 Results

Tweets were classified into 32 emotion classes with their corresponding ID, gender, location, and time of each tweet. Users were then classified according to these parameters and analyzed based on their emotions.

4.2.1 Emotion Network

Shown in Fig. 2 is the emotion network for all the 32 emotions. The network could be divided into clusters of nodes based on different emotions. Here, nodes represent users. People who share the same emotion are connected to each other and form one cluster. So, for each emotion, we have a cluster consists of people who expressed the same emotion via their tweets. Some emotions were used more than others in tweets and this is the reason of having different cluster sizes. From Fig. 2, it can be clearly realized that majority of the tweets represented Admiration. Joy, Optimism, Others. Some other notable emotions appeared in the dataset where quite a lot of users expressed Sadness, Disgust, Love, Disapproval. The rest of the emotions were encountered as well, but were not that much prominent in the dataset.

Fig. 2
figure 2

Emotion network

4.2.2 Gender Versus Emotion

Gender information which we got from the tweets was divided into two classes, namely male and female. In Fig. 3, the X-axis represents emotions and the Y -axis represents percentages of tweets of that emotion from a gender. Blue bars show Female tweets, and red bars show Male tweets.

Fig. 3
figure 3

Gender vs. emotion

Female users had the majority in positive emotions like Anticipation, Joy, Love, Pensiveness, Serenity, but they were also the major contributors to negative emotions like Boredom, Disgust, Disapproval, Fear, Grief, Loathing, Remorse, and Submission. In contrast, Male users expressed positive emotions like Acceptance, Amazement, Awe, and Trust and negative emotions like Aggressiveness, Anger, Distraction, Sadness, and Vigilance more than Females. Other emotions were mentioned in tweets from both Male and Female almost equally. Surprisingly, Apprehension was expressed by Females only.

4.2.3 Time Versus Emotion

Temporal information which we got from the tweets was divided into two classes. Tweets which were posted before up to 12:00 noon were classified as Morning tweets, and tweets that were posted after 12:00 noon were classified as Afternoon tweets. In Fig. 4, the X-axis represents emotions and the Y -axis represents corresponding percentages of tweets based on their temporal classes. Blue bars show Afternoon tweets and red bars show Morning tweets.

Fig. 4
figure 4

Time versus emotion

From the graph shown in Fig. 4, we can see that negative emotions like Loathing and Terror were prominent in Afternoon tweets with one exception, namely Love. On the other hand, positive emotions like Acceptance, Admiration, Amazement, Anticipation, Ecstasy, Interest, Joy, Optimism, Pensiveness, and Serenity, and negative emotions like Aggressiveness, Annoyance, Boredom, Contempt, Disgust, Remorse, Sadness, and Submission mostly occurred in Morning tweets. Apprehension, Distraction, Trust, and Vigilance have been encountered only in Morning tweets.

4.2.4 Location Versus Emotion

The relationship between emotion and user location (country) is shown in Figs. 5, 6, 7, 8, 9, 10, and 11. In Fig. 5, all the 32 emotions are shown in the map with different colors according to their locations. The pie charts shown in Figs. 6, 7, 8, 9, 10, 11 were generated based on 33 emotion classes (32 emotions and others) according to 63 countries (Africa, Argentina, Armenia, Australia, Austria, Belgium, Brazil, Canada, Chile, China, Colombia, Croatia, Czech Republic, Denmark, Dominican Republic, Ecuador, Egypt, Europe, France, Germany, Greece, Greenland, India, Indonesia, Iraq, Ireland, Israel, Italy, Japan, Kenya, Korea, Kuwait, Lebanon, Malaysia, Mexico, Morocco, Netherlands, New Zealand, Nigeria, Pakistan, Pennsylvania, Peru, Philippines, Poland, Polynesia, Portugal, Romania, Rome, Russia, Saudi Arabia, Serbia, Singapore, Spain, Sweden, Switzerland, Syria, Trinidad and Tobago, Turkey, UK, USA, Venezuela, Zimbabwe) which were detected from the dataset. Each circle represents an emotion and countries which contributed to that particular emotion. As most tweets were from USA and UK, these two countries were the two major contributors to all emotions.

Fig. 5
figure 5

Location vs. emotion (1)

Fig. 6
figure 6

Location vs. emotion (2)

Fig. 7
figure 7

Location vs. emotion (3)

Fig. 8
figure 8

Location vs. emotion (4)

Fig. 9
figure 9

Location vs. emotion (5)

Fig. 10
figure 10

Location vs. emotion (6)

Fig. 11
figure 11

Location vs. emotion (7)

For positive emotions like Ecstasy, Joy, Admiration, Acceptance, Anticipation, Interest, Amazement, Surprise, Pensiveness, Love, and Optimism, in addition to USA and UK, tweets from countries like Canada, Greece, Netherlands, Australia, India, and Nigeria are some major participators. Similarly, other than USA and UK, countries like Canada, Netherlands, Germany, New Zealand, Mexico, Australia, Ecuador, Europe, Indonesia, Sweden, Kenya, and Africa expressed negative emotions like Grief, Sadness, Loathing, Disgust, Boredom, Rage, Anger, Annoyance, Terror, Fear, Submission, Disapproval, Remorse, and Aggressiveness, more than other countries.

Experimental result as reported in this paper reflected some interesting aspects regarding emotions of a person with respect to his/her gender, location and time. But these results can not be generalized for all human beings and their emotions because they are completely based on a specific dataset containing tweets collected on a random day from different people scattered almost over all the world. It is important to investigate whether emotions were directly reflecting personal feelings related to any particular events associated with the time period during which the tweets were posted.

5 Conclusions and Future Work

Emotion detection and analysis is an important research area for analyzing both individual and public emotions on various events. The diversity and multiple dimensions of human emotions make it very difficult to find out the exact emotion from a text. The emotion model that was used in this work covered almost all basic human emotions. A larger emotion dictionary built by collecting words from different sources made emotion detection more sparse and accurate. Acronyms of common tweet words and some common words used in tweets only were considered in this work which made the emotion detection process easier and more efficient. After detecting emotions from the text, the analysis on the emotion with respect to gender, location, and time represented some interesting human characteristics.

Based on the study described in this paper, we have identified a number of aspects which we have started to investigate further with the hope to produce an improved model and hence produce better results. For instance, one of the limitations of this work is that the system cannot process tweets containing multiple emotions which can be considered as a possible future work. Detecting sarcasms, slangs, metaphors, and implicit emotions can also be some possible fields to focus on in future. In this paper, all emotions were considered with the same intensity which is not the case in real life. Assigning different weights to different emotions based on their intensity and the involved user would be interesting to investigate. Also, an improved emotion classification model could be a new research topic and a promising extension of this work.