Creating a mental health resource chatbot with a deep neural network.

You: Hey Serenity, how are you? Serenity: Good Alisha! How can I help you? You: I want to learn more about Schizophrenia, what is Schizophrenia? Serenity: Schizophrenia is a serious psychiatric disorder characterized by the person slowly losing contact with reality, often experiencing delusions or hallucinations. You: I know someone who has Schizophrenia, what can I do to support them? Serenity: Here are some tips Alisha; Maintain a low-stress environment, Use language that is positive and supportive instead of critical, Have one person speak at a time and keep voices down.

The Basics

For my program I used NLP and a Deep Neural Network, both of these concepts are subsections of Artificial Intelligence (AI).

NLP

NLP is a field of AI that gives machines the ability to read, understand and derive meaning from the human language.

Deep Learning

There are 3 main layers in a Deep learning neural network, an input layer, a hidden layer and an output layer. The system must process layers of data between the input and output to solve a task in our case make a prediction. Inputs to a neuron can either be features from a training set or outputs from a previous layer’s neurons. A neuron takes a group of weighted inputs, applies an activation function, and returns an output.

Building a mental health educational chatbot

Essentially what I have built is an ordinary chatbot with a twist as we are using Deep Learning to make better predictions of possible answers to questions.

Step 1: Initializing Chatbot Training

Our first step is to initialize the training for our chatbot.

Step 2: Building the Deep Learning Model

The next step to building the chatbot now that we have our training and testing data, is to use a deep learning model from keras called Sequential. Sequential is a neural network model from keras, if you want to learn more, check out this documentation .

import tensorflow as tf  
from tensorflow.python.framework import ops
ops.reset_default_graph()
net = tflearn.input_data(shape=[None, len(training[0])])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, len(output[0]), activation='softmax')
net = tflearn.regression(net)
model = tflearn.DNN(net)
try:
model.load('model.tflearn')
except:
model.fit(training, output, n_epoch=1000, batch_size=8, show_metric=True)
model.save('model.tflearn')

Step 3: Building the Chatbot

Now we assemble our chatbot!

def chat():
print("Start talking with the bot(type quit to stop)!")
while True:
inp = input('You:')
if inp.lower() == 'quit':
break
results = model.predict([bag_of_words(inp, words)])
results_index = numpy.argmaz(results)
tag = labels[results_index]
for tg in data ["intents"]
if tg ['tag'] == tag:
responses = tg['responses']
print(random.choice(responses))
chat()

Results

After a lot of tweaking and editing, the chatbot is made. Let’s run the chatbot!

You: Hi Serentiy  
Serenity: Hi Alisha, how can I help you?
You: What are some symptoms of depression?
Serenity: Here are some symptoms of depression: Hopeless outlook, Lost interest, Increased fatigue, Suicidal thoughts, and Anxiety
You: What italian restaurants should I try in Toronto?
Serenity: Unfortunately, I do not have an answer for that.

The Future

One of the biggest questions is now that we have this chatbot what are we going to do with it? and how is this technology going to be accessible?

  • Connect with me on Linkedin to stay updated on my AI journey, and shoot me a message (I love meeting new people).
  • Subscribe to my newsletter, for monthly updates on what I’m working on!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store