Computer Assisted Verbal Autopsy: Comparing Large Language Models to Physicians for Assigning Causes to 6939 Deaths in Sierra Leone from 2019-2022
This repository contains code to reproduce findings from the paper. The code requires R to run InterVA-5 and InSilicoVA models, as well as Python and an OpenAI API key to run GPT models. Plots are generated using R, while diagrams are created using draw.io.
Folders in this repository are organized in the following manner:
- archive: past versions of files with large differences
- bin: scripts meant to be run on the command line
- data: anonymized public datasets, and their data dictionaries if available
- src: code and files for models, plots, and diagrams
- manuscript: files for manuscript with related files and figures
Files of interest:
- data/healsl_rd1to2_cod_v1.csv: Data of cause of death coding results from models and physicians for all verbal autopsy records
- src/plots.Rmd: Code for generating figure plots using R
- Install git
- Install Python 3
- Install R and RStudio
- Install draw.io (to edit diagrams under src/figures)
- If on Windows, install RTools
- Open a command line interface and clone this repository
git clone https://github.com/cghr-toronto/wen-et-al-2025-cava - Navigate into the cloned folder
cd wen-et-al-2025-cava - Create a tmp folder for temporary files not tracked by git
mkdir tmp- This folder is used for model input and output data
- Intermediate files from running code may also be stored here
- The python environment also exists under
tmp/venv
- Setup the python environment using scripts in the bin folder with the following command:
- MacOS/Linux:
source bin/setup_python.sh - Windows:
bin\setup_python
- MacOS/Linux:
- Install pycrossva v0.97 in Python with the following commands:
- MacOS/Linux:
source bin/activatethensource bin/setup_pycrossva.sh - Windows:
bin\activatethenbin\setup_pycrossva
- MacOS/Linux:
- Open RStudio, and install the required R packages with the src/install.R script in the R terminal:
source("src/install.R") - All required software should now be installed
- Email the authors for access to the following files:
icd10_cghr10_v1.csvhealsl_rd1_adult_v1.csvhealsl_rd1_adult_age_v1.csvhealsl_rd1_who_adult_v1.csvhealsl_rd1_adult_narrative_v1.csvhealsl_rd2_adult_v1.csvhealsl_rd2_adult_age_v1.csvhealsl_rd2_who_adult_v1.csvhealsl_rd2_adult_narrative_v1.csvhealsl_rd1_child_v1.csvhealsl_rd1_child_age_v1.csvhealsl_rd1_who_child_v1.csvhealsl_rd1_child_narrative_v1.csvhealsl_rd2_child_v1.csvhealsl_rd2_child_age_v1.csvhealsl_rd2_who_child_v1.csvhealsl_rd2_child_narrative_v1.csvhealsl_rd1_neo_v1.csvhealsl_rd1_neo_age_v1.csvhealsl_rd1_who_neo_v1.csvhealsl_rd1_neo_narrative_v1.csvhealsl_rd2_neo_v1.csvhealsl_rd2_neo_age_v1.csvhealsl_rd2_who_neo_v1.csvhealsl_rd2_neo_narrative_v1.csvicd10_cghr10_v1.csv
- Put all the files above into the
tmpfolder - Run InterVA-5 and InSilicoVA:
- Open a command line interface and activate python:
- MacOS/Linux:
source bin/activate.sh - Windows:
bin\activate
- MacOS/Linux:
- Run pycrossva to prepare input data
python src/models/pycrossva.py- This creates prepared model input data for both InSilicoVA and InterVA-5 in the
tmpfolder
- This creates prepared model input data for both InSilicoVA and InterVA-5 in the
- Double click the file src/src.Rproj to open RStudio
- In RStudio, run InterVA-5 in the R terminal
source src/models/interva5.R- This creates InterVA-5 outputs with
_interva5_in the file name
- This creates InterVA-5 outputs with
- In RStudio, run InSilicoVA in the R terminal
source src/models/insilicova.R- This creates InSilicoVA outputs with
_insilicova_in the file name
- This creates InSilicoVA outputs with
- Both model outputs should now be available in the
tmpfolder
- Open a command line interface and activate python:
- Run GPT-3.5, GPT-4, and GPT-5:
- Open a command line interface and activate python:
- MacOS/Linux:
source bin/activate.sh - Windows:
bin\activate
- MacOS/Linux:
- Create a
.envfile atwen-et-al-2025-cava/.envand add a lineOPEN_API_KEY=<your_secret_api_key>- Replace
<your_secret_api_key>with your OpenAI API Key - CAUTION: Do not share this file or your key with anyone else, keep it safe from public access
- Replace
- Run GPT-3.5 in Python
python src/models/gpt3.py- This creates GPT-3.5 outputs and intermediate files with
_gpt3_in the file name
- This creates GPT-3.5 outputs and intermediate files with
- Run GPT-4 in Python
python src/models/gpt4.py- This creates GPT-4 outputs and intermediate files with
_gpt4_in the file name
- This creates GPT-4 outputs and intermediate files with
- Run GPT-5 in Python
python src/models/gpt5.py- This creates GPT-4 outputs and intermediate files with
_gpt5_in the file name
- This creates GPT-4 outputs and intermediate files with
- All model outputs should now be available in the
tmpfolder - Note: If you encounter an error, try re-installing the
openailibrary in the Python virtual environment:- Make sure the environment is activated:
source bin/activate(MacOS/Linux) orbin\activate - Then uninstall the
openailibrary:pip uninstall openai - Install it again:
pip install openai
- Make sure the environment is activated:
- Open a command line interface and activate python:
- Gather all model outputs:
- Double click the file src/src.Rproj to open RStudio
- In RStudio, open src/data.Rmd
- Combine all outputs by running this file using the
Runbutton drop down and selectingRun All - This produces the final anonymous output data for plotting under data/healsl_rd1to2_cod_v1.csv
- Produce plots:
- Double click the file src/src.Rproj to open RStudio
- In RStudio, open src/plots.Rmd
- Generate all plots using the
Runbutton drop down and selectingRun All - This produces several supplementary tables in the data folder and the plots under manuscript/figures
Richard Wen rrwen.dev@gmail.com for any code or technical related issues.