How AI is used for mental health therapy
Tags: machinelearning, therapy, mentalhealth, sentimentanalysis
Published: 2022-01-14 00:43:29

## TLDR
As the current mental health screening system relies too heavily on manual assessments, how can sentiment analysis (SA) be used to streamline the new patient screening process and reduce the abysmal 10-week long waitlist to receive help from a therapist?

## Outline

* The issue

* What’s all this jargon?

* New patient debrief

* CTRL+F for symptoms

* Further research and considerations

* Conclusion

## The issue
For a generation of young people who have de-stigmatized mental illness, we are shocked to discover that finding a therapist is as appalling as our dating culture: an arduous ghosting game. Patients wait an average of 10 weeks to see a mental health professional, just to receive a diagnosis! So if you are absolutely thirsty for attention, then there are apps commonly sponsored by YouTubers that match you with a therapist, but results may vary.

Why is it so difficult to receive help? Since we rely solely on a mental health professional to review tens of pages of medical history and questionnaires for each new patient, and with the normalization of mental illness, the supply of qualified mental health professionals cannot keep up with the volume of patients seeking help. It’s [alarming](https://www.nimh.nih.gov/health/statistics/mental-illness) that while 20% of people are mentally ill at any given time, only 44% get help, and 100% of therapists are exhausted and can’t get up.

_<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qnqvmmgc6ka59x5ynhqk.jpeg)Life alert [meme](https://memegenerator.net/Help-IVe-Fallen-And-I-CanT-Get-Up)_</center>

### Treatment plan
So, how can machine learning help in this situation?

In this blog post, we’ll be exploring how a method of sentiment analysis, ***named entity recognition*** (NER) can [expedite](https://pubmed.ncbi.nlm.nih.gov/25982909/) the new patient screening process for psychologists by categorizing and summarizing large amounts of unwritten responses by patients. This is a powerful information extraction tool that can potentially organize and make sense of otherwise unstructured and qualitative data that we currently rely on extremely specialized, manual labor for.

Sentiment analysis in therapy is a very new area of study, and the goal is not to replace mental health professionals, but make their jobs easier using machine learning applications. I genuinely hope there is more research in medicine and mental health so that we can not only ease the burden of overworked psychologists dealing with everyone’s Zoom fatigue but also improve accessibility to mental healthcare for those in need.

_<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szh1ynmga56h5788s238.jpeg)[Source](https://knowyourmeme.com/memes/modern-problems-require-modern-solutions)_</center>

## What’s all this jargon?
Before we discuss any AI, I’d like to spend some time addressing any confusion about the terms I just rattled off.

### Sentiment analysis
Sentiment analysis (SA) is the way AI is able to extract human emotions and intensity through [natural language processing](https://www.mdpi.com/2076-3417/9/24/5462) and context.

### Machine learning pipeline
The end goal of ML is to teach the model to do a task for you. Suppose you are a [weeb](https://www.urbandictionary.com/define.php?term=Weeb) and want to learn Japanese (did I just expose myself?)

_<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zherl6d4654bv3cfsnsf.png)Doki Doki Literature Club [reference](https://knowyourmeme.com/photos/1308052-doki-doki-literature-club)_</center>

I like to think of ***sentiment analysis*** (SA) in machine learning akin to learning Japanese from watching 1000 hours of anime (training stage), then going to an authentic Japanese restaurant to eavesdrop on some people speaking Japanese (testing stage).

Although you can’t understand entire statements, you used ***named entity recognition*** (NER) to pick up key phrases in the “PEOPLE” category/entity like mother-in-law, husband, and “unreasonable,” and that gives us a general vibe (or sentiment) that they’re likely talking 💩.

### Named entity recognition
NER is actually an information extraction algorithm that trains itself on specialized jargon and then categorizes data into pre-labeled entities or concepts.

Now that we have a better idea of what SA and NER are, let’s see how named entity recognition is useful for psychoanalysis.

## New patient debrief
Using NER, therapists can quickly familiarize themselves with new patients and which intense emotions they feel, behaviors they exhibit, which mental illness they suspect they have using the keywords patients used in their questionnaires.

Take this existing implementation of NER on identifying clinical terms in patient charts by [John Snow Labs](https://demo.johnsnowlabs.com/healthcare/NER_CLINICAL/) (screenshot of demo below) for example: the ML model is able to identify symptoms of illness and treatment methods after learning medical jargon from the PubMD data set.


_<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48w87cl3ss7dnok29rnw.png)NER_clinical [demo](https://demo.johnsnowlabs.com/healthcare/NER_CLINICAL/)_</center>

Thus, for therapists, instead of reading a patient’s entire life story, a sentence like this:

> *“When I’m feeling anxious, I overthink and lose my appetite.”*

Would be reduced to:

> *anxious: B-ILLNESS
lose: B-SYMPTOM
my: I-SYMPTOM
appetite: I-SYMPTOM*

Since some ideas are multiple words long, we use the “B” tag in front of the entity to indicate the first word in the phrase, and those that follow after with the “I” tag.

## Impact
This summary is significant in automating a time-consuming step by allowing therapists to quickly grasp what’s ailing the new patient. Particularly for patients that require care from both a psychiatrist and therapist, it would be revolutionary to have a tool that ensures communication between the medical professionals are concise, detailed, and missing no information.

### A technical explanation of NER
If you are the godsend thinking of implementing a sentiment analysis using NER for therapists, thank you, and please refer to SnowLab’s [implementation](https://github.com/JohnSnowLabs/spark-nlp-workshop/blob/master/tutorials/Certification_Trainings/Healthcare/1.Clinical_Named_Entity_Recognition_Model.ipynb) and [Medium article](https://medium.com/spark-nlp/named-entity-recognition-for-healthcare-with-sparknlp-nerdl-and-nercrf-a7751b6ad571) as a guide.

Else, we can get a general idea of how this NER model by Spark NLP (an open source ***N***atural ***L***anguage ***P***rocessing library) works through the same weeb analogy:

Since you cannot possibly learn Japanese from raw anime episodes, someone has to do the manual labor of adding English subtitles before you watch it. Therefore, we have to convert sentences into a format the NER model understands, CoNLL.

So my sentence “When I am feeling anxious, I overthink and lose my appetite,” has punctuation removed, and contractions like “I’m” expanded, parts of speech tags added, and is converted into this mess:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9vz0azdm99rgz4x5rhi.png)

If you’re kind of confused yet curious, you can find the list for part of speech abbreviations [here](https://stackoverflow.com/questions/15388831/what-are-all-possible-pos-tags-of-nltk) and try this example for yourself using my [code snippet](https://github.com/Felicious/Freudian-Clip)! Essentially, what’s happening in the code is that we need to separate sentences into individual words, mark their part of speech, and entity labels like in this excerpt:

_<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3dxvf5f8y3l75lhyceky.png)using “Paraiso” from [carbon.now.sh](https://carbon.now.sh/)_</center>

Fortunately, the Spark NLP library has a couple built-in functions that convert sentences into this format, so you don’t need to use the NLTK one I used in my example. The functions are this [tokenizer](https://nlp.johnsnowlabs.com/docs/en/annotators#tokenizer) for converting sentences into individual words, and a [POS tagger](https://nlp.johnsnowlabs.com/docs/en/annotators#postagger-part-of-speech-tagger) for identifying part of speech.

But since they do not have entity labels for psychology terms like the “emotion” and “behavior” tags I used in my example, we’d need to find a library based on the [The Diagnostic and Statistical Manual of Mental Disorders (DSM)](https://www.psychiatry.org/psychiatrists/practice/dsm) that’ll be used to identify mental illnesses and their symptoms in a piece of text.

Finally, now that the training data is pre-processed, data scientists can now train the model, test it, and let therapists use it! Let me know when it happens! 😉

_<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f331epockwk25g2rzsri.png)draw an owl [meme](https://knowyourmeme.com/memes/how-to-draw-an-owl)_</center>

## CTRL+F for symptoms
Or CMD+F for you Mac users.

On the other hand, after identifying the symptoms, emotions, and behaviors of the patient from their questionnaire, we can do a reverse-search to look for more specific information. Let’s say the therapist noticed a patient used sleeping medication and wanted more context and why.

In SnowLab’s [implementation](https://github.com/JohnSnowLabs/spark-nlp-workshop/blob/master/tutorials/Certification_Trainings/Healthcare/1.Clinical_Named_Entity_Recognition_Model.ipynb), for example, they wrote a search function called ***get_clinical_entities*** that finds all mentions of medications for 100 patients, as well as specifications, if any, about the quantity and frequency the medication is consumed. The location of the sentence in the overall piece is also recorded, to locate the information easier.

_<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t82pgzarirxklt1v24ks.png)from line 51 of [NER_clinical](https://github.com/JohnSnowLabs/spark-nlp-workshop/blob/master/tutorials/Certification_Trainings/Healthcare/1.Clinical_Named_Entity_Recognition_Model.ipynb)_</center>

## Applications
Once this information is identified, therapists can request data scientists to help them analyze and visualize trends in patient medical histories, and whether treatments are effective or not.

For example, a potential usage of analyzing a patient’s medication history for psychiatrists is monitoring whether the medicine they’re taking has improved their condition. It would be a lot to keep track of the condition of the numerous psychiatric patients, how dosages of several medications affect them, and whether there are unexpected side effects over time, but ***detecting anomalies*** and ***finding trends*** is what machine learning is great at.

Moreover, if certain medication is proven to be successful for a statistically significant number of patients with ADHD who experience the symptoms “x, y, and z,” it is crucial that this discovery is shared with a medical professional. While additional research is required, ML can expedite this cross-referencing process for psychiatrists. One possible application is an attempt at unbiased data reporting by generating a list of ADHD patients taking this medication, detailing whether they’ve recovered or not, the duration of consumption, and the side effects they experienced.

## Further research and considerations
There are many more ways sentiment analysis would improve the quality of therapy and assist mental health professionals in treating more patients. In addition to the ways textual information extraction SAs determine emotion in unstructured, self-reported medical reports, other forms of sentiment analysis could improve other facets of mental healthcare, such as:

* A classifier, based on various parameters describing patient condition, of whether a patient could be in a bad mental state and harm themselves. A support vector machine (SVM) is allegedly one of the best ML approaches that predict the polarity of a sentiment, according to the 3rd reference (“Emotion AI-Driven Sentiment Analysis”)

* Somehow quantifying a severity score of a patient’s condition to indicate they’re in critical condition and get them help faster

* Due to the personalized nature of therapy, it can also be difficult to get definitive feedback from patients. In this study, researchers have been trying to identify which words exchanged between therapist and patient were most effective at treating their illness using natural language processing (NLP). This is the umbrella sentiment analysis falls under

* How to normalize qualitative data, like subjective description of emotions, so that a patient who describes their emotions more animatedly does not receive a biased score over a patient who keeps things to themselves

## Conclusion
Whether you are a medical professional, data scientist, or someone with an interest, I thank you for taking the time to consider all of these ways sentiment analysis can benefit therapy. I believe your work and contribution to research in using machine learning to improve the quality of healthcare is noble and greatly appreciated in these times when we’re experiencing a mental health crisis and a shortage in healthcare workers.

_<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xhx3hvt08oekftikqm5.gif)[capoo](https://giphy.com/gifs/love-cute-1hoKkBNSBxVyHIsPer) ❤_</center>

I’m grateful that the two most important people in my life have access to mental healthcare, and I hope that with further interdisciplinary research, this accessibility is extended to more people’s loved ones.