Development Status :: 3 - Alpha
Copyright (c) 2023 MinWoo Park
Be careful when cloning this repository: It contains large NLP model weight. (>0.45GB,
git-lfs
)
If you want to clone without git-lfs, use this command beforegit clone
. The bandwidth provided by git-lfs for free is only 1GB per month, so there is almost no chance that a 0.45GB git-lfs download will work. So please download it manually.
git lfs install --skip-smudge &
export GIT_LFS_SKIP_SMUDGE=1
Since the advent of Chat GPT-4, there have been significant changes in the field. Nevertheless, Chat GPT-2 and Chat GPT-3 continue to be effective in specific domains as large-scale auto-regressive natural language processing models. This repository aims to qualitatively compare the performance of Chat GPT-2 and Chat GPT-4 in the medical domain, and estimate the resources and costs needed for Chat GPT-2 fine-tuning to reach the performance level of Chat GPT-4. Additionally, it seeks to assess how well up-to-date information can be incorporated and applied.
Although a few years behind GPT-4, the ultimate goal of this repository is to minimize costs and resources required for updating and obtaining usable weights after acquiring them. We plan to design experiments for few-shot learning in large-scale natural language processing models and test existing research. Please note that this repository is intended for research and practice purposes only, and we do not assume responsibility for any usage.
Additionally, this repository ultimately aims to achieve similar qualitative and quantitative performance as GPT-4 in certain domain areas through model lightweighting and optimization. For more details, please refer to my technical blog.
Keywords: GPT-2, Streamlit, Vector DB, Medical
- GPT-BERT Medical QA Chatbot
- Contents
- Quick Start
- Docker
- Dataset
- Pretrained Models
- Cites
- How to cite this project
- Tips
- References
You can chat with the chatbot through the command-line interface using the following command.
git clone https://github.com/DSDanielPark/medical-qa-bert-chatgpt.git
cd medical-qa-bert-chatgpt
pip install -e .
python main.py
A simple application can be implemented with streamlit as follows:
git clone https://github.com/DSDanielPark/medical-qa-bert-chatgpt.git
cd medical-qa-bert-chatgpt
pip install -e .
streamlit run chatbot.py
Check Docker Hub: https://hub.docker.com/r/parkminwoo91/medical-chatgpt-streamlit-v1
Docker version 20.10.24, build 297e128
git clone https://github.com/DSDanielPark/medical-qa-bert-chatgpt.git
cd medical-qa-bert-chatgpt
docker build -t chatgpt .
docker run -p 8501:8501 -v ${PWD}/:/usr/src/app/data chatgpt # There is no cost to pay for git-lfs, just download and mount it.
Since git clone downloads what needs to be downloaded from git-lfs, the volume must be mounted as follows. Or modify chatbot/config.py
to mount to a different folder.
You can also implement it in a docker container like this:
git clone https://github.com/DSDanielPark/medical-qa-bert-chatgpt.git
cd medical-qa-bert-chatgpt
docker compose up
docker pull parkminwoo91/medical-chatgpt-streamlit-v1:latest
docker compose up
Streamlit is very convenient and quick to view landing pages, but lacks design flexibility and lacks control over the application layout. Also, if your application or data set is large, the entire source code will be re-run on every new change or interaction, so application flow can cause speed issues. That landing page will be replaced by flask with further optimizations. Streamlit chatbot has been recently developed, so it seems difficult to have the meaning of a simple demo now.
Pre-trained model weight needed
Downloading datasets and model weights through the Hugging Face Hub is executed, but for some TensorFlow models, you need to manually download and place them at the top of the project folder. The information for the downloadable model is as follows, and you can visit my Hugging Face repository to check it.
modules/chatbot/config.py
class Config:
chat_params = {"gpt_tok":"danielpark/medical-QA-chatGPT2-tok-v1",
"tf_gpt_model":"danielpark/medical-QA-chatGPT2-v1",
"bert_tok":"danielpark/medical-QA-BioRedditBERT-uncased-v1",
"tf_q_extractor": "question_extractor_model",
"data":"danielpark/MQuAD-v1",
"max_answer_len": 20,
"isEval": False,
"runDocker":True, # Exceeds the bandwidth of git-lfs, mounts to local storage to find folder location for free use. I use the python utifunction package.
"container_mounted_folder_path": "/usr/src/app/data"}
The Medical Question and Answering dataset(MQuAD) has been refined, including the following datasets. You can download it through the Hugging Face dataset. Use the DATASETS method as follows. You can find more infomation at here.
from datasets import load_dataset
dataset = load_dataset("danielpark/MQuAD-v1")
Medical Q/A datasets gathered from the following websites.
- eHealth Forum
- iCliniq
- Question Doctors
- WebMD Data was gathered at the 5th of May 2017.
Hugging face pretrained models
- GPT2 pretrained model [download]
- GPT2 tokenizer [download]
- BIO Reddit BERT pretrained model [download]
TensorFlow models for extracting context from QA. I temporarily share TensorFlow model weights through my personal Google Drive.
- Q extractor [download]
- A extractor [download]
@misc {hf_canonical_model_maintainers_2022,
author = { {HF Canonical Model Maintainers} },
title = { gpt2 (Revision 909a290) },
year = 2022,
url = { https://huggingface.co/gpt2 },
doi = { 10.57967/hf/0039 },
publisher = { Hugging Face }
}
@misc{vaswani2017attention,
title = {Attention Is All You Need},
author = {Ashish Vaswani and Noam Shazeer and Niki Parmar and Jakob Uszkoreit and Llion Jones and Aidan N. Gomez and Lukasz Kaiser and Illia Polosukhin},
year = {2017},
eprint = {1706.03762},
archivePrefix = {arXiv},
primaryClass = {cs.CL}
}
@misc{medical_qa_bert_chatgpt,
title = {Medical QA Bert Chat GPT},
author = {Minwoo Park},
year = {2023},
url = {https://github.com/dsdanielpark/medical-qa-bert-chatgpt},
}
The MQuAD provides embedded question and answer arrays in string format, so it is recommended to convert the string-formatted arrays into float format as follows. This measure has been applied to save resources and time used for embedding.
from datasets import load_dataset
from utilfunction import col_convert
import pandas as pd
qa = load_dataset("danielpark/MQuAD-v1", "csv")
df_qa = pd.DataFrame(qa['train'])
df_qa = col_convert(df_qa, ['Q_FFNN_embeds', 'A_FFNN_embeds'])
Since the nvidia GPU driver fully supports wsl2, the method of supporting TensorFlow's gpu has changed. Please refer to the following pages to install it.
I have trained the model for 2 epochs using the mentioned dataset, utilizing 40 computing units from Google Colab Pro. The training was conducted for about 12 hours using an A100 multi-GPU with 56 GB of RAM or more. In the case of relatively simple question extractor or answer extractor models that perform summarization and indexing, the time required for training is minimal, and they are included in the inference module to evaluate whether the learning has been carried out appropriately. If the model is only responding to simple questions, the inference module should be changed;
however, it is currently included in the evaluation unnecessarily to check performance and calculate the time and resources consumed. I plan to update this information once sufficient training is completed (by incorporating additional datasets), or when funding for experiments and resources to derive adequate learning.
- Training 2 Epoch with
MQuAD
dataset, Comsuming 40 Google Colab Pro Computing unit, Take 12 hours using an A100 multi-GPU with 56 GB of RAM or more.
- Paper: Attention is All You Need
- Paper: BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
- Paper: GPT-2: Language Models are Unsupervised Multitask Learners
- Paper: Language Models are Unsupervised Multitask Learners
- GitHub Repository: DocProduct
- Applied AI Course
- Medium Article: Medical Chatbot using BERT and GPT-2
- GitHub Repository: Medical Question Answer Data
- Hugging Face Model Hub: GPT-2
- GitHub Repository: Streamlit Chat
- Streamlit Documentation
- Streamlit Tutorial: Deploying Streamlit Apps with Docker
- ChatterBot Documentation
- Blog Post: 3 Steps to Fix App Memory Leaks
- Blog Post: Common App Problems & Resource Limits
- GitHub Gist: Streamlit Chatbot Example (Lightweight and optimized)
- Databricks Blog: Democratizing Magic: ChatGPT and Open Models
- GitHub Repository: Pyllama