Skip to content

8-bit-processor/Hospital-chatbot

Repository files navigation

Chatbot

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.

Features

  • 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-transformers to 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.

Project Structure

  • main.py: The main entry point of the chatbot application. It orchestrates the loading of models, training, and user interaction.
  • intents.py: Defines the qa_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 the SimilarityModel (using sentence-transformers) and the custom NeuralNetwork for intent classification.
  • neural_net_text_preprocessor.py: Provides the TextPreprocessor class 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 the punkt tokenizer.

Setup and Installation

  1. Clone the repository:

    git clone <repository_url>
    cd chatbot
  2. Create and activate a virtual environment:

    python -m venv .venv
    # On Windows:
    .venv\Scripts\activate
    # On macOS/Linux:
    source .venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt

    (The requirements.txt file has been generated for you.)

  4. Download NLTK data: The main.py and neural_net_text_preprocessor.py scripts will attempt to download the punkt tokenizer if it's not found. Ensure you have an internet connection on the first run.

Usage

To start the chatbot, run:

python main.py

The chatbot will initialize, train its neural network, and then prompt you for input. Type your queries, and type exit to end the conversation.

Extending the Chatbot

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.

Dependencies

  • sentence-transformers
  • numpy
  • nltk
  • torch (for sentence-transformers)
  • scikit-learn (for TfidfVectorizer in neural_net_text_preprocessor.py)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages