Context based Emotion Analyzer for Interactive Agent

Emotions can affect human’s performance in a considerable manner. These emotions can be articulated in many ways such as text, speech, facial expressions, gestures and postures. Humans in effect of their emotions, have ability to perform surprising tasks under their emotional state. In recent years, interactive cognitive agents are being utilized in industrial and non-industrial organizations to interact with persons inside or outside the organization. Existing agents are intelligent enough to communicate like humans by expressing their emotions and recognizing emotions of other person. One of the main limitation of existing interactive agents is that they can only recognize emotions based on predefined keywords or semantics instead of analyzing the context in which those keywords were used. The focus of this paper is to study context based emotions and to present a model, which can analyze the context and generate emotion accordingly. Keywords—artificial general intelligence; context based sentiments; emotions; natural language processing; machine learning


INTRODUCTION
During last decade researchers from different domains such as psychology, linguistics, social science, communication and artificial intelligence tried to explore emotions and its impact on everyday situations.Human emotions articulate in the form of facial expressions, gesture, postures, voice or text [1].Tremendous advancement in Artificial General Intelligence (AGI) have attracted researchers to develop interactive cognitive agents having ability to recognize, interpret and express human like emotions.Some existing cognitive agents somehow perceive emotions from facial expressions, gestures, voice and text [2], [3].
Several attempts have been made previously to explore different dimensions of emotions especially from text.Emotion extraction from text is aimed towards understanding that how people express emotions through text.It is also equally important to understand that how text manipulates emotions particularly happiness, surprise, fear, sadness, disgust and anger [4], [5].Text may indicate vibrant representation of emotion presence yet in many cases emotions are concealed behind the text [6].
Emotions have profound influence on everyday life so that Interactive Cognitive Agent (ICA) may have the ability to perceive, learn and interact with environment [7].ICA having ability to perceive emotion using contextual information may contribute a lot in the advancement of this area of research.Therefore, there is a need to design ICA having ability to perceive emotions from text by evaluating context like humans who can recognize emotions by analyzing situations based on environment and circumstances [8].Previously several attempts have been made to extract emotions from text based on keyword spotting, text mining, machine learning, semantics based and corpus based methods.However, current agents are still lacking the ability to learn and articulate emotions from text based on context [9].This research work focus on analysis of emotion's polarity, which means analysis of negative and positive emotions from text, based on context generated by analyzer.

II. LITERATURE REVIEW
Emotions can be expressed in various ways including facial expressions, speech utterances, writing, gestures and actions.Consequently, scientific research in emotions has been pursued along several dimensions and drawn upon research from various fields like psychology, linguistics, social sciences and communication [10].
Psychologist have described emotions in different perspectives.Some of the researchers believe that emotions are evolved while several others are of the opinion that emotions are socially constructed [11].Hybrid theory is also there according to which some emotions are evolved and some are socially constructed [11].Emotions, which are considered as, evolved sometimes also known as basic or primary [11].According to Paul Ekman there are big six emotions which can be categorized as basic emotions.These big six emotions are happiness, surprise, fear, sadness, disgust and anger [4].After few year enhanced list of basic emotions produced which includes amusement, contempt, contentment, embarrassment, excitement, guilt, pride, achievement, relief, satisfaction, pleasure and shame [12].
According to Izard C.E, basic emotions considered as a set of neural bodily expressive motivational components generated rapidly, automatically and unconsciously [13].Most of the researchers agrees on Paul Ekman's big six emotions [12].www.ijacsa.thesai.org

A. Text and Emotions
Text is not only the source to communicate information but also a useful resource to express emotions and its state [14].
Researchers takes text in different perspectives to analyze emotions.Different techniques have been developed and modified to articulate emotions from text [10].

B. Keyword Spotting Technique
A keyword spotting system, which takes text document as input and convert the text into tokens and after finding emotional words and their intensity [15].This system analyzes negation presence in the text input and gives emotion.It also involve emotional words ontology to match emotional keywords present in the text [15].
One of the main drawback of this technique is its incapability of emotion extraction in the absence of emotional keywords and lacking of articulating emotions based on context [16].This system only recognize negation state of emotion based on negation keyword but unable to identify the positive polarity of emotion from the text.

A multi-modal emotion extraction technique based on Paul
Ekman's big six emotions extracts emotions based on keyword spotting [17].Another feature emotional modification word, which is used to enhance emotional state.This system works on voice as well as text input.One of the major drawback of this system is lack of contextual information extraction.Generally, keyword spotting is very popular and naïve technique to extract emotions based on emotional keywords existence in the text [18].If there is no existence of emotional keywords then this technique fails to articulate emotion from text [19].For example, "My client filed a case in the court for the custody of his children".This sentence contains no emotional keyword but evoke strong emotion.Therefore, this cannot be articulated using keyword spotting.Another weakness of this technique is appearance of negation word in the input.For example "I am happy" evokes correct emotion and will be classified easily while "I am not happy" makes this technique fails to articulate emotion due to use of exact keyword with negation.

C. Lexical Affinity Technique
Another technique for emotion extraction problem is lexical affinity [15].This technique is much better than keyword spotting technique due to the extraction of exact emotional words based on probability "affinity" for specific emotion.For example, word "accident" shows negative emotional state as used for "died in road accident" or "happened a road accident".This technique uses corpus for probability analysis [20].
The major problem in this technique is word level emotion extraction [21].For example "He died in road accident and "I met him by accident" have same emotion due to word level execution of technique.Another drawback of this approach is the corpus, which is specific to particular domain.This makes corpus useless for other sources.Therefore, this is domain dependent corpus based technique.

D. Common Sense Knowledge Technique
This technique can be used to extract emotions from sentence even in the absence of emotional keywords [20].The technique uses large scale of common sense knowledge corpus containing large amount of world knowledge in different situations [22].Open Mind Common Sense (OMCS) is very famous corpus.This technique extracts the substring having common sense emotional state.Normally common sense knowledge is shown in the form of graph.In which nodes and edges represents real life concepts and their relationships respectively.Major drawback for this technique is lack of linguistic understanding of sentence [23].For example, "I will complete this task using this method" and "It will impossible to complete this task using this method" will be classified into same group due to poor linguistics understating of the system.This is quite better technique as compare to keyword spotting and lexical affinity but still unable to extract emotion based on context.

E. Machine Learning and text
Machine Learning (ML) involves the process of automatic and accurate predictions based on past observations [24].ML is very useful in different classification problems like text categorization, machine vision, spoken language understanding, bio informatics [25] , [26].It involves different algorithms Naïve Bayes (NB), Maximum Entropy (ME) and Support Vector Machine (SVM) for solving classification problems [27].Latest research especially in the field of text classification is based on Knowledge based (KB) approaches and ML approaches [28].KB approaches consist of linguistic models or prior knowledge to classify text while ML based approaches uses learning algorithms.ML techniques shows better results as compare to KB approaches.which combines headlines and blogs.Saif Muhammad provides a word-level emotional lexicon, which gives improved results at sentence level for articulation of emotions [29].Hurst & Nigam introduces a combination of ML and NLP techniques to find opinion about a given topic [30].It involves a corpus of data having all relevant and irrelevant sentence.Mullen & collier uses ML techniques to classify discussion forums on internet based on political statements [31].
Text classification involves lot of contribution from researchers using ML techniques this work also involves the use of ML technique to classify text input for automatic extraction of emotional sentiment.This also combines the use of NLP techniques and ML algorithm.

III. PROPOSED METHODOLOGY
Emotion extraction from text involves a lot from different researchers as discussed above.The proposed system takes textual input and articulate emotion in the form of negativity and positivity using ML technique.This system contains chat application as input module, which takes real time input from user, a pre-contextual analyzer, a context analyzer (CA) with Sentiwordnet lexicon database, emotion analyzer (EA), a history generator (HG) and a history response store (HRS).

F. Input Module
Interactive chat application developed to act as interface between user and system.This chat application takes text based input from user in English language and send it to precontextual analyzer for further processing.www.ijacsa.thesai.org

H. Text Tokenizer
Tokenizer divide English sentences into a sequence of tokens, which are known as "words".The system uses Stanford NLP group tokenizer and POS tagger for pre-contextual processing of text input.The Tokenizer divides the text into tokens and tagger is activated for tagging process.

I. POS Tagger
POS tagger takes tokens generated by Tokenizer and assign Part of Speech tag to each token such as verb, noun and pronoun [36].Stanford tagger is java based tagger support English, German, French, Chinese, Arabic languages.English language Stanford POS tagger uses the Penn Treebank tagset.Penn Treebank annotates text with POS tags.It is a lexicon containing different POS tags for English language.Consider the example tagged by POS tagger is as shown.
Example Sentence: I want to travel from Pakistan for studying purpose.

J. Context Analyzer
CA performs two important tasks.Firstly, the analyzer extracts the emotional sentiment of given tags by using EA module and secondly, operate HG module to generate context.

K. Emotion Analyzer
Emotions add importance to our daily communication whether it is verbal or non-verbal.If we capture customer's emotions electronically, it will convey opinion, mood of customer.Negative and Positive emotions contributes a lot in all field of life to judge opinion, mood and sentiments of other people whether conveyed through text or voice.
Emotion analysis from text is valuable for interactive environment and helps us to add intelligence in the form of emotion analyzer into our cognitive agent.Emotion analysis rates human emotional states according to positive or negative polarity [37].Text having emotions sometimes refers to subjective or objective.|Subjective text relates to positivity and negativity while objectivity of text refers to neutral form of emotion [38].
EA module will extract polarity of tagged token.For this purpose, analyzer will extract positive or negative emotion by identifying its weight from available lexicon Sentiwordnet.

L. Sentiwordnet 3.0
Sentiwordnet 3.0 is a lexical resource for supporting emotional sentiment classification [39].It automatically annotates all WordNet sysnsets according to the nature of subjectivity i-e positive or negative emotion and objectivity i-e neutral emotion.Each synset of Sentiwordnet contains subjectivity score and objectivity score to measure whether sentiment is positive, negative or neutral.EA module extracts positive or negative emotion by suing Sentiwordnet 3.0 [39] and transform it to CA module for further processing.

M. History Generator
HG is responsible for analyzing the context of the sentence.Stanford POS tagger tagged the tokens and extracts subjectivity

Stanford Text Tokenizer
Stanford POS Tagger TEXT INPUT www.ijacsa.thesai.orgscore as positive or negative by CA module.The next step involves the use of HG module, which search each tagged word, which contains token (word) and its POS| tag from HRS module.If a match doesn't found the token (word) with its POS tag the subjectivity score send for storing into HRS and if match found then same value extracted from store and send to CA module for further processing.
For Example, the HG module searches the tagged word "Happy NN" from HRS and if found mismatched the following entry will be placed into store to generate the context of the tag.
"Happy" + "n" + "2.1.1"In above statement "happy is token (word)."n" is prefix for POS tag and "2.1.1"is a code used to generate context for this word in the HRS.Same form of data returns when tagged word matched into store.The sequence "2.1.1"is the technique used to create context in the environment using HG module and HRS.The logic for context generation depends on the use of Baye's Algorithm.The system used this algorithm to implement the concept of learning for context generation.Baye's Algorithm relates current probability to prior probability.Baye's Algorithm is stated mathematically as Here A and B are even.

1) P(A) and P(B) are the probabilities of A and B and
2) P(AB), the conditional probability is the probability of A given that B is true.
Baye's Algorithm works on the basis of Probability of occurrence of any event based on certain conditions.For example, HRS contains the following entries.
"Happy" + "n" + "2.1.1""Sad" + "n" + "2.1.1""Happy" + "n" + "3.2.1" "Happy" + "n" + "4.3.1""Sad" + "n" + "3.1.2""Happy" + "n" + "5.4.1" "Sad" + "n" + "4.1.3" In the above given sequence of words the first value indicates the aggregate of second value (positive score) and third value (negative score).When even the same word occurs the HG module add the sequence into HRS after searching the occurrence of same word from store and add its subjective score (positive or negative) into previous extracted score and also update the aggregate value and store back into HRS.Baye's algorithm implemented to extract score based on probability of each extracted word.
The sequence of activities performed by CA module for generating and maintaining the context is as below:  The given token (word) with its POS tag is searched from Sentiwordnet 3.0 and then search for positive or negative emotion counting from each token.
 As per Bayes algorithm now prior probability of each token is calculated as Prior Positive= Positive Marked Counts / (Positive Marked Counts + Negative Marked Counts)  Next step is based on the calculation of Current probability of emotion and this could be achieved by searching the token (word) with its POS tag from HRS.
If search unsuccessful the system will add the token (word), Prefix of POS tag and a sequence number into HRS store as "happy" + "n: + "2. After finding prior probability and current probability of each token (word), the system will update the value of existing token (word) context into history response store.
 Finally, if multiplication results of prior positive and current positive is greater than the multiplication result of prior negative and current negative then the Positive emotion updated and shown otherwise negative emotion updated and shown.

IV. RESULTS AND DISCUSSION
Chat application is developed as input module to implement the proposed model.This chat application develops an environment to start dialogue between two clients.Clients can input text in the form of English sentences and the receiving end will display the same text with emotion as positive or negative and evaluate the sentence based on context.Above dialogue between teacher and student executed through proposed model and chat application shows the results below.The conversation clearly articulates emotional sentiment as positive and negative and also shows involvement of context in articulating emotion.Proposed system detects basic emotional words as well as analysis of non-emotional words.The system is also generating context through this application.
Let's test another case study.This is used to experiment the implementation of context in the proposed system.The following shows the table of sample sentences to proof the proposed model  To proof the model using above case study, following steps are analyzed.
A sentence is input through keyboard using chat application, Pre-contextual analyzer executes Tokenizer and POS Tagger modules to tokenize and tag the given text.Further two important modules executes.One module evaluates the tokens for positivity and negativity of the emotion from Sentiwordnet and returns value between 0 -1.HG module analyze the context generated by the system to find positivity and negativity of given token.The following shows the results generated through these modules where positive count and negative count column shows values generated by Sentiwordnet and current negative, current positive column shows the values returns by HR module to show the context.Results are evaluated at sentence level and it shows the value of each word used in the conversation.www.ijacsa.thesai.orgPrior Positive and Prior Negative values calculated by using following formula, which generates the result.
Current positive and current negative columns shows in TABLE V, the values generated by the system after analyzing the context of the conversation and these values are calculated based on following formula.
Positive history and negative history values are extracted from HRS module used to generate and store context of the conversation.The following table shows the word-by-word code return by HRS and the contextual values of each word w.r.t to positivity and negativity.

Fig. 1 .
Fig. 1.A Model of Keyword Spotting Technique ML techniques were used for articulation of basic emotions.It involves the heterogeneous annotated dataset for emotions Text Input Tokenize Identify Emotion Words Analysis of Intensity Negation Check Emotion www.ijacsa.thesai.org

Fig. 3 .
Fig. 3. Chat Simulator as Input Module G. Pre-Contextual Analyzer Pre-Contextual Analyzer contains two sub modules.(i) Text Tokenizer module (ii) Part of Speech (POS) tagger module.

1 . 1 " 6 )
and if found successful then return the same Current probability of each token (word) emotion calculation is based on the following formulas.Positive Score = Extracted from History Response Store.(4) Negative Score = Extracted from History Response store.(5) The above score is calculated for each token (word) avaialble in the sentence.Current Negative = Current Negative + (Positive Score + Negative Score) / Negative Score (Current Positive = Current Positive + (Positive Score + Negative Score) / Positive Score (7)

Few
case studies in the form of dialogue between two persons used to generate experimental results using chat application based on the proposed model Case Study 1: A dialogue between student and teacher. www.ijacsa.thesai.org

Fig. 6 .
Fig. 6.Teacher side chat application interface Case Study 2: Random sentences to proof the model

TABLE I .
FINDINGS OF RESEARCHERS IN THEIR RESPECTIVE RESEARCH PAPER

TABLE II .
SENTENCE AFTER POS TAGGING

TABLE III .
A SAMPLE DIALOUGE BETWEEN STUDENT AND TEACHER ON COMING LATE IN THE CLASS

TABLE IV .
A SAMPLE RANDOM SENTENCES TO PROOF THE MODEL

TABLE VI .
FOR WORD "AM"

TABLE VII .
FOR WORD "NOT"