I have worked the past few months on analysing emotions with deep learning models in order to detect depression and I wrote my master thesis about it (link at the bottom of this article). I also elaborated some ways to counter depression on social networks when it is detected. This article aims to establish some methods that could be applied to detect and mitigate depression on social networks. I won’t enter into details such as the coding because I want this article to be accessible for any type of background, since the importance here lies in people being aware of these techniques.

The need to counter depression

Social networks are becoming a huge part of current human interactions. People publish publicly their thoughts, feelings and emotions. And they would interact more often with people feeling the same way as them. Hence, depressed people might interact, follow and share content with other depressed people. It creates some kind of vicious circle, where it becomes harder and harder to get out of the depressive period.

They have the data and the resources, I have the methods

Social Networks, now at the center of our life, have the responsibility to take care of their users. These companies have enough data to recommend you the smartphone you would most likely buy and they can do enough efforts to make you think you actually need that new smartphone. That data, and those efforts, could be used to help the users with problems like depression, and I’m going to show you how it can be done. So now Facebook, Twitter & Cie, you have no more excuses ;)

AI and Emotions

Here are the three problems that come up when we want to mix artificial intelligence and depression.

1. Emotion Classification

The emotion classification simply consists of attributing a class of emotion to a message. For example, “i love you” is supposed to be classified as a love message. To give you an idea, here are the classes of emotion I considered in my study :

Fun Haha that afternoon was so great
Happy I'm so glad I received a new phone
Love I miss you and I can't wait to see you !
Neutral This is an interesting article.
Worry I'm scared I won't have a good grade.
Sadness I don't like when it rains, it makes me feel down.

2. Emotion Prediction

The emotion prediction tries to predict the emotion of the next message of a user by considering the emotions of the few past messages of this user. This is an indicator of the user’s mood on the short term. Here are a few examples of what the system is supposed to give us for the given past emotions.

Past Emotions Prediction
Sad > Neutral > Sad Sad
Fun > Happy > Neutral Happy

3. Depression Detection

The depression detector tries to detect whether or not a user is going through a depressive period by considering the whole history of their messages’ emotions. This is a global indicator of the user’s mood.

Past Emotions Prediction
Happy > Love > Fun > Neutral > Happy > Neutral Not Depressed
Sad > Worry > Sad > Neutral > Sad > Sad Depressed

Building a Dataset of Emotions

For those of you who are not familiar with AI, such models to predict or classify need to be trained. It means that we have to find the right parameters that will give the right prediction. To do that, we need some data on which we can first train the models and try to optimize their performances. For instance, to train the emotion classifier, we need a list of numerous tweets associated to a class of emotion. It means we need a list of happy tweets, a list of sad tweets, etc. All these lists are then gathered to form the training dataset. Once the model is trained, we can then apply it to classify tweets for which the emotion is not given.

The whole question is how to get a training dataset ? Do we have to pay people to classify by hand the emotions of thousands of messages one by one ?

To answer this question, I chose to work on Twitter. Something really great about Twitter is being able to follow the tolerant tweets of an orange man with a blond hairpiece is its system of hashtags such as #covfefe and emoticons.

Instead of paying someone to label one by one the messages, I just “guess” the emotion of a tweet by looking at the hashtags and the emoticons in it. I make a list beforehand of hashtags and emoticons associated to a particular emotion and I retrieve the tweets containing only those.

#enjoy, #enjoylife, #relax, #laugh, #lovelife, #sohappy, #excited,#feelgood,#happier,#goodmood, #joy, 🙂, 😀, 😛, 😉 Happy
#sadness,#sad,#depressed,#alone,#lonely,#sadquotes, #depression,#anxiety,#crying,#upset,#lifesucks, 😞, 😕, 😢, 😞 Sad

Using these lists, I can now build my dataset. Let’s say I want to generate a list of happy tweets using only the hashtag “#enjoy”. I ask Twitter (via its API) to give the last tweets containing “#enjoy” and I collect all these tweets. I can do that for every other hashtags like “#enjoylife”, “#relax”, “#laugh”, etc. That is how I get my list of happy tweets. Similarly I can do the same for every single emotions, and generate a list of sad tweets, worried tweets, etc.

You might wonder : so you managed already to classify emotions since you are able to build a list of happy tweets. Yes I am able in a sense, but the rules defining a tweet as happy or sad are very simple, and work only with tweets containing the emoticons in my list. With that system I am not able to classify “I love you” for instance.

I want my model to be better than me because I want it not to use fixed rules like this. Hence, from my list of labeled tweets, I remove emoticons and hashtags, so that my model won’t have this information : it will have to understanding what the person is saying and not classify a tweet only based on emoticons and hashtags.

Counter the Depression

If social networks could set a depression detection as presented above, that would already be great. It would then be very simple to at least recommend helpful resources to depressive users.

Not only can my work be used to detect depression, but it can additionally be applied with ease to actively mitigate the spread of depression. Here are some methods I thought about, without having to do much more effort.

1. Limiting interaction with depressive content

The first way would be to offer to the users, with their consent, a way to limit their exposure to sad content if they are classified as a depressed user. This would limit the vicious circle effect. This would require to be able to classify the content as as sad or happy, but this is something that has been done many times in the past years, so this is easily doable.

2. Increase exposure to happy content

A complementary way would be to recommend to the depressed user more happy news and content more generally.

3. Predicting Depression

The work I did in terms of prediction was not very consistent : I had almost no resources, and I did not have access to much data. But I am pretty sure that some teams could manage to accurately predict more than just the next emotion. This prediction, of the next messages, could then be fed in a similar depression classifier to be able to identify depression before it actually occurs. The efficiency of the methods mentionned above to mitigate the effects of the depression would sensibly increase.

4. Other ways to help

I am an engineer, and I know almost nothing about depression. I tried to think about methods to counter depression from an engineering point of view, but they are not perfect, especially considering that people might not want the social networks to control their feelings. However, there are many specialists in the world that probably have better ideas on how to help depressed people online. They could probably come up with smarter ways to more directly help people suffering from depression.

Conclusion

I hope this article presents depression detection as easy, because it is actually very easy to create models that detect depression. The trickiest part, as an engineer, is to find the right thing to do in order to counter depression. And it is probably that point that would require the help of some specialists. But the technical part, at least, is easy to implement.

For those of you who want more details, here is my master thesis : Deep Learning For Emotion Analysis.