This is a simple yet powerful Mental Health Chatbot developed using PyTorch and Natural Language Processing (NLP). It is designed to recognize user intent from text input and provide supportive, empathetic responses to promote mental well-being.
- Tokenization and stemming of user input.
- Bag-of-Words vectorization of text.
- Feedforward Neural Network (FFNN) for intent classification.
- Predefined supportive responses for each intent.
- Easily extendable intents.json file to add new categories.
The preprocessing steps convert raw input text into a numerical format usable by the neural network.
Input Sentence: "Is anyone there?"
-
Tokenize: ["Is", "anyone", "there", "?"]
-
Lowercase + Stem: ["is", "anyon", "there", "?"]
-
Remove Punctuation: ["is", "anyon", "there"]
-
Bag-of-Words: [0, 0, 1, 0, 1, 0, 1]
- Input: Bag-of-Words vector.
- Hidden Layers: Fully connected layers with activation functions (e.g., ReLU).
- Output: Softmax layer for intent prediction.
Example: Input: "Hello?" → BoW: [0, 0, 0, 1, 0] → FFNN Output: [0.01, 0.02, 0.96, 0.01] → Predicted Intent: "greeting"
├── intents.json
├── chatbot.py
├── train.py
├── model.py
├── nltk_utils.py
├── data.pth
├── README.md
Install dependencies:
pip install torch nltk
Download NLTK tokenizer models:
import nltk
nltk.download('punkt')-
Run the following to train the chatbot:
-
python train.py
-
This trains the model and saves it as data.pth.
-
After training, start chatting with the bot:
-
python chat.py
-
You'll be prompted to type a message, and the bot will respond accordingly.
{
"intents": [
{
"tag": "greeting",
"patterns": ["Hi", "Hello", "Hey?", "What's up?"],
"responses": [
"Hello there! How are you feeling today?",
"Hi! I am your wellness buddy. What's your mood right now?"
]
},
{
"tag": "anxiety",
"patterns": ["I'm feeling anxious", "I can't calm down", "panic attack"],
"responses": [
"When anxiety takes over, it helps to remind yourself that you have come through tough moments before. You are stronger than this feeling. Would you like a short motivational speech, a calm soundscape, or a gentle mental reset exercise?",
"It sounds like your thoughts are racing. That can feel scary, but it is manageable. Try to focus on your breathing for just a minute. I can play something soothing or guide you through a calm-down method if you would prefer."
]
]
}
]
}
-
Add Named Entity Recognition (NER) or Sentiment Analysis for better contextual understanding.
-
Deploy the chatbot with a web interface using Streamlit.
-
Enable logging of conversations (with consent) for analysis.
-
The chatbot may not handle out-of-scope questions effectively.
-
Responses are limited to those defined in intents.json.
- This project is licensed under the MIT License.