Predicting and Curing Depression Using Long Short Term Memory and Global Vector

,


Introduction
Psychological disorders can be cured, or at least properly managed, if they are diagnosed at an early stage. Research has found that emotions and stress levels can be determined to a significant extent using heartbeat variation data. This data can be easily obtained using commonly available smartwatches or fitness bands. Capturing these data in the regular course of the day can help in early detection, subsequently helping to provide prompt corrective action that can overcome these stressrelated disorders. Although people have just been introduced to simple applications of Internet of Things (IoT), the power and range of IoT is vast. In the future, most of the devices will be connected to the internet, and will generate a lot of data that will enhance people's experience with smart devices. The following are reasons why this paper is relevant in today's world.
• There are several types of emotions people experience daily including happiness, sadness, joy, and depression, but most people fail to recognize that they are going through tremendous stress that may threaten their health. • Nowadays, students are very vulnerable to depression due to a variety of reasons, especially because of the COVID-19 lockdowns [1,2]. • There are various methods to detect a person's stress level and emotion, but a unique method is to analyze the kind of texts they search for on the Internet, the kind of messages they send to their friends and family, and the kinds of comments and posts they upload on social media. It can also be inferred from the kind of questions they ask voice chat boards like Siri and Google Assistant when they feel alone and depressed [3,4]. • Various algorithms can be used to overcome these problems and help people in need by predicting their stress level from their texts [5]. • Data collected regarding these emotional dynamics can be used to create an IoT architecture model that can use various devices like smartwatches, mobile phone, and a cloud server for processing the data. It can also use curative methods that can work together to develop an ecosystem for predicting and treating emotional problems [6,7]. • Using machine learning, this model will improve itself with each use. There will be an on-going supply of data for further sentiment analysis, emotion dynamics, and manipulation of emotions with IoT devices around us [8]. • The proposed model, which uses Bi-LSTM and a GloVe layer, achieved an accuracy of 86%.
This model can be used in an IoT system to predict and possibly cure depression.
The rest of the paper is organized as follows: Section 2 presents the related work in emotion dynamics, and how mood can be modulated. In Section 3, the problems people face and this paper's solution to them are described. Section 4 discusses the proposed architecture, experimental results, and performance analysis. Section 5 concludes the paper and provides the future directions.

Related Work
Heart rate data can be analyzed to recognize emotions based on its pattern. Researchers in the University of China conducted a study using 25 subjects and a wristband with sensors that electronically recorded subjects' heartbeat and pulse. After the data was analyzed, it was observed that emotional responses varied with heart rate variation. At the end of the study, it was determined that 80% to 90% of the data could be used to judge emotions, and that heart rate variations could be used to predict human emotions [3]. In addition, it was also found that the part of the brain that controls and monitors emotions also regulates the heart rate, thus proving that a person's heart rate and its variation are directly tied to their emotions [9,10]. To determine if a person is suffering from depression or hypertension, it is necessary to understand their emotions. This paper discusses how to predict depression through the variation of emotions, such as the variation of happiness, sadness, and other moods. A variety of algorithms can be used to determine if the person is suffering from depression, and if the person is, more can be done to help such as suggesting activities or recommending that they consult a doctor [11,12]. Music can be used to regulate emotions in a positive manner. The depression recognition method for college students using deep integrated support vector algorithm can work as therapy for a person who is suffering from depression. Listening to a particular kind of music or playlist at a certain time especially when the subject is experiencing certain mood types (sad, happy, moderate or critical thinking, etc.) can affect mood swings or changes [13].
In a way, emotions can also be gauged by a person's preference of music types. Conversely, we can see what type of music can be used to modulate one's emotions in a particular situation, for example, to determine what kind of music a person should listen to, to help battle depression, sadness, or other forms of mood disorders [14]. Emotions can be regulated by one's mobile phone and how it is used. There are many ways in which a mobile phone can help manage its users' emotions. It can serve content that can trigger bad memories; it can recommend music; it can connect users with various people who suffer or have suffered similar problems, thus creating avenues for emotional and moral support [15]. Even the light on the screen of the mobile phone can have some effect. Depending on the type of brightness, light affects the brain in different ways. The light from these devices can be used to change the users' mood and improve their environment [16]. In today's world, social media is an important part of people's daily lifestyle, and it collects data of everything we do online. Hence, the activity of a person on social media can also be used to predict depression [17,18].

Problem Statement
Predicting emotions via digital means requires a lot of data collection, processing, and analysis. With the proposed model, individuals' IoT devices such as mobile phones, smartwatches, fitness bands, and the data generated by various apps can be used to predict emotions using several methods. To predict emotions, machine learning models need to be built and validated. The data required to build these models include data collected from chats, comments, and social media posts. Other sources of data include search terms on web browsers, voice data from smart speakers (Google Assistant and Alexa), etc. Different models and algorithms need to be implemented, and the data needs to be analyzed to find the best possible method of natural language processing that can be used in this ecosystem for depression or stress prediction [19]. After creating the ecosystem to predict emotions, the next step would involve creating the curative aspect (everything required to help the subject recover from the disorder). The curative aspect might require recommendation engines and the use of IoT devices (smart speakers, smart light, etc.) within the subject's surroundings. To ensure the subjects' privacy during treatment with digital tools, cyber-security measures must be put in place. If the subject isn't responding to treatment, alternative measures must be tried. The system must also be built to learn from experience using machine learning algorithms. For instances where serious conditions are detected or predicted by the system, a trained and certified expert (e.g., doctor) must immediately be consulted to ensure early diagnosis and treatment of the condition.

Proposed Model of Predicting and Curing
The system for predicting and curing both depression and stress involves multiple devices, multiple layers, and various algorithms required to come up with an accurate and reliable conclusion about the subjects. None of the models available provide a complete IoT system with artificial intelligence to predict and cure depression.

IoT and AI Model for Predicting and Curing 4.1.1 Data Collection
Data collection is an important part of the whole mechanism, and even the slightest of errors can make a big difference. There must be an errorless method to recognize a person's emotions and feelings through digital means, whether by using the heart rate mechanism or social media data collection. Data is collected using devices that monitor heart rate (and its patterns) continuously for 24/7. Examples of such devices include smartwatches and fitness bands. Analyzing what kind of apps and sites a subject visits more often can signal when a person begins to slip into depression or others stressrelated problems. Text data can be collected from messaging apps chats, captions, and comments written by users on different social media platforms. Social media platforms like Facebook or Twitter recognize patterns in the words used in the posts of users. A user's search history can also be a source for evaluating their digital well-being.

Data Distribution
Once the data is collected from the hardware devices under digital platforms, it is shared with the in-built app on the phone that contains some preloaded algorithms which can detect depression symptoms. The data can also be shared with the cloud where it is further processed for more accurate analysis. Further processing makes it possible for a more precise result to be drawn from the given data, something that can be useful for recommending treatment options on the mobile phone.

Data Analysis
Having collected and distributed all the data, various algorithms are used to analyze the heart rate data, as well as the data from social media, apps, and platforms as shown in Fig. 1. After the analysis, the results are sent to the mobile phone. The algorithm predicts whether the person is suffering from depression or not. Once this step is done, other algorithms on the mobile phone and related processes take over. Furthermore, a recommended curative action like music (from a specific genre) will begin to play. This could be in a car via Bluetooth, in a smart home connected to the mobile phone via the internet, or even on the mobile phone itself. This will be the first step of attempting a cure to reduce depression or stress at an early stage. If the person is following the music trend recommended by the system, then any change in the person's emotions will be continuously recorded to see whether the music therapy is working. If the recommended solution is adjudged to be working, it will be continued, affirming that the diagnosis made by the system is correct. If not, then the system will try to do further research to determine if the person was misdiagnosed. If that is not the case, other curative steps would be recommended.

Post Depression Detection
Following confirmation that the individual has depression or another stress-related disorder, steps can be taken to help them. If the system recognizes that the person is suffering from depression, it does not directly recommend a consultation with a doctor or some other serious measures. After the therapy (i.e., music), the next step would be to involve the individual in creative activities that stimulate hormones and result in significant change in behavior. These activities include recommending special mobile games that are very addictive. Research shows that many people who are lonely and suffer from emotional problems like to play such games to keep themselves occupied [19]. Depending on the location of the person, some outdoor activities could be recommended to help the subject make better contact with the outside world. Such contact could result in positive change in behavior and elevated motivation. As the music therapy continues, the emotional dynamics data is recorded and analyzed to see whether these activities are helpful or not. If no improvements are detected, the system would try to analyze the data again and try some other therapy. The system could also recommend that the subject talk to close confidants, family, or even friends that they have not spoken to in a while. IoT devices installed in modern day smart homes have AI-based speakers and lighting systems. Even cars with smart lighting and music systems can be used for emotion regulation.

Security and Caution
A system that carries sensitive data about a user's needs to be alert and have a good security system. Therefore, if the person wishes to interrupt the system, he or she can do it at any given time. Should any of the therapies trigger negative emotions in the person, the system will stop automatically, and it will be recorded in the database. Using machine learning, the system will keep improving itself as time passes. As the number of users on the platform increase, the system is expected to get better because of the pooling of data. Because the modulation of emotions can be dangerous, the system doesn't change anything in the user's personal data. The system only makes recommendations which the user can decide to accept or reject.

Emotion Recognition by Wearables
Research has shown that analyzing the heart rate can be used to recognize emotions and feelings using simple gadgets found in everyday life [4]. Learning from data if (D c increases) then -stop the system -learn the mistake in curing from data End

Recording Heart Rate
Analyzing and recognizing the emotions of a person is a sensitive process in which the model cannot afford to be wrong. For such a sensitive process, devices and sensors that can collect an accurate and continuous heart rate data and its variation 24/7 are needed. To collect such an accurate data that could be fetched and further processed for emotion recognition, there are many sensitive devices like electronic wearables such as smartwatches and fitness bands. These wearables manufactured by various authentic and reliable companies such as Apple, Samsung, Fitbit, etc., can record the data that is required for the process of emotion recognition accurately.

Recognizing Emotions Digitally
Research has proven that continuous heart rate data can provide a digital understanding of emotions. One such experiment [3] was done using a band which was tied on the wrist of the volunteers. The band could electronically record heart rate patterns accurately. All the volunteers were shown different kinds of videos that could change their emotions. For example, while some were shown sad videos, others were shown happy videos that could stimulate the hormones in their brains and modulate their emotions so that the variation in the continuous heart rate could be monitored. This made it possible for a conclusion to be drawn on the variation between heart rates and different kinds of emotions. It was shown that wave patterns from continuous heart rates varied with changes in mood when a stimulus was received from an emotional video. As a result, it is found that emotions can be recognized digitally with varying heart rates recorded with smart devices (smartwatches or fitness bands) and observable on optical heart readers [3].

Emotion Recognition by Wearables
The emotional weather characterizing people's daily life activities and interactions can be predicted using machine learning algorithms. This can be achieved by analyzing various data gleaned from users' online searches, comments, and other digital footprints.

Input Sequence
A human's statement can be in the form of a conversation between two people, a comment or a caption, the basic idea being that the statement can be picked out for sentiment analysis to predict if the person is happy, sad, or in love. Input sentence can be any statement from a conversation between two people or a comment or a caption on a post. The basic idea is that the input statement must be a kind of sentence written by a human from which keywords can be picked out for sentiment analysis to help predict whether the person is in a happy, sad, or a loving mood. In the case of IoT devices, these sentences can be fetched from the search history of the browser. These are the keywords that the user frequently searches based on what they are thinking, the questions they are asking, or the problems they are currently dealing with. Users often interact with chat bots like Siri, Google Assistant, and Alexa. The comments and captions that users write on social media platforms daily are also relevant. To understand how the prediction of emotions from texts using natural language processing is generated, the architecture shown in Fig. 2

Global Vector Layer
Global vector or "GloVe" is a kind of unsupervised learning algorithm that helps in creating a vector form of normal words in a language. There are predefined vectors for many words in the text file. If a unique vector for a particular word does not exist, then a random vector is assigned to that word by calculating the mean and standard deviation of the words already present in the global vector text file. In this model, a vocabulary size of 10,000 is chosen and a vector of size 100 is set to map the words of the dataset in the GloVe representation. GloVe is chosen over word2vec and fasttext because GloVe is built on global matrix factorization using matrix factorization methods that reduce large term frequency matrices.

Bi-Directional LSTM
Long-Short Term Memory (LSTM) is a modified Recurrent Neural Network (RNN). LSTM was created to overcome the long-term dependency problem of RNN not remembering the information for a long time, in order to compare it with the current processing information. LSTM is created on an architecture like that of a RNN, but it has an advantage of remembering the information for a long time in the dense neural network that helps in predicting outcomes more accurately, especially in the case of natural language processing (NLP) problems. Bidirectional long-short term memory (Bi-LSTM), as the name suggests, is an advanced version of LSTM that has a bidirectional flow of data. Bi-LSTM can take input from both directions i.e., forward, and backward, and keep both past and future data in its memory. This helps in predicting the outcomes better than LSTM. Eq. (1) represents forward LSTM and Eq. (2) represents backward LSTM. Combined (1) and (2) forms the Bidirectional LSTM that used in this prediction model.
In Eqs. (1) and (2) c t is representing the hidden state h t is representing memory state. c t-1 and h t-1 are the previous states of LSTM function. A i represents attention score as input vector.

Dataset Analyses
The dataset consists of 21,405 unique entries of sentences, and each sentence is assigned the respective emotion it represents. Fig. 3 represents data analysis of the emotion dataset. Happy = 33%, sadness = 29%, anger + love + surprise + fear = 38%. Therefore, majority of data is primarily distinct between two emotion categories, i.e., "happy" and "sadness". Hence, it can be said that these two kinds of emotions will be predicted most accurately. The most frequently occurring words are found after removing all the unwanted words, spaces and symbols from the dataset as shown in Fig. 4. 80% of the data is used for training and 20% for testing.

Algorithm 2: Predicting emotions from text using Bi-LSTM and GloVe Input
Conversational text from -Chatting apps Caption and comments social media platforms Output Predicted emotion from the given text

Prediction algorithm begins Step 1 Input text pre-processing
Remove-unwanted symbols Null spaces Using NLTK Convert uppercase to lowercase

Step 2 Embedding GloVe layer
Plotting words in vector from -Vocabulary Size-10000 -Vector Size-100

Step 3 Processing
Input the vector words to Bi-LSTM Learning Rate-0.01 Batch Size-128 Epoch-45 Further process in the dense neural layer Step 4 On the above processing Predict emotion from sentence End

Creating the Prediction Model
The text data collected from a user's device is given as input in this architecture. After removing all the unwanted symbols, spaces, words and null values using Natural Language Toolkit (NLTK), the sentences are converted to the global vector representation form. After this conversion, the bidirectional LSTM model is implemented. With further sentiment analysis, the final output is given, which is the predicted emotions from a particular sentence. Two models will be evaluated and implemented. Both will be based on bidirectional LSTMs, but the difference will be that one model will be implemented without depicting global vectors, and another model will have global vector representation before Bi-LSTMs. The configuration of the models is given in Table 1. After implementation, both models will be compared based on accuracy, precision, recall, f1-score, macro average, weighted average and graphical representation.

Model Comparison
Figs. 5 and 6 represent the variation of accuracy with the epochs and the variation of loss with the epochs. On comparison of the accuracy and loss of training dataset and validation dataset of both the models i.e., Bi-LSTM without Global Vector layer and with Global Vector layer, it was observed (visually) that the model of Bi-LSTM with GloVe performed a little better than the one without GloVe. It can clearly be observed that the gap between the training line and the validation line reduces, which means the model is more accurate and precise.   Tables 2 and 3 shows that the Bi-LSTM with Global Vector layer embedded before the Bi-LSTM layer has proven to be more accurate with 86% than the one without GloVe that has an accuracy of 83%. Fig. 7 represents the comparing scores of Bi-LSTM algorithms with GloVe layer and computed using Eqs. (4)- (6).
where, TP-True Positive, FP-False Positive, TN-True Negative and FN-False Negative.   Many models predict stress with 70%-80% accuracy, but this model precisely predicts the exact state of emotions of 6 different classes with an accuracy of 86%. This makes the analysis of stress and depression more accurate and detailed.

Predicting Depression Using Social Media
Activities observed on social media platforms like Facebook and Twitter are significant predictors of depression. Indications of depression on social media platforms shouldn't be surprising. Research has shown that users' social media activities are significant enough to help in the prediction of the onset of depression [18,20]. A combination of recent posts, search history and status updates can help in predicting the user's behavior and depression. This shows the data of the emotion variability curve of big social media platforms like Facebook and Twitter. Every word written by the user in posts is analyzed by the algorithm, and the time adjusted mean squared successive difference (MSSD) score is calculated for every activity on the platform. The data is continuously analyzed whether the MSSD score is pointing towards positive behavior or negative behavior [5].

MSSD-mean squared successive difference
In Eq. (7) i = temporal order of x i δ 2 -determines whether a trend exists This further proves that digital means can be used to predict emotions and depression.

Music Modulates Psychology and Emotions
Studies have shown that the human mind reacts to different stimuli in different ways, and that this technique can be used to modulate one's emotions to some extent. Controlling and modulating emotions may seem impossible or difficult, but it has been proven that the brain can process information differently depending on the stimulus [13,14].
Music stimulates a neural impulse in the brain which can in turn affect a person's mood and emotions. Different genres of music can be used to modulate certain kinds of mood. For example, pop and rock music can change a sad mood to a lively or more enthusiastic and positive mood, while Rhythm and Blues (R&B) and slow music could be used to change someone's enthusiastic and excited mood to a normal and stable mood [21,22]. 30 people were used as volunteers for this survey. The participants were made to listen to music of different genres. A conclusion was drawn based on the opinion of the listeners as to what genre is suitable for a particular state or mood. Table 4 and Fig. 8 shows how the SCR frequency varies with change in genre of music. This happens due to changes in the nervous system when there is a change in the tempo and frequency of the music [23].  Depression and stress are very common psychological problems, but many people do not even realize that they suffer from them. In other instances, their doctors failed to diagnose them or diagnose them too late. This paper proposes a novel approach using the Bi-directional Long Short-term Memory (Bi-LSTM) and global vector algorithms for the prediction and treatment of these conditions. We compared the accuracy and loss of the two models namely Bi-LSTM without a global vector layer and Bi-LSTM with a global vector layer. We observed that the Bi-LSTM without a global vector layer had an accuracy of 83%, while the Bi-LSTM with a global vector layer had an accuracy of 86%. This predictive and curative method can help with early prediction and treatment. It provides basic therapy for keeping the situation under control and preventing the worsening of the condition. Regular people can also use this method for recommendation of music, and for a more engaging experience on their phones. The proposed model can be built in smartwatches. The data collected can be shared with other IoT devices to enable new forms of emotional regulation. For example, data about the user's moods can be shared with smart home systems which will then use the information to modulate the user's mood using lighting or music. This diffused use would increase the effect of this method on the digital curation of mild depression and stress-related problems. Furthermore, chat bots or AI-based voice instruction services like Siri or Google Assistant could be integrated to increase person-to-phone interaction. To better predict emotions and recommend cures for them, a more advanced model can be used. Such advanced method could use microchips that fit inside the human body to gather the necessary data. These microchips can detect change in hormones (i.e., serotonin, dopamine, and other components in the blood), making it possible for emotions and the patient's overall health to be better monitored. Brain waves can also be used in the future. However, they are still in the early stages of research. This research can help create the most advanced sentiment analysis models that could completely change the classical methods of treating psychology and other health problems.