Text-Based Emotion Recognition with ML

0% found this document useful (0 votes)
20 views7 pages
The document presents a study on text-based emotion recognition using machine learning and deep learning techniques, focusing on sentiment analysis through a web-based platform. The proposed model integrates natural language processing with machine learning algorithms, achieving a maximum accuracy of 63% with Logistic Regression. The research highlights the importance of emotion detection in various applications, including customer feedback and social media analysis, while also discussing future advancements in image-based emotion recognition.

Uploaded by

vickyjordan100
License
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tuijin Jishu/Journal of Propulsion Technology

ISSN: 1001-4055
Vol. 45 No. 2 (2024)
__________________________________________________________________________________

Text-based Emotion Recognition using


Machine Learning through Sentiment
Analysis
Alokam Meghana1, Bilakanti Vanshika2, Karnam VedaSamhitha3, Sreevidya B.4 and
Rajesh M.5
1, 2, 3
Department of Computer Science and Engineering, Amrita School of Computing,
Bengaluru, Amrita Vishwa Vidyapeetham, India
5,6 Department of Computer Science and Engineering, Amrita School of Computing,
Bengaluru, Amrita Vishwa Vidyapeetham, India
Abstract. This application explores the smooth integration of emotion detection features into a web page. It fol-
lows a dual-pronged approach by leveraging natural language processing (NLP) for textual data machine learning
models and deep learning models for analyzing the emotion in textual data. Powered by a flask backend, the
platform utilizes a natural language toolkit (NLTK) for sentiment analysis, enabling users to put their text for
customized emotion detection within an interactive web interface. This hybrid model provides a dynamic envi-
ronment that not only analyses user emotions but also reacts to them in real time by seamlessly integrating machine
learning and deep learning with web development. Its adaptability provides a sophisticated user experience. It
extends to a multitude of applications, starting from sentiment-aware recommendation systems to interactive en-
tertainment platforms. The effectiveness of the proposed model is verified by a comprehensive dataset consisting
of text labeled with various emotions that are used to train and assess the suggested emotion detection algorithm.
Quantitative results demonstrate that the Logistic Regression -based proposed model outperforms competing
methods by accurately identifying and classifying emotions in textual data. The best suited model in all the ML
algorithms and Deep Learning is Logistic Regression i.e 63%
Keywords: Sentiment Analysis, NLTK, GANs, CNN, Emotions, Text data, Classification Models, Naïve Bayes,
Logistic Regression, Machine Learning, FNN, RNN.

1 Introduction
You will find In the current world Text-based emotion recognition is important due to the huge volume of digital
communication, like in need for effective customer feedback, computer- human interaction, and in media. social
media platform is the place where many people express their emotions publicly, analyzing these emotions in social
media posts allows researchers, businesses and to respond to the issues effectively. Many organizations and gov-
ernments can benefit from text-based emotion recognition, for analyzing public opinion on various issues, mainly
for politics, social trends, and public policies. Emotion recognition helps to develop many personalized services
and applications, like chatbots or virtual assistants they can understand us respond to users and create more natural
and engaging interaction.
Sentiment analysis is also called opinion mining, it is a natural language processing (NLP) technique that deter-
mines and analyses the sentiment, or the emotion expressed in the text. the main objective of this sentiment anal-
ysis is to identify and categorize the sentiment given by the author whether the the given text is positive, negative,
or neutral. Frequently used to gather information on public opinion and sentiments from user reviews, social media
posts, customer feedback, and other textual communication formats. The main goal Is to not only identify if the
sentiment is negative, neutral, or positive but also identify more specific features such as expressions of joy,
sadness, fear, anger, and other emotions through the use of computer algorithms.
Pictures these days are like emotionally charged messages in the digital era. Images play a major role in conveying
emotions, whether they are used in advertisements or social media posts. To implement this work, it is important
to investigate text-Based Emotion Recognition, with a particular focus on applying sentiment analysis and ma-
chine learning techniques. The aim is to simplify the emotions concealed in pictures so that we may better

6920
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 2 (2024)
__________________________________________________________________________________

comprehend the visual language of emotions. Consider all the images we view on the internet; they resemble a
vast assemblage of feelings just begging to be deciphered. We aim to apply sentiment analysis to images in the
same way that it is used to analyze text for emotions. This research explores machine learning for text-based
emotion recognition. We want to delve further into the more nuanced emotions, such as happiness, sadness, rage,
and more, rather than just identifying the fundamental ones like happy or sad. As we proceed, we will review
the findings of other knowledgeable researchers, examine the approaches they have employed, and propose our
approach to machine learning for image- based emotion recognition. The purpose of this post is to provide some
insightful information about how machine learning, in particular sentiment analysis, might aid in our understand-
ing of the emotions depicted in images. Let's investigate how machine learning for emotion recognition in photo-
graphs can be applied in practical scenarios. Applications on image-based sentiment analysis: Monitoring of
Driver Emotion in the Automotive Industry, Entertainment, Healthcare, Determine Pain Level Advertising &
Marketing.
We discussed the system's broad structure and key components in Section 3 along with our planning and design
process. After that, we covered the techniques and technologies we employed in Section 4 to go into more detail
about how we implemented the system. Section 5 presents a detailed analysis of the obtained results and provides
insights into the system's performance. A summary of our findings, their significance, and potential next steps are
provided in Section 6, which also serves as a conclusion. In Section 2, we referred papers deeply into the work of
other scholars in this field and situating our findings within the body of current knowledge.
1. Related Work
In recent research, a plethora of studies have delved into text-based emotion recognition using machine learning
algorithms, with applications ranging from mental health tracking to social media analysis. Midhan et al.[1] ad-
dress the concern of depression by evaluating ML algorithms for emotion classification in English text, empha-
sizing implications for mental health tracking systems. Chavan et al.[2] conduct a survey exploring the application
of machine learning and deep learning in emotion detection from text, focusing on challenges in accurately de-
picting human emotions without audio or facial features. Their insights guide future research efforts, aiming to
enhance emotion classification for text [Link] studies, such as Jain et al.[3] and Tleubayeva et al.[4],
leverage advanced models like BERT and Roberta for precise emotion detection in various contexts, including
social media and surveys. Lathish et al.[6] compare the performance of SVM and KNN in text classification for
emotion recognition, revealing SVM's superior accuracy. Julian et al.[7] specifically focus on emotion detection
in tweets, finding Support Vector Machine to be particularly effective. Mahima et al.[8] introduce a hybrid ap-
proach for multiple emotion detection, outperforming traditional sentiment analysis. Furthermore, Andry et al.[9]
achieve optimal results in text-based emotion recognition on social media using diverse machine learning tech-
niques. These studies collectively contribute to the growing field of text-based emotion recognition, showcasing
the versatility and efficacy of machine learning in understanding and categorizing emotions from textual data.
In a diverse array of studies exploring text-based emotion detection, Cecilia et al. [10] employ supervised machine
learning with the SNoW architecture to predict emotions from children's fairy tales, aiming for expressive text-
to- speech synthesis. Rajkumar et al.[11] delve into emotion detection from Twitter data, utilizing supervised
learning techniques like K-means, Naive Bayes, and SVM, transforming emotions into an eight-category vector.
E. C. C. Kao et al.[12] conduct a comprehensive survey categorizing text-based emotion detection methods into
keyword-based, learning-based, and hybrid recommendation approaches, proposing solutions for practical en-
hancement in human-computer interactions. Zahid et al.[13] focus on identifying dominant emotions in email text
using machine learning, achieving an average accuracy of 83% with three classifiers and feature selection meth-
ods. Additionally, Alaa et al.[14] review machine learning techniques for emotion detection and sentiment analy-
sis, highlighting SVM and Naïve Bayes as popular algorithms. Lastly, Fatma et al.[15] present a novel system,
PERS, integrating social media and machine learning for personality and emotion recognition, achieving high
accuracy in personality detection and emotion recognition, with applications including identifying individuals at
risk based on social media content. These studies collectively contribute to the evolving landscape of text-based
emotion recognition, showcasing advancements in diverse domains and methodologies. These studies aim to

6921
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 2 (2024)
__________________________________________________________________________________

advance the subject of recognizing emotions from text by showcasing advancements in multiple domains and
using a variety of approaches..
2 System Design

Fig. 1. Block Diagram


The Fig 1 shows the block diagram of the proposed system design.
Data Loading: The data was loaded and explored using pandas. We examined the shape, data types, and
distribution of emotions in the dataset.
Text Preprocessing: Applied various text preprocessing techniques, such as stop word removal, punctuation
removal, and extraction of the most common words for each emotion.
Feature Extraction: Used CountVectorizer to convert the cleaned text into numerical features that can be used
for machine learning.
Model Training: Trained different machine learning models, including Naive Bayes, Logistic Regression, and
Support Vector Machines on the training dataset.
Model Evaluation: Evaluated the models using accuracy, confusion matrix, and classification report.
Interpretation of the model was performed using eli5.
Model Deployment: The final trained model was saved for future use.
Predict Results: The naive Bayes model achieved an accuracy of 0.56, whereas the Logistic Regression model
achieved a better accuracy of 0.63.

Fig. 2. Probability of success of different emotions

6922
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 2 (2024)
__________________________________________________________________________________

3 Implementation
Implementation starts by gathering this data from a MongoDB database, assuming the presence of infor-
mation related to both the text itself and the associated emotions. The script then gets the data ready for analysis
by converting it into a structured format using Pandas. Next, it cleans up the text by making it all lowercase and
removing any characters that aren't letters or numbers. This ensures a uniform format for the text data. The dataset
is then divided into two parts: one for training the model and the other for testing its accuracy. To understand the
text better, the script converts it into numerical form using a technique called Count Vectorization. This essentially
transforms words into numbers that a machine learning model can understand. Instead of using Naïve bayes to
understand the text, it switches to another technique called Logistic Regression. This change might affect how
accurately the model interprets emotions from the text. Finally, after training the model on the training data, it
evaluates the model's performance using the testing data. It calculates how accurately the model predicts emotions
in the text and provides a detailed report summarizing its effectiveness. Coming to deep learning models Each
model underwent similar preprocessing steps to prepare the textual data and corresponding emotion labels. While
the CNN focused on spatial patterns within the text, the FNN relied on traditional neural network layers to learn
intricate relationships, and the RNN specifically targeted sequential data, retaining memory to capture contextual
information. The Probability of success of different emotions is given in Fig 2.
4 Result
This study utilizes machine learning models and deep learning models to classify emotions in textual
data using a dataset consisting of text categorized into eight different emotion labels: neutral, joy, sadness, fear,
surprise, anger, shame, disguist The primary machine learning classifiers evaluated are the Multinomial Naive
Bayes and Logistic Regression models. During testing, the Multinomial Naive Bayes classifier achieved 57%
accuracy, whereas the Logistic Regression model achieved 63% accuracy. The primary deep learning models
evaluated are CNN, RNN and FNN. During testing the CNN achieved 54.19% accuracy, FNN achieved 54.63%
while RNN has achieved 56.03% accuracy. Those are depicted in following Fig 3 to Fig 7
The machine learning models have performed better than deep learning model and have attained more
[Link] key aspect of this work revolves around the interpretability of the Logistic Regression model, it is
highlighted through the presentation of feature weights. The visualization of the results provides valuable insights
into the importance of every word in classifying the emotions from the [Link] dataset used in this work has a
important role, containing annotated texts with one of the thirteen specified emotions. It serves as both the training
and evaluation foundation for the emotion classification [Link] results demonstrate the significance of the
chosen classifiers and emphasize the interpretability of the Logistic Regression model. This offers a comprehen-
sive overview of the performance in this emotion classification task.
MACHINE LEARNING

Fig. 3 Naïve Bayes

6923
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 2 (2024)
__________________________________________________________________________________

Fig. 4. Logistic Regression

DEEP LEARNING

Fig.5 CNN Model

Fig.6 FNN Model

Fig.7 RNN Model

5 Conclusion
The data set is classified into 8 categories so the accuracy will be a bit less than binary classification, when com-
pared to all classifiers Logistic Regression model achieves an accuracy of 0.63%. In deep learning models the
best accuracy is in RNN model which is very much lesser than the Machine learning model. As we explore the
future of image analysis, the convergence of deep learning advancements, particularly in convolutional neural
networks (CNNs), holds promise for more accurate and efficient visual data extraction. The integration of multiple

6924
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 2 (2024)
__________________________________________________________________________________

modalities, such as text and image analysis, is a key trend, enhancing contextual understanding. Future achieve-
ments include the continual improvement of model interpretability, real-time analysis at the edge, and the respon-
sible deployment of image analysis technologies. Expectations also include the evolution of Generative Ad-
versarial Networks (GANs) for realistic image synthesis and increased automation in anomaly detection. Image
analysis is poised to contribute significantly to environmental monitoring, sustainability efforts, and the seamless
integration of augmented and virtual reality experiences. Considering image analysis in the future, a few predicted
developments come to mind. First, improvements in multimodal analysis—which merges multiple sources, in-
cluding text and images—are anticipated to enhance contextual knowledge. It is anticipated that interpretation
and explanation will play a larger role in image analysis models going forward, addressing issues of trust and
transparency. Real-time analysis at the edge, where models are installed closer to data sources to increase effi-
ciency and decrease latency, is another expected development.
Generative Adversarial Networks (GANs) are poised to play a crucial role in realistic image synthesis, contrib-
uting to applications in various fields. The responsible and ethical use of image analysis technologies, including
considerations for bias and privacy, is becoming increasingly important. Automation in anomaly detection, espe-
cially in domains like manufacturing and healthcare, is expected to advance, streamlining quality control pro-
cesses. Lastly, image analysis is set to contribute significantly to environmental monitoring and sustainability
efforts
6 References

[1] T. Madhu Midhan, P. Selvaraj, M. Harshavardan Kumar Raju., M. Bhanu Prakash Reddy. and T. Bhaskar.,
"Classification of Mental Health and Emotion of Human from Text using Machine Learning Approaches,"
2023 6th International Conference on Information Systems and Computer Networks (ISCON), Mathura,
India, 2023.

[2] D. Chavan, E. Anvekar, M. Dandapat, V. Bichave and J. Jagdale, "Machine Learning Applied in Emotion
Classification: A Survey on Dataset, Techniques, and Trends for Text Based Documents," 2023 9th Interna-
tional Conference on Advanced Computing and Communication Systems (ICACCS), Coimbatore, India,
2023.

[3] G. Jain, S. Verma, H. Gupta, S. Jindal, M. Rawat and K. Kumar, "Machine Learning Algorithm Based Emo-
tion Detection System," 2022 Fifth International Conference on Computational Intelligence and Communi-
cation Technologies (CCICT), Sonepat, India, 2022.

[4] A. Tleubayeva, A. Shaikhanova, B. Ospan, A. Sultan, M. Abu and N. Darmenkyzy, "Machine Learning Ex-
pert System for Recognizing Emotions in text “Umai Cloud Services”," 2023 IEEE International Conference
on Smart Information Systems and Technologies (SIST), Astana, Kazakhstan, 2023.

[5] Saravanakumar, S., & Thangaraj, P. (2019). A computer aided diagnosis system for identifying Alzheimer’s
from MRI scan using improved Adaboost. Journal of medical systems, 43(3), 76.

[6] Kumaresan, T., Saravanakumar, S., & Balamurugan, R. (2019). Visual and textual features based email spam
classification using S-Cuckoo search and hybrid kernel support vector machine. Cluster Computing,
22(Suppl 1), 33-46.

[7] Saravanakumar, S., & Saravanan, T. (2023). Secure personal authentication in fog devices via multimodal
rank‐level fusion. Concurrency and Computation: Practice and Experience, 35(10), e7673.

[8] Thangavel, S., & Selvaraj, S. (2023). Machine Learning Model and Cuckoo Search in a modular system to
identify Alzheimer’s disease from MRI scan images. Computer Methods in Biomechanics and Biomedical
Engineering: Imaging & Visualization, 11(5), 1753-1761.

[9] Saravanakumar, S. (2020). Certain analysis of authentic user behavioral and opinion pattern mining using
classification techniques. Solid State Technology, 63(6), 9220-9234.

6925
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 2 (2024)
__________________________________________________________________________________

[10] R.R. Malagi, Y.R,S. P. T. K, A. Kodipalli, T. Rao and R. B. R, "Emotion Detection from Textual Data Using
Supervised Machine Learning Models," 2023 4th International Conference for Emerging Technology
(INCET), Belgaum, India, 2023.

[11] A. Lathish and T. Devi, "Comparison of Support Vector Machine and K-Nearest Neighbour Algorithm for
Accurate text Classification," 2022 4th International Conference on Inventive Research in Computing Ap-
plications (ICIRCA), Coimbatore, India, 2022.

[12] C. R. Julian, G. R. Athevan, N. G. Hanjaya, H. Lucky and D. Suhartono, "Utilizing Machine Learning Al-
gorithms to Detect Emotions from Tweets," 2022 9th International Conference on Advanced Informatics:
Concepts, Theory and Applications (ICAICTA), Tokoname, Japan, 2022.

[13] M. A. Mahima, N. C. Patel, S. Ravichandran, N. Aishwarya and S. Maradithaya, "A Text-Based Hybrid
Approach for Multiple Emotion Detection Using Contextual and Semantic Analysis," 2021 International
Conference on Innovative Computing, Intelligent Communication and Smart Electrical Systems (ICSES),
Chennai, India, 2021.

[14] Chowanda, A., Sutoyo, R. and Tanachutiwat, S., “Exploring text- based emotions recognition machine learn-
ing techniques on social media conversation”, Procedia Computer Science, 179, pp.821-828, 2021.

[15] Alm, C.O., Roth, D. and Sproat, R., “Emotions from text: machine learning for text-based emotion predic-
tion. In Proceedings of human language technology conference and conference on empirical methods in
natural language processing pp. 579-586, 2005.

[16] Salam, S.A. and Gupta, R., “Emotion detection and recognition from text using machine learning”, Int. J.
Comput. Sci. Eng., Vol. 6, No. 6, pp.341-345, 2018.

[17] Kao, E.C.C., Liu, C.C., Yang, T.H., Hsieh, C.T. and Soo, V.W., “Towards text-based emotion detection a
survey and possible improvements”, 2009 International conference on information management and engi-
neering, pp. 70-74, 2009.

[18] Halim, Z., Waqar, M. and Tahir, M., “A machine learning-based investigation utilizing the in-text features
for the identification of dominant emotion in an email”, Knowledge-based systems, Vol. 208, 2020.

[19] Alslaity, A. and Orji, R., “Machine learning techniques for emotion detection and sentiment analysis: current
state, challenges, and future directions”, Behaviour & Information Technology, pp.1-26, 2022.

[20] Talaat, F.M., El-Gendy, E.M., Saafan, M.M. and Gamel, S.A., “Utilizing social media and machine learning
for personality and emotion recognition using PERS”, Neural Computing and Applications, Vol. 35, No. 33,
pp.23927-23941, 2023.

6926

Common questions

Powered by AI

Text-based emotion recognition primarily uses machine learning (ML) and natural language processing (NLP) techniques. Techniques like sentiment analysis are employed, where textual data is analyzed to detect underlying emotions. ML models such as Logistic Regression, Naive Bayes, and Support Vector Machines play a key role by classifying text into predefined emotion categories based on learned patterns from a trained dataset. These methods enhance detection by leveraging the power of computational algorithms to identify nuanced emotions, which helps in applications ranging from customer feedback analysis to mental health evaluation .

Text-based emotion recognition offers a broad range of applications, including customer feedback analysis, social media monitoring, and enhancing human-computer interaction. It facilitates the development of personalized services like sentiment-aware recommendation systems and chatbots that can engage users naturally. Moreover, it aids organizations in analyzing public opinion trends, particularly in political and social contexts, contributing to strategic decision-making. These applications highlight the utility of emotion recognition in adapting to user needs and enhancing interaction quality .

Logistic Regression is identified as the most effective model for emotion classification in textual data, achieving an accuracy of 63%. This surpasses the performance of other machine learning models like Naive Bayes which reached 56% accuracy and Support Vector Machines, known for their effectiveness but not quantified in the document. The superiority of Logistic Regression is evident through its higher accuracy rate, which highlights its capability in discerning emotions more accurately within the given dataset .

Deep learning models, such as CNN, RNN, and FNN, diverge from traditional machine learning models by focusing on hierarchical and more complex data patterns. Deep learning models like RNN can capture sequential dependencies and contextual information in text data better than traditional models. However, the document reveals that in this specific emotion recognition task, deep learning models (e.g., RNN achieving 56.03% accuracy) underperformed compared to machine learning models like Logistic Regression, which achieved 63% accuracy. This underperformance might be attributed to the complexity or inadequacies in dataset size and diversity, which favors traditional methods in this instance .

The document underscores the interpretability of machine learning models as a critical factor in emotion recognition. Logistic Regression, specifically, is highlighted for its interpretability, offering insights into the significance of individual features (words) in emotion classification. This ability is crucial for understanding model decisions and improving transparency. While deep learning models like CNNs possess superior pattern recognition capabilities, their complex architectures often result in reduced interpretability compared to simpler models like Logistic Regression. This trade-off between accuracy and interpretability is pivotal in selecting appropriate models for practical applications .

The quality of the dataset is pivotal in text-based emotion recognition as it establishes the foundation for model training and evaluation. A comprehensive dataset provides varied and representative text samples, annotated with distinct emotion labels, allowing models to learn nuanced emotional expressions effectively. The effectiveness of the recognition models, such as Logistic Regression achieving 63% accuracy, largely depends on the diversity and quality of the training data. High-quality datasets ensure that models have adequate training material to handle different contexts and improve their prediction capabilities .

Integrating NLP and machine learning in emotion recognition systems is crucial as it combines the strengths of natural language understanding and computational analysis. NLP techniques parse and process textual data to extract meaningful patterns and features, which machine learning models then use to classify emotions. This integration allows for dynamic interaction with user emotions in real-time web applications, enhancing personalization. Such systems can learn from evolving datasets, improving sentiment detection accuracy over time. This comprehensive approach extends applications across domains like sentiment-aware recommendation systems, enhancing virtual assistants, and analyzing social media trends effectively .

Detecting human emotions from text alone presents several challenges, primarily due to the lack of non-verbal cues such as tone and facial expressions that are crucial for interpreting emotions accurately. The complexity of human language, including nuances like sarcasm or irony, further complicates detection. Additionally, textual data requires sophisticated preprocessing to handle variations in language use, syntax, and sentiment expression. These challenges necessitate advanced techniques in machine learning and NLP, such as deep learning models that can infer context and sequential patterns to improve accuracy, although current models still struggle with these complexities .

The document predicts that future developments in image analysis will involve improvements in multimodal analysis, enhanced real-time analysis at the edge, and advancements in Generative Adversarial Networks (GANs). These developments are expected to boost efficiency and contextual understanding, offering more accurate data interpretation and synthesis. These improvements can significantly impact emotion recognition systems by enabling more comprehensive and real-time analysis through the integration of visual and textual data, thus enhancing the accuracy and reliability of recognizing emotions across complex datasets .

Different machine learning models handle text preprocessing through standardized methods such as lowercasing text, punctuation removal, and stop word removal. These steps ensure uniformity and clarity in the data fed into the models. Techniques like CountVectorization are used to convert text into numerical representations suitable for machine learning algorithms. Although these preprocessing methods are model-agnostic in nature, the simplicity or complexity of preprocessing can vary depending on the model's requirements and its ability to handle raw textual input effectively. For instance, deep learning models might employ more advanced preprocessing like embedding layers to capture contextual nuances .

You might also like