Source code of the research on differential diagnostic (DDX) record generation.
- python>=3.8
- transformers==4.44.0
- tiktoken
- torch
- pandas
- openpyxl
- gensim
- rouge-chinese
- bert-score
- nltk
- jieba
- tqdm
- openai
- numpy
-
GENERATION The files
generate_response_onLLM.ipynbandgenerate_response_offLLM.pyare used to prompt online and offline LLMs to generate differential diagnostic records. Note thatgenerate_response_offLLM.pyuses an available GPU (an NVIDIA GTX 3090 GPU in our experiments) to prompt the offline LLMGLM-4-9bto generate differential diagnostic records.python generate_response_onLLM.py
The execution of
generate_response_offLLM.ipynbhas no limis to machines while it requires an available OpenAI API key. -
EVALUATION The generated notes are evaluated in
evaluation_allLLM.ipynb. The datasets are analyzed indataset_stat.ipynb.
-
Model preparations.
- Prepare an available OpenAI API key.
- Download the model GLM-4-9b and bert-base-chinese from Huggingface to the folder
./models. (If you want to load bert-base-chinese from your local path, you should modify the codes ofclass BERTScorein the bert-score package) - Download the trained skip-gram (word embedding) model from Google Drive or BaiduNetDisk to the folder
./models. - Modify the model paths in the programs.
-
Data preparations.
- The synthetic dataset is included in
data_public.xlsx. - If you are using your own data, the dataset paths are required to be modified in
utils/generate_glm_cuda.pyandutils/generate_gpt.py.
- The synthetic dataset is included in
-
Generation. Execute the cells in
generate_response_onLLM.ipynb.Notice: the generation takes much time and requires paid api. For convenience, we provide the generation results in the folder
./output/so that you can directly execute the evaluation codes. -
Evaluation.
- The results of LLM response evaluation are shown in the file
evaluation_allLLM.ipynb. You can also execute the cells in it. - Data statistics are shown in the file
dataset_stat.ipynb. You can also execute the cells in it to analyze the dataset.
- The results of LLM response evaluation are shown in the file
For more details about the functions called during generation and evaluation, you can read the files in the folder ./utils.
- The file
eval.pycontains all the evaluation metrics in the experiments. - The file
generate_gpt.pyload the dataset and provides the interfaces to call online GPT models. - The file
generate_glm_cuda.pyis similar togenearte_gpt.py, but it should be executed on the machine with GPU and the GLM-4-9b model.