Emotional sentiment analysis of social media content for mental health safety

Text sentiment analysis is mostly used for the assessment of the author’s mood depending on the context. The purpose of sentiment analysis is to discover the exactness of the underlying emotion in a given situation. It has been applied to various fields, including stock market predictions, social media data on product evaluations, psychology, the judiciary, forecasting, illness prediction, agriculture, and more. Many researchers have worked on these topics and generated important insights. These outcomes are useful in the field because they (outcomes) help people comprehend the general summary quickly. Additionally, sentiment analysis aids in limiting the harmful effects of some posts on various social media sites such as Facebook and Twitter. For these reasons and more, we are proposing an approach to filter the social media content that could be emotionally harmful to the user, through getting the social networks content; for that, we have used Twitter API to get the user posts, and then, we have used API natural understanding language API tool to extract and classify the emotions of the Twitter content into five basic emotional categories—Joy, sadness, anger, fear, disgust—into an array of emotions; after that, we have defined a perfect emotion array from over 450 words from the English language. The main purpose of this comprehensive research article is to examine the proposed solution that we have conducted to improve the quality of content displayed to users emotionally.


Introduction
Excessive use of social media has created imbalances in people's mental health and has become a major problem for this generation, scientists, and society (Boivin et al. 1995). This excessive use of social media is one of the most popular hobbies of today's generation. Social media can be in any form of website and application, from chat platforms like Facebook and Instagram, to online gaming and virtual worlds like YouTube and Reddit. These modern sites are expanding rapidly and serving as accessible gateways for communication and enjoyment for the young population. Virtual social media platforms such as Facebook, Twitter, and others have greatly enhanced the virtual environment over the last decade by allowing users to share their thoughts, ideas, personal information, images and videos at an unprecedented rate (Chou et al. 2011). Moreover, as the number of daily users is increasing, social media users have quickly accepted online social communication as an integral element of daily life (Davila et al. 2012). In fact, since 2015, Facebook has counted an estimated 1 billion active members. This implies that one in seven individuals on the planet is using Facebook at least once in a single day. As a result, social media has a significant impact on several elements of modern digital life, including marketing, politics, education, health, and fundamental human connection. Even though the social media phenomenon is still relatively young, some empirical studies have analyzed the overall impact of frequent usage of social media on well-being and users' mental health. This lack of awareness is particularly concerning in the context of today's younger generation, as teenagers and young people spend a significant amount of time online socializing and so are at a higher risk of harmful consequences. Some studies have identified a link between social media use and negative consequences such as increased anxiety (Deters and Mehl 2012), stress (Dick 2013), depression (Drouin et al. 2012), loneliness (Davila et al. 2012), and eating disorders. This usage of social media by the younger generation generates major concerns about its negative consequences. For these reasons and more, we are proposing an approach to filter the social media content that could be emotionally harmful to the user, by getting the social media content; for that, we have used Twitter API to get the user posts, then we have used API natural understanding language API tool to extract and classify the emotions of the Twitter content into five basic emotional categories-Joy, sadness, anger, fear, disgust-into an array of emotions, and after that, we defined a perfect emotion array from 450 words from the English language. Then, we calculate the Euclidean distance (similarity distance) between the emotions array of each tweet content and the perfect emotions array; after that, we define a value called the threshold which will be 1.08; if the distance is equal to or less than the threshold, it is ok to display, otherwise display a warning message that the content could be emotionally harmful. This paper is organized as follows: Section 2 describes the related works and some previous research, Sect. 3 gives an overview of the proposed approach, and in Sect. 4, we discuss some results. Finally, Sect. 5 concludes the paper and outlines some future work. For all of these reasons, we are proposing an approach to filter the social media content that might be emotionally harmful to the user, To do this, we first obtained Twitter user posts by using Twitter API, then we have used IBM natural language understanding API to extract and classify the emotions of the Twitter content into five basic emotional categories-Joy, sadness, anger, fear, disgust-into an array of emotions, moreover, we defined a perfect emotion array from 450 words from the English language.

Literature review
In this section, we explore original research on the topic of emotion detection using artificial intelligence filters. In emotion detection, researchers have proposed many emotion models to understand emotions and the expressions behind emotions. Therefore, emotion models play an important role in text-based emotion detection on social media platforms. There have been several general approaches developed in the last 10 years regarding textbased emotion detection, we can list some of these attempts as follows: Boivin et al. (1995) explained the keyword-based emotion recognition approach. Each sentence is considered as a combination of content words or Emotional Function words (EFW). They can take three forms: emotional keywords, modifiers, and metaphors. Emotion keywords can take six emotion labels from Ekman's emotion model and assign specific weights. Chou et al. (2011) presented an emotion classification system for tweets in the English language. Initially, text preprocessing has performed using word and sentence tokenization, stemming, lowercasing, and POS-tagging. Next, feature extraction is accomplished using n-gram features, lexicon features, and various semantic and syntactic features. Then, to solve the multi-class multi-label problem, a set of eleven binary classifiers was created for each possible emotion class, anger, anticipation, disgust, trust, fear, love, joy, pessimism, optimism, surprise, and sadness where each model gets the previous models' predictions as supplementary features to create a multi-label representation of the predictions. Davila et al. (2012), Deters and Mehl (2012), Dick (2013) and Drouin et al. (2012) studied deep Learning-based approach; deep learning is a variant of machine learning in artificial intelligence with networks capable of unsupervised learning from unstructured or unlabeled data. This approach allows neural networks to learn complex concepts by constructing them from simpler concepts. Initial preprocessing was performed on the data set. After that, the embedding layer is built, where tokens are represented in the form of numbers. Then, depending on the number of emotion labels, these feature vectors are input into one or more Deep Neural Network layers. Patterns are learned from data and used to predict the labels by using classification. Souri et al. (2018) proposed a deep learning system, for challenges with multi-label emotion identification problems, microblogging, preprocessing, they used the Ekphrasis tool. Word normalization, tokenization, spell correction, and segmentation are all performed by Ekphrasis. GloVe, a pre-trained word embedding algorithm, was used. The features from the embedding layer are provided to two Bidirectional-Gated recurrent unit layers. Then, the output of the first Bi-GRU layer is given to the first attention layer. The output combined from the first and second Bi-GRU and embedding layer is given to the second attention layer. Then, combined two attention layers are provided to a DNN with a sigmoid activation function for classification. The authors used 11 emotion categories to classify emotions: anger, anticipation, disgust, trust, fear, love, joy, pessimism, optimism, surprise, and sadness. Neural network model as a solution to filter negative emotion on social media platforms: In the neural models, unique words are utilized as the input in the parse trees which provide the synthetic data and semantic data. Hence, emotion composition is derived from the best. Recurrent neural networks and convolution neural networks are becoming more popular, and they do not require parse trees to split their features from the given sentences. Instead, recurrent neural networks and convolution neural networks (CNNs) use word embedding as inputs that already inscribes the semantic and synthetic data. Additionally, the architecture of the convolution neural networks and recurrent neural networks helps in learning the connectivity between the words in a statement (Morente-Molinera et al. 2019). The recursive automatic coding network (RAN) in the semi-supervised model for the sentence-level, sentiment analysis provided a lowdimensional vector representation. Risch and Krestel (2018) proposed a new matrix-vector recursive neural network (MVRNN), each context is also associated with a tree representation of the matrix (Subramani et al. 2018). The structure of the tree is derived from the parser that is used externally. It describes a collaboration between the Recurrent Neural Network (RNN) and CNN architecture for sentiment classification from the short context that are privileged in the coarse-grained features generated by a CNN (Subramani et al. 2019). An approach based on the linguistics LSTM for effective sentiment prediction incorporates the sentiment lexicon as both a highly intensive context and negative context. In Abualigah et al. (2021), the LSTM includes these features during analyzing the sentiment to provide a useful view of the context. Authors have presented a traditional CNN/LSTM model which consists of two sections-local CNN and LSTM-to predict the attitude illustrated. Z Mo, E Sam -Journal of Student Academic Research, 2021, used biometric data to detect the emotional state of social media users as the first step toward early anxiety detection and intervention card against anxiety. Abualigah (2019) presented a personality classification model by analyzing user activities on Facebook using machine learning. The proposed method uses Facebook API to collect the data from 100 users. The proposed method also can recommend friends in Facebook groups. As many researchers reported on sentiment analysis (Ahmed and Abdelhamid 2022; Shaha and Amal 2022; Mountaga et al. 2021;LEUNG 2009), Ahmad et al. (2019) leveraged a sentiment analysis technique to address group decision-making using social media. The proposed method helps experts to generate preference relations which may be applied to group decision-making. Budiharto and Meiliana (2018) proposed a deep learning-based model to identify the aggregation of user-generated content in social media. The proposed method uses a recurrent neural network based on a bidirectional gated recurrent unit. They used a machine-translated to augment a dataset used for model training. Prabhu et al. (2019) proposed a domestic violence identification system using deep learning. The proposed system uses a dataset collected from Facebook. The proposed system uses a binary text classification approach that can detect if the content created by a user is recognized as critical or uncritical. Cury (2019) also presented a deep learning-based domestic violence identification system. Unlike their previous work (Drouin et al. 2012), this system can be applied for a multi-class post categorization including five categories, namely general, empathy, awareness, personal story, and fundraising. The proposed system was evaluated using a dataset collected from Facebook users' generated content and achieved a high accuracy rate. Al Shehhi et al. (2019) used a deep learning model with a sentiment analysis technique to classify user-generated content on Twitter (tweets) as a binary classification (extremist tweets or non-extremist tweets). In their work, Subramani et al. (2019) used sentiment analysis techniques to predict the result of the Indonesian presidential election. The prediction of the proposed method was correct according to the result of the Indonesian presidential election. Pong-inwong and Songpan (2018) used sentiment analysis techniques to analyze tweets collected from Twitter users in the United Arab Emirates (UAE) to measure happiness. They used tweets in English and Arabic. They found that 7:00 am is the happiest hour and Friday is the happiest day. In Aloufi and Saddik (2018), the authors proposed a sentiment analysis system that can be applied to analyze posts in the teaching evaluation system. The proposed system collects student feedback and analyzes sentiment analysis phrases to obtain the classification of teaching attitude. Arias et al. (2013) proposed a sentiment analysis approach to analyze football fans' sentiments through tweets posted by them and their reaction to game events (i.e., penalty kicks, scoring goals, etc.). The proposed approach can conclude fan interaction through football game events. Jansen et al. (2009) proposed a toxic detection model based on a convolutional neural network (CNN), bidirectional gated recurrent units (GRU), and bidirectional long short-term memory (LSTM). They used the Wikipedia dataset to evaluate the proposed method and achieved an F1 score of 87.2% for predicting toxicity types and 82.2% for the toxic/non-toxicclassification. In Abualigah et al. (2021), the authors presented a personal attack analysis method based on a combination of machine learning and crowdsourcing. In Abualigah et al. (2021), the authors proposed a deep learning-based approach to classify toxic comments. They used Kaggle data to test their approach. Sentic computing, a sentiment analysis paradigm that makes use of AI and Semantic Web approaches, has been presented by the authors in Ji et al. (2022) to improve the recognition and interpretation of sentiment in natural language processing. A chained-fusion approach is provided to jointly learn face dynamics and appearance in Ansari et al. (2022) authors' proposal. They have demonstrated how such sequential fusion might offer a probabilistic perspective on the model complementarity and correlation between two various data modalities for improved depression recognition. The authors of  have suggested using relation networks to identify mental illnesses and suicidal tendencies along with associated risk markers. In , authors employed two sets of methods-hybrid and ensemble-to early diagnosis depression. The results indicated that numerous feature combinations and careful feature selection can lead to higher performance, and  provides a survey of the techniques currently utilized to identify depression and its shortcomings. A model that makes sense has been put forth by the authors of  for identifying depression on Twitter. It includes a unique encoder that combines feed-forward neural networks with hierarchical attention methods. Google and Jigsaw presented an API (Perspective API, https:// www. persp ectiv eapi. com/ (accessed on 10 February 2021)) for classifying toxic comments. However, this API handles a simple binary text. Moreover, another study addressed the classification of toxic comments presented by Ringsquandl and Petkovic (2013). This study also used a simple binary text classification to test the proposed model.

Methodology
In this section, we will describe our proposed solution and examine what we have conducted to improve the quality of content displayed to the user emotionally through getting the content of the social networks; for this, we have used the Twitter API to get the user posts, analyzing and classifying the content into five basic emotional categories: Joy, sadness, anger, fear, disgust. For this, we have used IBM understanding language API tool, an online open source API for textual emotion recognition; after that, we output the dataset into an array of emotions; then, we have defined a perfect emotion array extracted from 450 words from English language; then, we calculate the Euclidean distance (similarity distance ) between the emotions array of each tweet content and the perfect emotions array; after that, we define a value called the threshold which will be (1.08); if the distance is equal or less than the threshold, it is ok to display, otherwise display a warning message that the content could be emotionally harmful.

Data preprocessing
For the first step of building our application, we needed data from social media, so we used the Twitter API "tweets" to get all the data that we needed to proceed with the analysis; then, to analyze and classify content into five basic emotion categories: Joy anger disgust sadness and fear, we used IBM natural language understanding API (Komal and Joshi 2016).

IBM natural language understanding API tool
IBM API tool is used to analyze various features of text content at scale. Provide text, raw HTML, or a public URL and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content. With Natural Language Understanding, we can do a full emotional analysis which includes a set of text analytics features that you can use to extract meaning from unstructured data (Komal and Joshi 2016).

Sentiment analysis of tweet content
To perform a sentiment analysis on the dataset (tweets) we got from the Twitter API, we have used IBM natural language understanding Api to extract the emotions from about 450 words from the English language that people usually use to express positive emotions with every tweet presented as an emotion array X[i, j] for further analysis. After getting data of every tweet is presented in form of an array of emotions X[i, j] from the IBM natural language understanding Api, the content will be analyzed in the next step.

Emotion analysis of tweet content
For this step and in order to filter content, emotionally we have collected more than 450 words that people usually use to express positive emotions in English language. Then, we have analyzed them using the IBM API, the output that we got is going to be defined as the perfect emotions array, and its values are as next: We defined a perfect emotion array as a matrix Y, where Y is a m * n matrix, where each row represents a sample and each column represents the 5 emotions, respectively.

Evaluation of emotion
In order to classify the emotion array we got from our given tweet in the dataset, we will compute the Euclidean distance between every tweet in the dataset array X [i, j] from the tweet data content and the perfect emotion array Y [i, j]

Euclidean distance
Euclidean distance is a measure of similarity and dissimilarity, the distance between two vectors X and Y is defined as shown in equation 1, in simple words, the Euclidean distance is the sum of squared differences between the similar elements of the two vectors X and Y, the reason behind taking the Euclidean distance is that it proved its effectiveness for text classification and clustering (see Cambria et al. 2010 for more details), and also, it is one of the most common distance metrics and acts as an inverse similarity function. To classify tweets as emotionally safe or harmful content, we set a threshold of (1.083274218344552), and we have proceeded with this value practically after the experimentation results process that we have made: • First, we have collected more than 800 words that can be used to express negative emotions. • Next, we analyzed the words, to get the following output • The next point in the process is to calculate the Euclidean distance between the perfect emotion array and the output that we get from the previous step; this value is going to be defined as the threshold.
The value that we have obtained (1.08) expresses how much the contents are different, as we have previously mentioned the greater the distance, the greater the difference (check Eq. 1, E.D stands for Euclidean distance). Now if the distance is equal to or less than (1.08), then we assume that the tweet content is emotionally safe. Otherwise, we display a warning message that this content could be emotionally harmful. Figure 1 illustrates in detail the proposed approach. We built the application using Nodejs and Angular framework and made it available on Github, you can find the source code and installation instructions in Yuan et al. (2016).

Results and discussion
Text emotion detection is one of the hardest tasks in natural language processing because even humans struggle to analyze sentiments accurately, here are some of the limitations that we faced when we were building the application: • The language and Intentions: We faced a lot of problems concerning languages because the intention of the tweets sometimes varies on what real means. • The media content: Text is not the only content in social media, there are also photographs and videos that can be emotionally harmful in the same way as text.
Furthermore, there are certain threats to the validity of our approach primarily in inherent differences between the compared tools. First, the method of calculating the Euclidean distance, which could not have been avoided, might have produced certain inconsistencies. Second, the nature of this tool type itself might have affected the results. IBM tool does not treat neutral as a special type, so we had to determine a threshold which was 1.08, the dataset combined Fig. 1 Flowchart of the proposed approach the emotions of anger and disgust into one emotional type (label). Neviarouskaya et al. had a similar problem with certain inconsistencies in the emotional model. Most IBM tool errors come from cases where additional context is required for the correct interpretation of textual emotion. This emphasized the need to include word sense disambiguation in our future research. Further research is needed to determine how much the difference between the data set and the second data set emotion (the difference sometimes is very small) affects IBM's final accuracy. The third kind of error is due to the vocabulary and style used in the language of fairy tales which is, arguably, significantly different from the contemporary use of language. These errors might be reduced by expanding our lexicon, but it is uncertain whether this would make the algorithm sufficiently powerful to take it out of the context of fairy tales and into the "wilderness" of the Web. We have gathered a collection of tweets that we intuitively thought might hurt users emotions, some of which we included in Table 1(We have done the same process with content that we thought might be emotionally positive to certain users, results are included in table 2). The results demonstrate the efficiency and effectiveness of our approach in filtering any suspicious content that may cause emotional harm to end users and by consequence protect users mental health to a certain extent.
According to the results shown in the table below, we have noticed that the Euclidean distance calculated from all the tweets that we have performed an emotional analysis did not exceed the threshold that we have set earlier (1,08); therefore, the emotion classification of these tweets is positive and content is emotionally safe and by consequence, it is okay to be displayed. We have noticed as well that the joy value in all tweets emotion extraction is significantly higher than all other 4 emotions (sadness, anger, disgust, fear) which are considered to be negative emotions and this proves the positive results that we have obtained, in addition to that if we analyze the sentences individually we can see for sure that their content affirms something good and reflects happy and joyful emotions like for example in the first tweet it reflected the fact that PLA's participation in drills aims to deepen practical and friendly cooperation with the militaries of participating countries, which is good news, in the other hand the second tweet expressed the feeling of the first meeting with his lover, and for third tweet, it was a Congratulations message; as for the last tweet, it was a motivational message and helpful advice to feel better about yourself. To conclude this observation, we saw that if the joy value is significantly higher than the other emotions, the content will be automatically positive and safe according to the Euclidean distance.

Conclusion
Artificial intelligence (AI) has gotten a lot of press in recent years. The idea that computers would be able to imitate human cognitive processes to solve complicated computational/analytical issues is enticing, but it might be deceptive. It is easy for someone who is not familiar with AI technologies to think. For example, these systems can mysteriously and almost simply extract valuable insights from data. In this paper, we have presented a solution to create an emotion filter that detects based-text emotions extracted from tweets and monitors them based on their harmfulness. We presented an approach for textual emotion recognition positioned within the context of tweets from API Twitter. Our classification algorithm receives a text tweet as input and classifies it according to the five emotional types. The output  Chen et al. (2021) in their paper they look into sentence-level categorization, as well as review-level categorization, and their research and analysis make use of the Scikit-learn program which is a Python-based accessible software library which they use unsupervised techniques to measure similarity. On the other hand, IBM API analysis and similarity calculation using the Euclidian distance performed better than other machine learning methods and eventually outperforms the Scikit-learn program. Therefore, for our study, we decided to categorize tweets into their relevant sentiment and emotion classes using the score we got from calculating the Euclidian distance. Also, our contribution is based on the way IBM natural language understanding API libraries are created and how they are used in conjunction with heuristic rules. Our approach is illustrated through a software system, IBM API. Besides the affect recognition engine, IBM's natural language understanding API is, to the extent of our knowledge, the most reliable free open-source textual emotion recognition API published on the web. The evaluation study showed promising results in terms of high classification accuracy, highlighting the importance of text emotion recognition. Future efforts will be centered on refining the algorithm in the IBM natural language understanding API software for better accuracy.

Conflict of interest
The authors declare that they have no conflicts of interest.