Loading repository data…
Loading repository data…
Haohao-end / repository
A medical question-answering system built on the GPT-2 language model, fine-tuned on a large corpus of doctor-patient dialogues. The system supports multi-turn conversations and provides both command-line and web-based interfaces for interaction.
A medical question-answering system built on the GPT-2 language model, fine-tuned on a large corpus of doctor-patient dialogues. The system supports multi-turn conversations and provides both command-line and web-based interfaces for interaction.
Install dependencies:
pip install -r requirements.txt
Place the training and validation text files in the data directory:
data/
├── medical_train.txt
└── medical_valid.txt
Preprocess the data (if not already done):
python data_preprocess/preprocess.py
python train.py --pretrained_model gpt2-medium
Training parameters such as batch size, learning rate, and number of epochs can be adjusted in parameter_config.py.
Command-line interaction:
python interact.py
Web interface:
python flask_predict.py
Then visit http://localhost:5000 in your browser.
Gpt2_Chatbot/
├── data/ # Training and validation data
├── data_preprocess/ # Data preprocessing scripts
│ ├── preprocess.py
│ ├── dataset.py
│ └── dataloader.py
├── save_model/ # Trained model checkpoints
├── train.py # Training script
├── interact.py # Command-line inference
├── flask_predict.py # Web service
├── app.py # Flask application
└── parameter_config.py # Hyperparameters and paths
The system uses GPT2LMHeadModel with a custom tokenizer (BertTokenizerFast) configured with [CLS] and [SEP] tokens to handle dialogue turns. Input sequences are formatted as:
[CLS] utterance1 [SEP] utterance2 [SEP] ...
Generation employs top-k sampling with repetition penalty to produce fluent and relevant responses.
| Metric | Training Set | Validation Set |
|---|---|---|
| Accuracy | 92.3% | 88.7% |
| Perplexity (PPL) | 15.2 | 18.6 |
User: What auxiliary treatments are available for Parkinson's plus syndrome?
System: Recommended approaches include: