Skip to content

A sophisticated Natural Language Processing (NLP) system specifically designed for medical text analysis. This pipeline combines state-of-the-art NLP models to extract meaningful information from medical texts, including patient information, conditions, temporal data, and intent classification.

License

Notifications You must be signed in to change notification settings

MohamedSebaie/Medical_Task_Management_ChatBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Medical Task Management ChatBot πŸ₯

GitHub Python Maintenance

A sophisticated Natural Language Processing (NLP) system specifically designed for medical text analysis. This pipeline combines state-of-the-art NLP models to extract meaningful information from medical texts, including patient information, conditions, temporal data, and intent classification.

πŸš€ Features

Core Capabilities

  • Advanced Entity Extraction: Powered by GLiNER for accurate medical entity recognition
  • Smart Intent Classification: Zero-shot classification using BART model
  • Temporal Information Analysis: Precise extraction of dates, times, and frequencies
  • Structured Data Output: Well-organized JSON output format
  • Medical Domain Specialization: Optimized for medical terminology and context

Entity Categories

  • πŸ‘€ Patient Information

    • Names
    • Age
    • Gender
    • Patient IDs
  • πŸ₯ Medical Information

    • Conditions
    • Symptoms
    • Medications
    • Procedures
    • Tests
    • Dosages
    • Frequencies
  • πŸ“… Temporal Information

    • Dates
    • Times
    • Durations
    • Frequencies
  • 🏒 Location Information

    • Hospitals
    • Departments
    • Rooms

πŸ“‹ Requirements

System Requirements

  • Python 3.8+
  • 4GB+ RAM
  • CUDA-compatible GPU (optional, for faster processing)

Dependencies

transformers>=4.30.0
torch>=2.0.0
spacy>=3.5.0
gliner>=1.0.0
pydantic>=2.0.0
fastapi>=0.100.0
uvicorn>=0.22.0

πŸ’» Installation

  1. Clone the repository
git clone https://github.com/MohamedSebaie/Medical_Task_Management_ChatBot.git
cd Medical_Task_Management_ChatBot
  1. Create a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install required packages
pip install -r requirements.txt
  1. Install Spacy model
python -m spacy download en_core_web_sm

🎯 Quick Start

Basic Usage

from app.services.nlp_pipeline import MedicalNLPPipeline

# Initialize pipeline
nlp = MedicalNLPPipeline()

# Process text
text = "Patient John Doe, 45 years old, presents with diabetes and hypertension"
result = nlp.process_text(text)

# Access results
print(result["entities"])  # Extracted entities
print(result["intent"])    # Classified intent

API Integration

from fastapi import FastAPI
from app.services.nlp_pipeline import MedicalNLPPipeline

app = FastAPI()
nlp = MedicalNLPPipeline()

@app.post("/process")
async def process_text(text: str):
    return nlp.process_text(text)

πŸ“Š Example Output

{
    "intent": {
        "primary_intent": "add_patient",
        "confidence": 0.944
    },
    "entities": {
        "patient_info": [
            {
                "text": "John Doe",
                "type": "patient",
                "confidence": 0.995
            },
            {
                "text": "45 years old",
                "type": "age",
                "confidence": 0.990
            }
        ],
        "medical_info": [
            {
                "text": "diabetes",
                "type": "condition",
                "confidence": 0.986
            },
            {
                "text": "hypertension",
                "type": "condition",
                "confidence": 0.985
            }
        ]
    },
    "temporal_info": {
        "dates": [],
        "times": [],
        "patterns": []
    },
    "processed_at": "2024-12-20T02:38:48.669624"
}

πŸ— Architecture

Core Components

1. GLiNER Model

  • Primary entity extraction engine
  • Pre-trained on medical data
  • Advanced medical terminology handling

2. Zero-Shot Classification

  • Intent classification using BART
  • Flexible classification system
  • Multiple medical intent support

3. SpaCy Pipeline

  • Linguistic feature extraction
  • Temporal information processing
  • Text preprocessing

Processing Flow

  1. Text Input β†’ Preprocessing
  2. Parallel Processing:
    • Entity Extraction (GLiNER)
    • Intent Classification (Zero-shot)
    • Temporal Analysis (SpaCy)
  3. Result Structuring
  4. Output Generation

πŸ”§ Configuration

Environment Variables

CUDA_VISIBLE_DEVICES=0
MODEL_PATH=/path/to/models
LOG_LEVEL=INFO

Model Configuration

# config.py
DEFAULT_CONFIG = {
    "model_name": "urchade/gliner_base",
    "device": -1,  # CPU
    "batch_size": 32,
    "max_length": 512
}

Test Cases πŸ§ͺ

Example Scenarios for System Testing

1. Patient Addition & Basic Medication

Add a new patient Sarah Miller, female, 32 years old, with hypertension
Assign medication Lisinopril 10mg daily for Sarah Miller
Schedule appointment for Sarah Miller next Monday at 2 PM

2. Incorrect Medication Dosage

Add a new patient Michael Chen, male, 55 years old, with arthritis
Assign medication Methotrexate 1000mg weekly for Michael Chen
Schedule follow-up for Michael Chen in 2 weeks

3. Non-existent Medication

Add a new patient Emily Wilson, female, 28 years old, with migraine
Assign medication SuperPainAway 250mg for Emily Wilson
Book appointment for Emily Wilson tomorrow morning

4. Missing Frequency

Add a new patient Robert Brown, male, 61 years old, with high cholesterol
Assign medication Atorvastatin 40mg for Robert Brown
Schedule check-up for Robert Brown next Friday

5. Contraindicated Medication

Add a new patient Lisa Anderson, female, 35 years old, with pregnancy
Assign medication Accutane 20mg daily for Lisa Anderson
Schedule prenatal check for Lisa Anderson next week

πŸ› Troubleshooting

Common Issues

  1. GLiNER Initialization Errors

    Solution: Verify CUDA installation and model paths
    
  2. Memory Issues

    Solution: Reduce batch size or use CPU mode
    
  3. Performance Optimization

    Solution: Enable batch processing for large datasets
    

πŸ“ˆ Performance Metrics

  • Entity Recognition Accuracy: ~95%
  • Intent Classification Accuracy: ~94%
  • Processing Speed: ~100ms per text (GPU)
  • Maximum Text Length: 512 tokens

πŸ›  Development

Testing

# Run tests
pytest tests/

# Run specific test
pytest tests/test_pipeline.py -k test_entity_extraction

Code Style

# Format code
black .

# Check types
mypy .

πŸ“– Documentation

Full documentation is available in the /docs directory:

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.

πŸ™ Acknowledgments

  • GLiNER team for the base model
  • Hugging Face for transformers library
  • SpaCy for NLP utilities

πŸ“« Contact

Mohamed Sebaie - LinkedIn Profile - [email protected]

Project Link: https://https://github.com/MohamedSebaie/Medical_Task_Management_ChatBot

LinkedIn Email GitHub

⭐️ If you found this project useful, please give it a star!

About

A sophisticated Natural Language Processing (NLP) system specifically designed for medical text analysis. This pipeline combines state-of-the-art NLP models to extract meaningful information from medical texts, including patient information, conditions, temporal data, and intent classification.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published