cehrbert 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cehrbert might be problematic. Click here for more details.
- cehrbert-1.1.0/.github/workflows/tests.yml +39 -0
- cehrbert-1.1.0/.gitignore +38 -0
- cehrbert-1.1.0/.pre-commit-config.yaml +83 -0
- cehrbert-1.1.0/LICENSE +21 -0
- cehrbert-1.1.0/PKG-INFO +217 -0
- cehrbert-1.1.0/README.md +160 -0
- cehrbert-1.1.0/db_properties.ini +5 -0
- cehrbert-1.1.0/deepspeed_configs/zero1.json +22 -0
- cehrbert-1.1.0/deepspeed_configs/zero2.json +26 -0
- cehrbert-1.1.0/deepspeed_configs/zero3.json +30 -0
- cehrbert-1.1.0/full_grid_search_config.ini +11 -0
- cehrbert-1.1.0/images/cehr_bert_architecture.png +0 -0
- cehrbert-1.1.0/images/tokenization_att_generation.png +0 -0
- cehrbert-1.1.0/pyproject.toml +87 -0
- cehrbert-1.1.0/sample_configs/hf_cehrbert_finetuning_runner_config.yaml +53 -0
- cehrbert-1.1.0/sample_configs/hf_cehrbert_pretrain_runner_config.yaml +53 -0
- cehrbert-1.1.0/sample_configs/hf_cehrbert_pretrain_runner_meds_config.yaml +53 -0
- cehrbert-1.1.0/sample_data/finetune/full/fake_data.parquet +0 -0
- cehrbert-1.1.0/sample_data/finetune/test/fake_data.parquet +0 -0
- cehrbert-1.1.0/sample_data/finetune/train/fake_data.parquet +0 -0
- cehrbert-1.1.0/sample_data/pretrain/patient_sequence.parquet +0 -0
- cehrbert-1.1.0/setup.cfg +4 -0
- cehrbert-1.1.0/simple_grid_search_config.ini +8 -0
- cehrbert-1.1.0/src/cehrbert/__init__.py +12 -0
- cehrbert-1.1.0/src/cehrbert/config/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/config/grid_search_config.py +13 -0
- cehrbert-1.1.0/src/cehrbert/config/output_names.py +9 -0
- cehrbert-1.1.0/src/cehrbert/const/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/const/common.py +28 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/data_classes.py +33 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/data_generator_base.py +470 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/graph_sample_method.py +75 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/hf_data_generator/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/hf_data_generator/hf_dataset.py +133 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/hf_data_generator/hf_dataset_collator.py +229 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/hf_data_generator/hf_dataset_mapping.py +458 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/hf_data_generator/meds_to_cehrbert_conversion_rules/__init__.py +2 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/hf_data_generator/meds_to_cehrbert_conversion_rules/meds_to_cehrbert_base.py +137 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/hf_data_generator/meds_to_cehrbert_conversion_rules/meds_to_cehrbert_micmic4.py +53 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/hf_data_generator/meds_utils.py +398 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/learning_objective.py +1173 -0
- cehrbert-1.1.0/src/cehrbert/data_generators/tokenizer.py +131 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/evaluation.py +354 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/evaluation_parameters.py +28 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/evaluation_parse_args.py +255 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/model_evaluators/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/model_evaluators/bert_model_evaluators.py +249 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/model_evaluators/frequency_model_evaluators.py +146 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/model_evaluators/hierarchical_bert_evaluators.py +283 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/model_evaluators/model_evaluators.py +91 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/model_evaluators/sequence_model_evaluators.py +444 -0
- cehrbert-1.1.0/src/cehrbert/evaluations/transfer_learning_evaluation.py +13 -0
- cehrbert-1.1.0/src/cehrbert/keras_transformer/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/keras_transformer/bert.py +109 -0
- cehrbert-1.1.0/src/cehrbert/keras_transformer/extras.py +143 -0
- cehrbert-1.1.0/src/cehrbert/keras_transformer/position.py +55 -0
- cehrbert-1.1.0/src/cehrbert/med_extension/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/med_extension/schema_extension.py +36 -0
- cehrbert-1.1.0/src/cehrbert/models/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/models/bert_models.py +169 -0
- cehrbert-1.1.0/src/cehrbert/models/bert_models_visit_prediction.py +208 -0
- cehrbert-1.1.0/src/cehrbert/models/evaluation_models.py +649 -0
- cehrbert-1.1.0/src/cehrbert/models/hf_models/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/models/hf_models/config.py +230 -0
- cehrbert-1.1.0/src/cehrbert/models/hf_models/hf_cehrbert.py +486 -0
- cehrbert-1.1.0/src/cehrbert/models/hf_models/hf_modeling_outputs.py +219 -0
- cehrbert-1.1.0/src/cehrbert/models/hf_models/tokenization_hf_cehrbert.py +349 -0
- cehrbert-1.1.0/src/cehrbert/models/hf_models/tokenization_utils.py +49 -0
- cehrbert-1.1.0/src/cehrbert/models/hierachical_bert_model_v2.py +380 -0
- cehrbert-1.1.0/src/cehrbert/models/hierachical_phenotype_model_new.py +433 -0
- cehrbert-1.1.0/src/cehrbert/models/layers/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/models/layers/custom_layers.py +941 -0
- cehrbert-1.1.0/src/cehrbert/models/layers/hierarchical_custom_layers.py +201 -0
- cehrbert-1.1.0/src/cehrbert/models/loss_schedulers.py +56 -0
- cehrbert-1.1.0/src/cehrbert/models/parse_args.py +430 -0
- cehrbert-1.1.0/src/cehrbert/runners/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/runners/hf_cehrbert_finetune_runner.py +337 -0
- cehrbert-1.1.0/src/cehrbert/runners/hf_cehrbert_pretrain_runner.py +275 -0
- cehrbert-1.1.0/src/cehrbert/runners/hf_runner_argument_dataclass.py +288 -0
- cehrbert-1.1.0/src/cehrbert/runners/runner_util.py +339 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/atrial_fibrillation.py +44 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/cabg.py +71 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/coronary_artery_disease.py +88 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/covid.py +42 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/covid_inpatient.py +83 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/death.py +45 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/heart_failure.py +422 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/ischemic_stroke.py +44 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/last_visit_discharged_home.py +34 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/query_builder.py +153 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/spark_app_base.py +745 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/type_two_diabietes.py +170 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/cohorts/ventilation.py +22 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/decorators/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/decorators/patient_event_decorator.py +759 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/generate_concept_similarity_table.py +423 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/generate_hierarchical_bert_training_data.py +238 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/generate_included_concept_list.py +116 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/generate_information_content.py +131 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/generate_required_labs.py +109 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/generate_training_data.py +343 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/legacy/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/legacy/mortality.py +183 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/afib_ischemic_stroke.py +13 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/cad_cabg_cohort.py +18 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/cad_hf_cohort.py +18 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/copd_readmission.py +69 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/covid_death.py +13 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/covid_ventilation.py +13 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/discharge_home_death.py +22 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/hf_readmission.py +79 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/hospitalization.py +98 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/hospitalization_mortality.py +81 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/prediction_cohorts/t2dm_hf_cohort.py +18 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/spark_parse_args.py +350 -0
- cehrbert-1.1.0/src/cehrbert/spark_apps/sql_templates.py +42 -0
- cehrbert-1.1.0/src/cehrbert/tools/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/tools/download_omop_tables.py +131 -0
- cehrbert-1.1.0/src/cehrbert/trainers/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/trainers/model_trainer.py +308 -0
- cehrbert-1.1.0/src/cehrbert/trainers/train_cehr_bert.py +181 -0
- cehrbert-1.1.0/src/cehrbert/utils/__init__.py +0 -0
- cehrbert-1.1.0/src/cehrbert/utils/checkpoint_utils.py +198 -0
- cehrbert-1.1.0/src/cehrbert/utils/logging_utils.py +16 -0
- cehrbert-1.1.0/src/cehrbert/utils/model_utils.py +366 -0
- cehrbert-1.1.0/src/cehrbert/utils/spark_utils.py +1404 -0
- cehrbert-1.1.0/src/cehrbert.egg-info/PKG-INFO +217 -0
- cehrbert-1.1.0/src/cehrbert.egg-info/SOURCES.txt +156 -0
- cehrbert-1.1.0/src/cehrbert.egg-info/dependency_links.txt +1 -0
- cehrbert-1.1.0/src/cehrbert.egg-info/entry_points.txt +3 -0
- cehrbert-1.1.0/src/cehrbert.egg-info/requires.txt +44 -0
- cehrbert-1.1.0/src/cehrbert.egg-info/top_level.txt +1 -0
- cehrbert-1.1.0/tests/__init__.py +0 -0
- cehrbert-1.1.0/tests/integration_tests/__init__.py +0 -0
- cehrbert-1.1.0/tests/integration_tests/runners/__init__.py +0 -0
- cehrbert-1.1.0/tests/integration_tests/runners/hf_cehrbert_pretrain_runner_test.py +54 -0
- cehrbert-1.1.0/tests/integration_tests/trainers/__init__.py +0 -0
- cehrbert-1.1.0/tests/integration_tests/trainers/train_cehr_bert_test.py +65 -0
- cehrbert-1.1.0/tests/unit_tests/__init__.py +0 -0
- cehrbert-1.1.0/tests/unit_tests/data_generators/__init__.py +0 -0
- cehrbert-1.1.0/tests/unit_tests/data_generators/bert_masked_language_modeling_learning_objective_test.py +112 -0
- cehrbert-1.1.0/tests/unit_tests/data_generators/hf_data_generator/__init__.py +0 -0
- cehrbert-1.1.0/tests/unit_tests/data_generators/hf_data_generator/hf_generate_start_end_index_mapping_test.py +61 -0
- cehrbert-1.1.0/tests/unit_tests/data_generators/hf_data_generator/hf_masked_language_modeling_mapping_test.py +67 -0
- cehrbert-1.1.0/tests/unit_tests/data_generators/hf_data_generator/hf_med_to_cehrbert_mapping_test.py +313 -0
- cehrbert-1.1.0/tests/unit_tests/data_generators/hf_data_generator/hf_sort_patient_sequence_dataset_mapping_test.py +86 -0
- cehrbert-1.1.0/tests/unit_tests/data_generators/hf_data_generator/meds_utils_test.py +23 -0
- cehrbert-1.1.0/tests/unit_tests/data_generators/visit_prediction_learning_objective_test.py +57 -0
- cehrbert-1.1.0/tests/unit_tests/models/__init__.py +0 -0
- cehrbert-1.1.0/tests/unit_tests/models/concept_value_decoder_layer_test.py +43 -0
- cehrbert-1.1.0/tests/unit_tests/models/hf_models/__init__.py +0 -0
- cehrbert-1.1.0/tests/unit_tests/models/hf_models/hf_cehrbert_test.py +94 -0
- cehrbert-1.1.0/tests/unit_tests/models/hf_models/tokenization_hf_cehrbert_test.py +68 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
|
3
|
+
|
|
4
|
+
name: Tests
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ "main" ]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: [ "main" ]
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
build:
|
|
17
|
+
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v3
|
|
22
|
+
- name: Set up Python 3.10.0
|
|
23
|
+
uses: actions/setup-python@v3
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.10"
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: |
|
|
28
|
+
python -m pip install --upgrade pip
|
|
29
|
+
pip install flake8 pytest
|
|
30
|
+
pip install -e .
|
|
31
|
+
- name: Lint with flake8
|
|
32
|
+
run: |
|
|
33
|
+
# stop the build if there are Python syntax errors or undefined names
|
|
34
|
+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
35
|
+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
|
36
|
+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
|
37
|
+
- name: Test with pytest
|
|
38
|
+
run: |
|
|
39
|
+
PYTHONPATH=./: pytest
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
.idea/
|
|
3
|
+
.vscode/
|
|
4
|
+
venv*
|
|
5
|
+
dist/*
|
|
6
|
+
|
|
7
|
+
*ipynb_checkpoints/
|
|
8
|
+
*h5
|
|
9
|
+
*logs
|
|
10
|
+
*nohup.out
|
|
11
|
+
*ipynb
|
|
12
|
+
|
|
13
|
+
*__pycache__/
|
|
14
|
+
.eggs/
|
|
15
|
+
*.dat
|
|
16
|
+
.metastore_db/
|
|
17
|
+
|
|
18
|
+
src/cehr-bert/evaluations/hospitalization_baseline.py
|
|
19
|
+
src/cehr-bert/evaluations/hospitalization_prediction-new-data-generator.py
|
|
20
|
+
hospitalization_baseline.py
|
|
21
|
+
hospitalization_prediction-new-data-generator.py
|
|
22
|
+
build/
|
|
23
|
+
concept_embeddings.egg-info/
|
|
24
|
+
|
|
25
|
+
src/cehr-bert/runner/*yaml
|
|
26
|
+
|
|
27
|
+
*.out
|
|
28
|
+
*.egg-info/
|
|
29
|
+
|
|
30
|
+
cehr_transformers.egg-info/dependency_links.txt
|
|
31
|
+
cehr_transformers.egg-info/PKG-INFO
|
|
32
|
+
cehr_transformers.egg-info/requires.txt
|
|
33
|
+
cehr_transformers.egg-info/SOURCES.txt
|
|
34
|
+
cehr_transformers.egg-info/top_level.txt
|
|
35
|
+
|
|
36
|
+
test_data
|
|
37
|
+
test_dataset_prepared
|
|
38
|
+
test*results
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# For documentation on pre-commit usage, see https://pre-commit.com/
|
|
2
|
+
# This file should be updated quarterly by a developer running `pre-commit autoupdate`
|
|
3
|
+
# with changes added and committed.
|
|
4
|
+
# This will run all defined formatters prior to adding a commit.
|
|
5
|
+
default_language_version:
|
|
6
|
+
python: python3 # or python3.10 to set a specific default version
|
|
7
|
+
|
|
8
|
+
repos:
|
|
9
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
10
|
+
rev: v4.6.0
|
|
11
|
+
hooks:
|
|
12
|
+
- id: check-yaml
|
|
13
|
+
- id: end-of-file-fixer
|
|
14
|
+
- id: trailing-whitespace
|
|
15
|
+
|
|
16
|
+
- repo: https://github.com/DanielNoord/pydocstringformatter
|
|
17
|
+
rev: 'v0.7.3'
|
|
18
|
+
hooks:
|
|
19
|
+
- id: pydocstringformatter
|
|
20
|
+
|
|
21
|
+
- repo: https://github.com/PyCQA/autoflake
|
|
22
|
+
rev: v2.2.0
|
|
23
|
+
hooks:
|
|
24
|
+
- id: autoflake
|
|
25
|
+
|
|
26
|
+
- repo: https://github.com/psf/black
|
|
27
|
+
rev: '24.1.1'
|
|
28
|
+
hooks:
|
|
29
|
+
- id: black
|
|
30
|
+
# It is recommended to specify the latest version of Python
|
|
31
|
+
# supported by your project here, or alternatively use
|
|
32
|
+
# pre-commit's default_language_version, see
|
|
33
|
+
# https://pre-commit.com/#top_level-default_language_version
|
|
34
|
+
# Pre-commit hook info from: https://black.readthedocs.io/en/stable/integrations/source_version_control.html
|
|
35
|
+
# Editor integration here: https://black.readthedocs.io/en/stable/integrations/editors.html
|
|
36
|
+
|
|
37
|
+
- repo: https://github.com/adamchainz/blacken-docs
|
|
38
|
+
rev: "v1.12.1" # replace with latest tag on GitHub
|
|
39
|
+
hooks:
|
|
40
|
+
- id: blacken-docs
|
|
41
|
+
additional_dependencies:
|
|
42
|
+
- black>=22.12.0
|
|
43
|
+
|
|
44
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
45
|
+
rev: 'v4.5.0'
|
|
46
|
+
hooks:
|
|
47
|
+
- id: trailing-whitespace
|
|
48
|
+
exclude: .git/COMMIT_EDITMSG
|
|
49
|
+
- id: end-of-file-fixer
|
|
50
|
+
exclude: .git/COMMIT_EDITMSG
|
|
51
|
+
- id: detect-private-key
|
|
52
|
+
- id: debug-statements
|
|
53
|
+
- id: check-json
|
|
54
|
+
- id: pretty-format-json
|
|
55
|
+
- id: check-yaml
|
|
56
|
+
- id: name-tests-test
|
|
57
|
+
- id: requirements-txt-fixer
|
|
58
|
+
|
|
59
|
+
- repo: https://github.com/pre-commit/pygrep-hooks
|
|
60
|
+
rev: 'v1.10.0'
|
|
61
|
+
hooks:
|
|
62
|
+
- id: python-no-eval
|
|
63
|
+
- id: python-no-log-warn
|
|
64
|
+
- id: python-use-type-annotations
|
|
65
|
+
|
|
66
|
+
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
|
67
|
+
rev: v1.5.4
|
|
68
|
+
hooks:
|
|
69
|
+
- id: remove-crlf
|
|
70
|
+
- id: remove-tabs # defaults to: 4
|
|
71
|
+
exclude: .git/COMMIT_EDITMSG
|
|
72
|
+
|
|
73
|
+
- repo: https://github.com/PyCQA/isort.git
|
|
74
|
+
rev: 5.13.2
|
|
75
|
+
hooks:
|
|
76
|
+
- id: isort
|
|
77
|
+
args: [ "--profile", "black" ]
|
|
78
|
+
|
|
79
|
+
- repo: https://github.com/PyCQA/bandit
|
|
80
|
+
rev: '1.7.7'
|
|
81
|
+
hooks:
|
|
82
|
+
- id: bandit
|
|
83
|
+
args: ["--skip", "B101,B106,B107,B301,B311,B105,B608,B403"]
|
cehrbert-1.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Department of Biomedical Informatics
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
cehrbert-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cehrbert
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: CEHR-BERT: Incorporating temporal information from structured EHR data to improve prediction tasks
|
|
5
|
+
Author-email: Chao Pang <chaopang229@gmail.com>, Xinzhuo Jiang <xj2193@cumc.columbia.edu>, Krishna Kalluri <kk3326@cumc.columbia.edu>, Nishanth Parameshwar Pavinkurve <np2689@cumc.columbia.edu>, Karthik Natarajan <kn2174@cumc.columbia.edu>
|
|
6
|
+
License: MIT License
|
|
7
|
+
Project-URL: Homepage, https://github.com/cumc-dbmi/cehr-bert
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.10.0
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: dask==2024.1.1
|
|
17
|
+
Requires-Dist: dask[dataframe]==2024.1.1
|
|
18
|
+
Requires-Dist: datasets==2.16.1
|
|
19
|
+
Requires-Dist: evaluate==0.4.1
|
|
20
|
+
Requires-Dist: fast-ml==3.68
|
|
21
|
+
Requires-Dist: fastparquet==0.8.1
|
|
22
|
+
Requires-Dist: femr==0.2.0
|
|
23
|
+
Requires-Dist: Jinja2==3.1.3
|
|
24
|
+
Requires-Dist: meds==0.3.3
|
|
25
|
+
Requires-Dist: meds_reader==0.1.1
|
|
26
|
+
Requires-Dist: networkx==3.2.1
|
|
27
|
+
Requires-Dist: numpy==1.24.3
|
|
28
|
+
Requires-Dist: packaging==23.2
|
|
29
|
+
Requires-Dist: pandas==2.2.0
|
|
30
|
+
Requires-Dist: peft==0.10.0
|
|
31
|
+
Requires-Dist: Pillow==10.3.0
|
|
32
|
+
Requires-Dist: pyarrow==15.0.0
|
|
33
|
+
Requires-Dist: pydantic==2.6.0
|
|
34
|
+
Requires-Dist: pyspark==3.2.2
|
|
35
|
+
Requires-Dist: python-dateutil==2.8.2
|
|
36
|
+
Requires-Dist: PyYAML==6.0.1
|
|
37
|
+
Requires-Dist: scikit-learn==1.4.0
|
|
38
|
+
Requires-Dist: scipy==1.12.0
|
|
39
|
+
Requires-Dist: tensorflow==2.15.0
|
|
40
|
+
Requires-Dist: tensorflow-metal==1.1.0; sys_platform == "darwin"
|
|
41
|
+
Requires-Dist: tensorflow-datasets==4.5.2
|
|
42
|
+
Requires-Dist: tqdm==4.66.1
|
|
43
|
+
Requires-Dist: torch==2.4.0
|
|
44
|
+
Requires-Dist: tokenizers==0.15.2
|
|
45
|
+
Requires-Dist: transformers==4.39.3
|
|
46
|
+
Requires-Dist: Werkzeug==3.0.1
|
|
47
|
+
Requires-Dist: wandb==0.17.8
|
|
48
|
+
Requires-Dist: xgboost==2.0.3
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
51
|
+
Requires-Dist: pytest; extra == "dev"
|
|
52
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
53
|
+
Requires-Dist: pytest-subtests; extra == "dev"
|
|
54
|
+
Requires-Dist: rootutils; extra == "dev"
|
|
55
|
+
Requires-Dist: hypothesis; extra == "dev"
|
|
56
|
+
Requires-Dist: black; extra == "dev"
|
|
57
|
+
|
|
58
|
+
# CEHR-BERT
|
|
59
|
+
|
|
60
|
+
CEHR-BERT is a large language model developed for the structured EHR data, the work has been published
|
|
61
|
+
at https://proceedings.mlr.press/v158/pang21a.html. CEHR-BERT currently only supports the structured EHR data in the
|
|
62
|
+
OMOP format, which is a common data model used to support observational studies and managed by the Observational Health
|
|
63
|
+
Data Science and Informatics (OHDSI) open-science community.
|
|
64
|
+
There are three major components in CEHR-BERT, data generation, model pre-training, and model evaluation with
|
|
65
|
+
fine-tuning, those components work in conjunction to provide an end-to-end model evaluation framework. The CEHR-BERT
|
|
66
|
+
framework is designed to be extensible, users could write their
|
|
67
|
+
own [pretraining models](trainers/README.md), [evaluation procedures](evaluations/README.md),
|
|
68
|
+
and [downstream prediction tasks](spark_apps/README.md) by extending the abstract classes, see click on the links for
|
|
69
|
+
more details. For a quick start, navigate to the [Get Started](#getting-started) section.
|
|
70
|
+
|
|
71
|
+
## Patient Representation
|
|
72
|
+
|
|
73
|
+
For each patient, all medical codes were aggregated and constructed into a sequence chronologically.
|
|
74
|
+
In order to incorporate temporal information, we inserted an artificial time token (ATT) between two neighboring visits
|
|
75
|
+
based on their time interval.
|
|
76
|
+
The following logic was used for creating ATTs based on the following time intervals between visits, if less than 28
|
|
77
|
+
days, ATTs take on the form of $W_n$ where n represents the week number ranging from 0-3 (e.g. $W_1$); 2) if between 28
|
|
78
|
+
days and 365 days, ATTs are in the form of **$M_n$** where n represents the month number ranging from 1-11 e.g $M_{11}$;
|
|
79
|
+
|
|
80
|
+
3) beyond 365 days then a **LT** (Long Term) token is inserted. In addition, we added two more special tokens — **VS**
|
|
81
|
+
and **VE** to represent the start and the end of a visit to explicitly define the visit segment, where all the
|
|
82
|
+
concepts
|
|
83
|
+
associated with the visit are subsumed by **VS** and **VE**.
|
|
84
|
+
|
|
85
|
+

|
|
86
|
+
|
|
87
|
+
## Model Architecture
|
|
88
|
+
|
|
89
|
+
Overview of our BERT architecture on structured EHR data. To distinguish visit boundaries, visit segment embeddings are
|
|
90
|
+
added to concept embeddings. Next, both visit embeddings and concept embeddings go through a temporal transformation,
|
|
91
|
+
where concept, age and time embeddings are concatenated together. The concatenated embeddings are then fed into a fully
|
|
92
|
+
connected layer. This temporal concept embedding becomes the input to BERT. We used the BERT learning objective Masked
|
|
93
|
+
Language Model as the primary learning objective and introduced an EHR specific secondary learning objective visit type
|
|
94
|
+
prediction.
|
|
95
|
+
|
|
96
|
+

|
|
97
|
+
|
|
98
|
+
## Pre-requisite
|
|
99
|
+
|
|
100
|
+
The project is built in python 3.10, and project dependency needs to be installed
|
|
101
|
+
|
|
102
|
+
Create a new Python virtual environment
|
|
103
|
+
|
|
104
|
+
```console
|
|
105
|
+
python3.10 -m venv .venv;
|
|
106
|
+
source .venv/bin/activate;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Build the project
|
|
110
|
+
|
|
111
|
+
```console
|
|
112
|
+
pip install -e .[dev]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Download [jtds-1.3.1.jar](jtds-1.3.1.jar) into the spark jars folder in the python environment
|
|
116
|
+
```console
|
|
117
|
+
cp jtds-1.3.1.jar .venv/lib/python3.10/site-packages/pyspark/jars/
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Instructions for Use with [MEDS](https://github.com/Medical-Event-Data-Standard/meds)
|
|
121
|
+
|
|
122
|
+
### 1. Convert MEDS to the [meds_reader](https://github.com/som-shahlab/meds_reader) database
|
|
123
|
+
|
|
124
|
+
If you don't have the MEDS dataset, you could convert the OMOP dataset to the MEDS
|
|
125
|
+
using [meds_etl](https://github.com/Medical-Event-Data-Standard/meds_etl).
|
|
126
|
+
We have prepared a synthea dataset with 1M patients for you to test, you could download it
|
|
127
|
+
at [omop_synthea.tar.gz](https://drive.google.com/file/d/1k7-cZACaDNw8A1JRI37mfMAhEErxKaQJ/view?usp=share_link)
|
|
128
|
+
```console
|
|
129
|
+
tar -xvf omop_synthea.tar .
|
|
130
|
+
```
|
|
131
|
+
Convert the OMOP dataset to the MEDS format
|
|
132
|
+
```console
|
|
133
|
+
pip install meds_etl==0.3.6;
|
|
134
|
+
meds_etl_omop omop_synthea synthea_meds;
|
|
135
|
+
```
|
|
136
|
+
Convert MEDS to the meds_reader database to get the patient level data
|
|
137
|
+
```console
|
|
138
|
+
meds_reader_convert synthea_meds synthea_meds_reader --num_threads 4
|
|
139
|
+
```
|
|
140
|
+
### 2. Pretrain CEHR-BERT using the meds_reader database
|
|
141
|
+
```console
|
|
142
|
+
mkdir test_dataset_prepared;
|
|
143
|
+
mkdir test_synthea_results;
|
|
144
|
+
python -m cehrbert.runners.hf_cehrbert_pretrain_runner sample_configs/hf_cehrbert_pretrain_runner_meds_config.yaml
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Instructions for Use with OMOP
|
|
148
|
+
|
|
149
|
+
### 1. Download OMOP tables as parquet files
|
|
150
|
+
|
|
151
|
+
We created a spark app to download OMOP tables from SQL Server as parquet files. You need adjust the properties
|
|
152
|
+
in `db_properties.ini` to match with your database setup.
|
|
153
|
+
|
|
154
|
+
```console
|
|
155
|
+
PYTHONPATH=./: spark-submit tools/download_omop_tables.py -c db_properties.ini -tc person visit_occurrence condition_occurrence procedure_occurrence drug_exposure measurement observation_period concept concept_relationship concept_ancestor -o ~/Documents/omop_test/
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
We have prepared a synthea dataset with 1M patients for you to test, you could download it
|
|
159
|
+
at [omop_synthea.tar.gz](https://drive.google.com/file/d/1k7-cZACaDNw8A1JRI37mfMAhEErxKaQJ/view?usp=share_link)
|
|
160
|
+
|
|
161
|
+
```console
|
|
162
|
+
tar -xvf omop_synthea.tar ~/Document/omop_test/
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 2. Generate training data for CEHR-BERT
|
|
166
|
+
|
|
167
|
+
We order the patient events in chronological order and put all data points in a sequence. We insert artificial tokens
|
|
168
|
+
VS (visit start) and VE (visit end) to the start and the end of the visit. In addition, we insert artificial time
|
|
169
|
+
tokens (ATT) between visits to indicate the time interval between visits. This approach allows us to apply BERT to
|
|
170
|
+
structured EHR as-is.
|
|
171
|
+
The sequence can be seen conceptually as [VS] [V1] [VE] [ATT] [VS] [V2] [VE], where [V1] and [V2] represent a list of
|
|
172
|
+
concepts associated with those visits.
|
|
173
|
+
|
|
174
|
+
```console
|
|
175
|
+
PYTHONPATH=./: spark-submit spark_apps/generate_training_data.py -i ~/Documents/omop_test/ -o ~/Documents/omop_test/cehr-bert -tc condition_occurrence procedure_occurrence drug_exposure -d 1985-01-01 --is_new_patient_representation -iv
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 3. Pre-train CEHR-BERT
|
|
179
|
+
If you don't have your own OMOP instance, we have provided a sample of patient sequence data generated using Synthea
|
|
180
|
+
at `sample/patient_sequence` in the repo. CEHR-BERT expects the data folder to be named as `patient_sequence`
|
|
181
|
+
|
|
182
|
+
```console
|
|
183
|
+
mkdir test_dataset_prepared;
|
|
184
|
+
mkdir test_results;
|
|
185
|
+
python -m cehrbert.runners.hf_cehrbert_pretrain_runner sample_configs/hf_cehrbert_pretrain_runner_config.yaml
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
If your dataset is large, you could add ```--use_dask``` in the command above
|
|
189
|
+
|
|
190
|
+
### 4. Generate hf readmission prediction task
|
|
191
|
+
If you don't have your own OMOP instance, we have provided a sample of patient sequence data generated using Synthea
|
|
192
|
+
at `sample/hf_readmissioon` in the repo
|
|
193
|
+
|
|
194
|
+
```console
|
|
195
|
+
PYTHONPATH=./:$PYTHONPATH spark-submit spark_apps/prediction_cohorts/hf_readmission.py -c hf_readmission -i ~/Documents/omop_test/ -o ~/Documents/omop_test/cehr-bert -dl 1985-01-01 -du 2020-12-31 -l 18 -u 100 -ow 360 -ps 0 -pw 30 --is_new_patient_representation
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 5. Fine-tune CEHR-BERT
|
|
199
|
+
|
|
200
|
+
```console
|
|
201
|
+
mkdir test_finetune_results;
|
|
202
|
+
python -m cehrbert.runners.hf_cehrbert_finetuning_runner sample_configs/hf_cehrbert_finetuning_runner_config.yaml
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Contact us
|
|
206
|
+
|
|
207
|
+
If you have any questions, feel free to contact us at CEHR-BERT@lists.cumc.columbia.edu
|
|
208
|
+
|
|
209
|
+
## Citation
|
|
210
|
+
|
|
211
|
+
Please acknowledge the following work in papers
|
|
212
|
+
|
|
213
|
+
Chao Pang, Xinzhuo Jiang, Krishna S. Kalluri, Matthew Spotnitz, RuiJun Chen, Adler
|
|
214
|
+
Perotte, and Karthik Natarajan. "Cehr-bert: Incorporating temporal information from
|
|
215
|
+
structured ehr data to improve prediction tasks." In Proceedings of Machine Learning for
|
|
216
|
+
Health, volume 158 of Proceedings of Machine Learning Research, pages 239–260. PMLR,
|
|
217
|
+
04 Dec 2021.
|
cehrbert-1.1.0/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# CEHR-BERT
|
|
2
|
+
|
|
3
|
+
CEHR-BERT is a large language model developed for the structured EHR data, the work has been published
|
|
4
|
+
at https://proceedings.mlr.press/v158/pang21a.html. CEHR-BERT currently only supports the structured EHR data in the
|
|
5
|
+
OMOP format, which is a common data model used to support observational studies and managed by the Observational Health
|
|
6
|
+
Data Science and Informatics (OHDSI) open-science community.
|
|
7
|
+
There are three major components in CEHR-BERT, data generation, model pre-training, and model evaluation with
|
|
8
|
+
fine-tuning, those components work in conjunction to provide an end-to-end model evaluation framework. The CEHR-BERT
|
|
9
|
+
framework is designed to be extensible, users could write their
|
|
10
|
+
own [pretraining models](trainers/README.md), [evaluation procedures](evaluations/README.md),
|
|
11
|
+
and [downstream prediction tasks](spark_apps/README.md) by extending the abstract classes, see click on the links for
|
|
12
|
+
more details. For a quick start, navigate to the [Get Started](#getting-started) section.
|
|
13
|
+
|
|
14
|
+
## Patient Representation
|
|
15
|
+
|
|
16
|
+
For each patient, all medical codes were aggregated and constructed into a sequence chronologically.
|
|
17
|
+
In order to incorporate temporal information, we inserted an artificial time token (ATT) between two neighboring visits
|
|
18
|
+
based on their time interval.
|
|
19
|
+
The following logic was used for creating ATTs based on the following time intervals between visits, if less than 28
|
|
20
|
+
days, ATTs take on the form of $W_n$ where n represents the week number ranging from 0-3 (e.g. $W_1$); 2) if between 28
|
|
21
|
+
days and 365 days, ATTs are in the form of **$M_n$** where n represents the month number ranging from 1-11 e.g $M_{11}$;
|
|
22
|
+
|
|
23
|
+
3) beyond 365 days then a **LT** (Long Term) token is inserted. In addition, we added two more special tokens — **VS**
|
|
24
|
+
and **VE** to represent the start and the end of a visit to explicitly define the visit segment, where all the
|
|
25
|
+
concepts
|
|
26
|
+
associated with the visit are subsumed by **VS** and **VE**.
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
## Model Architecture
|
|
31
|
+
|
|
32
|
+
Overview of our BERT architecture on structured EHR data. To distinguish visit boundaries, visit segment embeddings are
|
|
33
|
+
added to concept embeddings. Next, both visit embeddings and concept embeddings go through a temporal transformation,
|
|
34
|
+
where concept, age and time embeddings are concatenated together. The concatenated embeddings are then fed into a fully
|
|
35
|
+
connected layer. This temporal concept embedding becomes the input to BERT. We used the BERT learning objective Masked
|
|
36
|
+
Language Model as the primary learning objective and introduced an EHR specific secondary learning objective visit type
|
|
37
|
+
prediction.
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
## Pre-requisite
|
|
42
|
+
|
|
43
|
+
The project is built in python 3.10, and project dependency needs to be installed
|
|
44
|
+
|
|
45
|
+
Create a new Python virtual environment
|
|
46
|
+
|
|
47
|
+
```console
|
|
48
|
+
python3.10 -m venv .venv;
|
|
49
|
+
source .venv/bin/activate;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Build the project
|
|
53
|
+
|
|
54
|
+
```console
|
|
55
|
+
pip install -e .[dev]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Download [jtds-1.3.1.jar](jtds-1.3.1.jar) into the spark jars folder in the python environment
|
|
59
|
+
```console
|
|
60
|
+
cp jtds-1.3.1.jar .venv/lib/python3.10/site-packages/pyspark/jars/
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Instructions for Use with [MEDS](https://github.com/Medical-Event-Data-Standard/meds)
|
|
64
|
+
|
|
65
|
+
### 1. Convert MEDS to the [meds_reader](https://github.com/som-shahlab/meds_reader) database
|
|
66
|
+
|
|
67
|
+
If you don't have the MEDS dataset, you could convert the OMOP dataset to the MEDS
|
|
68
|
+
using [meds_etl](https://github.com/Medical-Event-Data-Standard/meds_etl).
|
|
69
|
+
We have prepared a synthea dataset with 1M patients for you to test, you could download it
|
|
70
|
+
at [omop_synthea.tar.gz](https://drive.google.com/file/d/1k7-cZACaDNw8A1JRI37mfMAhEErxKaQJ/view?usp=share_link)
|
|
71
|
+
```console
|
|
72
|
+
tar -xvf omop_synthea.tar .
|
|
73
|
+
```
|
|
74
|
+
Convert the OMOP dataset to the MEDS format
|
|
75
|
+
```console
|
|
76
|
+
pip install meds_etl==0.3.6;
|
|
77
|
+
meds_etl_omop omop_synthea synthea_meds;
|
|
78
|
+
```
|
|
79
|
+
Convert MEDS to the meds_reader database to get the patient level data
|
|
80
|
+
```console
|
|
81
|
+
meds_reader_convert synthea_meds synthea_meds_reader --num_threads 4
|
|
82
|
+
```
|
|
83
|
+
### 2. Pretrain CEHR-BERT using the meds_reader database
|
|
84
|
+
```console
|
|
85
|
+
mkdir test_dataset_prepared;
|
|
86
|
+
mkdir test_synthea_results;
|
|
87
|
+
python -m cehrbert.runners.hf_cehrbert_pretrain_runner sample_configs/hf_cehrbert_pretrain_runner_meds_config.yaml
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Instructions for Use with OMOP
|
|
91
|
+
|
|
92
|
+
### 1. Download OMOP tables as parquet files
|
|
93
|
+
|
|
94
|
+
We created a spark app to download OMOP tables from SQL Server as parquet files. You need adjust the properties
|
|
95
|
+
in `db_properties.ini` to match with your database setup.
|
|
96
|
+
|
|
97
|
+
```console
|
|
98
|
+
PYTHONPATH=./: spark-submit tools/download_omop_tables.py -c db_properties.ini -tc person visit_occurrence condition_occurrence procedure_occurrence drug_exposure measurement observation_period concept concept_relationship concept_ancestor -o ~/Documents/omop_test/
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
We have prepared a synthea dataset with 1M patients for you to test, you could download it
|
|
102
|
+
at [omop_synthea.tar.gz](https://drive.google.com/file/d/1k7-cZACaDNw8A1JRI37mfMAhEErxKaQJ/view?usp=share_link)
|
|
103
|
+
|
|
104
|
+
```console
|
|
105
|
+
tar -xvf omop_synthea.tar ~/Document/omop_test/
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2. Generate training data for CEHR-BERT
|
|
109
|
+
|
|
110
|
+
We order the patient events in chronological order and put all data points in a sequence. We insert artificial tokens
|
|
111
|
+
VS (visit start) and VE (visit end) to the start and the end of the visit. In addition, we insert artificial time
|
|
112
|
+
tokens (ATT) between visits to indicate the time interval between visits. This approach allows us to apply BERT to
|
|
113
|
+
structured EHR as-is.
|
|
114
|
+
The sequence can be seen conceptually as [VS] [V1] [VE] [ATT] [VS] [V2] [VE], where [V1] and [V2] represent a list of
|
|
115
|
+
concepts associated with those visits.
|
|
116
|
+
|
|
117
|
+
```console
|
|
118
|
+
PYTHONPATH=./: spark-submit spark_apps/generate_training_data.py -i ~/Documents/omop_test/ -o ~/Documents/omop_test/cehr-bert -tc condition_occurrence procedure_occurrence drug_exposure -d 1985-01-01 --is_new_patient_representation -iv
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 3. Pre-train CEHR-BERT
|
|
122
|
+
If you don't have your own OMOP instance, we have provided a sample of patient sequence data generated using Synthea
|
|
123
|
+
at `sample/patient_sequence` in the repo. CEHR-BERT expects the data folder to be named as `patient_sequence`
|
|
124
|
+
|
|
125
|
+
```console
|
|
126
|
+
mkdir test_dataset_prepared;
|
|
127
|
+
mkdir test_results;
|
|
128
|
+
python -m cehrbert.runners.hf_cehrbert_pretrain_runner sample_configs/hf_cehrbert_pretrain_runner_config.yaml
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
If your dataset is large, you could add ```--use_dask``` in the command above
|
|
132
|
+
|
|
133
|
+
### 4. Generate hf readmission prediction task
|
|
134
|
+
If you don't have your own OMOP instance, we have provided a sample of patient sequence data generated using Synthea
|
|
135
|
+
at `sample/hf_readmissioon` in the repo
|
|
136
|
+
|
|
137
|
+
```console
|
|
138
|
+
PYTHONPATH=./:$PYTHONPATH spark-submit spark_apps/prediction_cohorts/hf_readmission.py -c hf_readmission -i ~/Documents/omop_test/ -o ~/Documents/omop_test/cehr-bert -dl 1985-01-01 -du 2020-12-31 -l 18 -u 100 -ow 360 -ps 0 -pw 30 --is_new_patient_representation
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 5. Fine-tune CEHR-BERT
|
|
142
|
+
|
|
143
|
+
```console
|
|
144
|
+
mkdir test_finetune_results;
|
|
145
|
+
python -m cehrbert.runners.hf_cehrbert_finetuning_runner sample_configs/hf_cehrbert_finetuning_runner_config.yaml
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Contact us
|
|
149
|
+
|
|
150
|
+
If you have any questions, feel free to contact us at CEHR-BERT@lists.cumc.columbia.edu
|
|
151
|
+
|
|
152
|
+
## Citation
|
|
153
|
+
|
|
154
|
+
Please acknowledge the following work in papers
|
|
155
|
+
|
|
156
|
+
Chao Pang, Xinzhuo Jiang, Krishna S. Kalluri, Matthew Spotnitz, RuiJun Chen, Adler
|
|
157
|
+
Perotte, and Karthik Natarajan. "Cehr-bert: Incorporating temporal information from
|
|
158
|
+
structured ehr data to improve prediction tasks." In Proceedings of Machine Learning for
|
|
159
|
+
Health, volume 158 of Proceedings of Machine Learning Research, pages 239–260. PMLR,
|
|
160
|
+
04 Dec 2021.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"zero_optimization": {
|
|
3
|
+
"stage": 1,
|
|
4
|
+
"overlap_comm": true
|
|
5
|
+
},
|
|
6
|
+
"bf16": {
|
|
7
|
+
"enabled": "auto"
|
|
8
|
+
},
|
|
9
|
+
"fp16": {
|
|
10
|
+
"enabled": "auto",
|
|
11
|
+
"auto_cast": false,
|
|
12
|
+
"loss_scale": 0,
|
|
13
|
+
"initial_scale_power": 32,
|
|
14
|
+
"loss_scale_window": 1000,
|
|
15
|
+
"hysteresis": 2,
|
|
16
|
+
"min_loss_scale": 1
|
|
17
|
+
},
|
|
18
|
+
"gradient_accumulation_steps": "auto",
|
|
19
|
+
"train_batch_size": "auto",
|
|
20
|
+
"train_micro_batch_size_per_gpu": "auto",
|
|
21
|
+
"wall_clock_breakdown": false
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"zero_optimization": {
|
|
3
|
+
"stage": 2,
|
|
4
|
+
"offload_optimizer": {
|
|
5
|
+
"device": "cpu"
|
|
6
|
+
},
|
|
7
|
+
"contiguous_gradients": true,
|
|
8
|
+
"overlap_comm": true
|
|
9
|
+
},
|
|
10
|
+
"bf16": {
|
|
11
|
+
"enabled": "auto"
|
|
12
|
+
},
|
|
13
|
+
"fp16": {
|
|
14
|
+
"enabled": "auto",
|
|
15
|
+
"auto_cast": false,
|
|
16
|
+
"loss_scale": 0,
|
|
17
|
+
"initial_scale_power": 32,
|
|
18
|
+
"loss_scale_window": 1000,
|
|
19
|
+
"hysteresis": 2,
|
|
20
|
+
"min_loss_scale": 1
|
|
21
|
+
},
|
|
22
|
+
"gradient_accumulation_steps": "auto",
|
|
23
|
+
"train_batch_size": "auto",
|
|
24
|
+
"train_micro_batch_size_per_gpu": "auto",
|
|
25
|
+
"wall_clock_breakdown": false
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"zero_optimization": {
|
|
3
|
+
"stage": 3,
|
|
4
|
+
"overlap_comm": true,
|
|
5
|
+
"contiguous_gradients": true,
|
|
6
|
+
"sub_group_size": 0,
|
|
7
|
+
"reduce_bucket_size": "auto",
|
|
8
|
+
"stage3_prefetch_bucket_size": "auto",
|
|
9
|
+
"stage3_param_persistence_threshold": "auto",
|
|
10
|
+
"stage3_max_live_parameters": 0,
|
|
11
|
+
"stage3_max_reuse_distance": 0,
|
|
12
|
+
"stage3_gather_16bit_weights_on_model_save": true
|
|
13
|
+
},
|
|
14
|
+
"bf16": {
|
|
15
|
+
"enabled": "auto"
|
|
16
|
+
},
|
|
17
|
+
"fp16": {
|
|
18
|
+
"enabled": "auto",
|
|
19
|
+
"auto_cast": false,
|
|
20
|
+
"loss_scale": 0,
|
|
21
|
+
"initial_scale_power": 32,
|
|
22
|
+
"loss_scale_window": 1000,
|
|
23
|
+
"hysteresis": 2,
|
|
24
|
+
"min_loss_scale": 1
|
|
25
|
+
},
|
|
26
|
+
"gradient_accumulation_steps": "auto",
|
|
27
|
+
"train_batch_size": "auto",
|
|
28
|
+
"train_micro_batch_size_per_gpu": "auto",
|
|
29
|
+
"wall_clock_breakdown": false
|
|
30
|
+
}
|
|
Binary file
|
|
Binary file
|