A proof of concept repository demonstrating foundation models on MIMIC-IV Built using the Event Stream GPT library. See this tutorial in that repository for a walk through of the components of this repository!
This repository demonstrates how to use the Event Stream GPT library for foundation modeling applications. It walks through the process in an end-to-end manner over MIMIC-IV, including the following steps:
.env.example
to a file named .env
on your machine. Populate the environment
variables therein for your specific system, as defined below:PROJECT_NAME
: This is a simple string name for this project. It will be used in logging, weights and
biases, etc.PROJECT_DIR
: This is a directory to where you want output artifacts for this project to be stored
(e.g., datasets, model runs, etc.). It is used as a base path in various scripts.EVENT_STREAM_PATH
: This is the path at which you cloned the Event Stream GPT repository. It is used to
ensure that library can be used by python files in this repository.pip install rootutils
)Download the MIMIC-IV dataset. To do so, follow the instructions on PhysioNet. Note that we use MIMIC-IV version 2.0 in this work, though it may still work for later versions too. For our code, you need to set up the postgres version of the database, and this postgres database needs to be accessible in the script you run to build the dataset (detailed below).
./scripts/build_dataset.sh cohort_name=???
You can visualize the dataset with the notebooks/Visualize ESD.ipynb
notebook.
To build task dataframes, use the
notebooks/Build Task DataFrames.ipynb
notebook. Stay tuned for
future developments here where tasks can also be specified via configuration files, rather than in raw code.
To see the zero-shot task labelers for these tasks, see the task_labelers
folder.
wandb
Sweep:Run the ./scripts/launch_hyperparameter_tuning.sh
script from the
root directory of this repository with the appropriate conda env activated.
To adjust any parameter choices, modify the
hyperparameter_sweep
config file.
This script will initiate a Weights and Biases Sweep over this parameter space.
To run agents to execute the models in the sweep, run
./scripts/launch_wandb_agent.sh $WANDB_USERNAME $SWEEP_ID
, again from the
root directory of this repository with the appropriate conda env. Note that you will need to populate
$WANDB_USERNAME
and $SWEEP_ID
yourself, the latter of which is printed to the command line when you run
the sweep initiation script.
Launching a wandb agent kicks off a process which will repeatedly fetch model parameters from the sweep server and run them locally, in the environment where the agent is started. So, if you want to control this environment (e.g., have it run in a slurm job, have it only have access to a select GPU, etc.), make sure that you begin the job in the appropriate manner to do so.
You can use this template wandb report to analyze your hyperparameter tuning sweep. Simply clone the report to your project, and adjust the filters in the various tabs of the run selector in the bottom to point to your sweep ID.
You can also run sklearn baseline, from scratch supervised neural network training, or fine-tuning hyperparameter searches using the respective scripts and configs in the ESGPT library. See this tutorial for more details!
To evaluate the pre-trained models on zero-shot, forecasting-based performance, you need to take several steps:
${task_df_name}_labeler.py
:
cp task_labelers/readmission.py $DATA_DIR/task_dfs/readmission_30d_all_labeler.py
scripts/run_zero_shot_eval.sh
script.