COVID19, Mental Health & Artificial Intelligence — Part3

What is a chatbot?

A bot is a software program that can automate tasks. A chatbot is a bot that can have a conversation with a human through the internet. A user can submit a question or remark to the chatbot, and the bot will respond as appropriate.

A chatbot interacts on a format similar to instant messaging or texting. It artificially replicates human interaction using machine learning to guide its responses.

A chatbot is an application that has an application layer, APIs and a backend database. It needs to be able to process human language.

How does a chatbot work?

A chatbot needs to be able to understand user queries and respond appropriately. It relies on pretrained models for this. The chatbot also records and logs all communication for future training. While it requires a bigger set of questions for initial implementation, it is also trained to identify and understand when questions are similar, making future updates easily.


On the backend, a text based or voice based chatbot performs two tasks — its analyzes the user query and formulates a response. The most important part of the chatbot algorithm is to identify context and extract information from the user query. If the algorithm fails to understand this, then the chatbot won’t be able to respond correctly.

The biggest advantage of machine learning models is their ability to learn on their own, with no need to define manual rules. A set of relevant data with several examples for the tags you want to analyze, is what you need to train your chatbot.

How is a chatbot trained?

  1. Define “intent” — what is the specific purpose of your chatbot
  2. Collect real end-user “utterances” to map to intents. It is very important to collect and use real world user data. The more realistic the training data is, the better is the performance of the system.
  3. Create “entities” these are the words/phrases in the utterances that represent key information. These become tags that are used to extract relevant content from end user query.
  4. Map utterances collected in step2 to intents defined in step1. Subject matter experts help is required to correctly assign utterances to intents.
  5. Divide the utterances in step 3 into two sets randomly, a training set and a test set. A 70% training and 30% test is a typical split.
  6. Train the chatbot using the training data set from step4. This training set creates the baseline for the chatbot.
  7. Run the test set from step4 against the trained classifier. Collect performance metrics like precision & accuracy.
  8. Perform Error Analysis: review the results in step 6, if the classifier missed certain utterances, try to understand why. Update your training data accordingly and go back to step 5.
  9. Now the system is ready to be used. Collect user feedback through ratings or other mechanisms.
  10. Make sure to collect and log end user utterances, feedback and intents applied by the chatbot.
  11. Create a continuously learning system. Map the results collected in step9 to create new training/test data. Go back to step4 and iterate. This makes sure that the system is incorporating utterances missed earlier.

Chatbot Architecture

AI algorithms and multiple natural language processing tasks, like sentiment analysis, keyword extraction, tokenization, text & topic classification, and more, facilitate back and forth conversation and appropriate solution.

AI based chatbots work on these classification methods:

Pattern Matches

Bots utilize pattern matches to group the “utterances” and use the “entities” to identify “intent”. Once the chatbot understands the context, it can produce an appropriate response. Artificial Intelligence Markup Language (AIML), is the standard structured model used for these patterns.

Natural Language Understanding

NLU focuses on how to understand the human language so that machines can understand and analyze it. It involves breaking down the human language into a machine readable format. Using grammar rules and syntax, NLU attempts to understand the context of the user query.

NLU is a sub field of NLP. NLU is used in natural language processing (NLP) tasks like topic classification (entities), keyword extraction (tags), intent detection and sentiment analysis.

Natural Language Processing


NLP helps to process the user’s speech or text so that the chatbot can have a back and forth conversation with the user. It converts user data into structured form, which is utilized to find the appropriate answer to the user query.

Natural language processing consists of the following:

  1. Tokenization: The NLP task splits a series of words into linguistically useful pieces called tokens. Sentence tokenization splits sentences within a text, and word tokenization splits words within a sentence.
  2. Dependency Parsing: This NLP task searches for the subjects, verbs, objects, common phrases and nouns in the user’s text to discover related phrases that what users want to convey.
  3. Part-of-speech tagging: this involves adding a part of speech (eg: noun, verb, adverb, adjective, etc) to each token. This helps to understand the meaning of sentences by identifying relationship between words.
  4. Normalization: This program model processes the text to find out the typographical errors and common spelling mistakes that might alter the intended meaning of the user’s request.
  5. Named Entity Recognition: This task involves extracting entities (different categories of words) from within a text. This is information that is required to assess response.
  6. Text classification: It understands the meaning of unstructured text and organizes it into predefined categories/tags.
  7. Sentiment Analysis: This is a kind of text classification which categories text by sentiment. This task uses the machine learning model it is trained with to classify the text by user opinion(positive, negative, neutral, etc.). It will study and learn the user’s experience, and transfer the inquiry to a human when necessary.

Once the chatbot interprets the user’s request correctly, it will provide the most appropriate answer for that request.

Mental health chatbots during COVID

Many mental health chatbots have become available during pandemic times to enable people to seek help and talk to someone during these difficult lockdown times, when anxiety & depression is increasing but access to usual health system is limited.

Success stories of AI mental health chatbots help spread the word and encourage others to use these chatbots for help. “A chatbot pulled me out of a ‘really dark place’” published in BBC, is a story of how Vivibot, a mental health chatbot, helped out a patient by having friendly conversations and setting simples goals like painting nails for starters. A global study showed that 82% of people believe robots can support their mental health and would prefer talking to chatbots over humans.

While chatbots may not be able to completely replace human intervention in mental health, various chatbots targeting specific mental health issues are offering a viable solution to those in need.

Divya Sikka is a Student Ambassador in the Inspirit AI Student Ambassadors Program. Inspirit AI is a pre-collegiate enrichment program that exposes curious high school students globally to AI through live online classes. Learn more at





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

🔍 Where do biases in ML come from? (5/N) 📊 Structural bias

Will AI take away your jobs??

360Learning: A Crisp AI-Based Learning Platform!

Teenage AI Chatbot

AI: Self-Programming, Is It Far From Us?

Belarus situation, and how A.I can help

Game playing with adversarial algorithms

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
Divya Sikka

Divya Sikka


More from Medium

Advancing Health Equity with Artificial Intelligence

AI for achieving Critical View of Safety in Laparoscopic Cholecystectomy Videos

AI in Agriculture

Meet the 2022 Fellows: Cindy Xie