This project implements a Python-based chatbot designed to assist with medical-related inquiries. It leverages a hybrid approach combining semantic similarity and a custom-built neural network for natural language understanding.
- Intent Recognition: Identifies user intentions such as scheduling appointments (general and specialty), requesting medical imaging, medical supplies, medication renewals, and general information.
- Semantic Search: Utilizes
sentence-transformersto find the most semantically similar predefined questions to user input, enabling robust understanding of varied phrasing. - Neural Network Classifier: Employs a custom-implemented feed-forward neural network for intent classification, trained on embeddings generated by the semantic model.
- Text Preprocessing: Includes a dedicated module for cleaning and normalizing text data, preparing it for machine learning models.
- Extensible Knowledge Base: Intents and responses are defined in
intents.py, making it easy to add or modify the chatbot's capabilities.
main.py: The main entry point of the chatbot application. It orchestrates the loading of models, training, and user interaction.intents.py: Defines theqa_pairs(question-answer/action pairs) that serve as the chatbot's knowledge base and training data.similarity_model_and_neural_net.py: Contains the core implementations of theSimilarityModel(usingsentence-transformers) and the customNeuralNetworkfor intent classification.neural_net_text_preprocessor.py: Provides theTextPreprocessorclass for cleaning, normalizing, and vectorizing text data.__pycache__/: Directory for Python bytecode cache..venv/: Virtual environment for managing project dependencies.nltk_data/: Directory for NLTK (Natural Language Toolkit) data, specifically thepunkttokenizer.
-
Clone the repository:
git clone <repository_url> cd chatbot
-
Create and activate a virtual environment:
python -m venv .venv # On Windows: .venv\Scripts\activate # On macOS/Linux: source .venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
(The
requirements.txtfile has been generated for you.) -
Download NLTK data: The
main.pyandneural_net_text_preprocessor.pyscripts will attempt to download thepunkttokenizer if it's not found. Ensure you have an internet connection on the first run.
To start the chatbot, run:
python main.pyThe chatbot will initialize, train its neural network, and then prompt you for input. Type your queries, and type exit to end the conversation.
To add new intents or modify existing ones, edit the qa_pairs list in intents.py. After making changes, retrain the model by running main.py.
sentence-transformersnumpynltktorch(forsentence-transformers)scikit-learn(forTfidfVectorizerinneural_net_text_preprocessor.py)