cehrbert 1.2.4__tar.gz → 1.2.6__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.
- {cehrbert-1.2.4 → cehrbert-1.2.6}/PKG-INFO +2 -2
- {cehrbert-1.2.4 → cehrbert-1.2.6}/README.md +1 -1
- {cehrbert-1.2.4 → cehrbert-1.2.6}/sample_configs/hf_cehrbert_finetuning_runner_config.yaml +1 -1
- {cehrbert-1.2.4 → cehrbert-1.2.6}/sample_configs/hf_cehrbert_pretrain_runner_config.yaml +1 -1
- {cehrbert-1.2.4 → cehrbert-1.2.6}/sample_configs/hf_cehrbert_pretrain_runner_meds_config.yaml +1 -1
- cehrbert-1.2.6/src/cehrbert/config/output_names.py +9 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/hf_dataset.py +25 -15
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/runners/hf_cehrbert_finetune_runner.py +1 -1
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/runners/hf_cehrbert_pretrain_runner.py +4 -12
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/runners/hf_runner_argument_dataclass.py +2 -2
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/runners/runner_util.py +65 -9
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert.egg-info/PKG-INFO +2 -2
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert.egg-info/SOURCES.txt +2 -0
- cehrbert-1.2.6/tests/integration_tests/runners/hf_cehrbert_pretrain_runner_streaming_test.py +55 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/.github/workflows/python-build.yml +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/.github/workflows/tests.yml +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/.gitignore +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/.pre-commit-config.yaml +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/LICENSE +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/db_properties.ini +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/deepspeed_configs/zero1.json +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/deepspeed_configs/zero2.json +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/deepspeed_configs/zero3.json +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/full_grid_search_config.ini +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/images/cehr_bert_architecture.png +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/images/tokenization_att_generation.png +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/pyproject.toml +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/sample_data/finetune/full/fake_data.parquet +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/sample_data/finetune/test/fake_data.parquet +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/sample_data/finetune/train/fake_data.parquet +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/sample_data/pretrain/patient_sequence.parquet +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/setup.cfg +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/simple_grid_search_config.ini +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/config/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/config/grid_search_config.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/data_classes.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/data_generator_base.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/graph_sample_method.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/hf_dataset_collator.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/hf_dataset_mapping.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/meds_to_cehrbert_conversion_rules/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/meds_to_cehrbert_conversion_rules/meds_to_cehrbert_base.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/meds_to_cehrbert_conversion_rules/meds_to_cehrbert_micmic4.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/meds_to_cehrbert_conversion_rules/meds_to_cehrbert_omop.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/meds_utils.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/patient_block.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/learning_objective.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/tokenizer.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/evaluation.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/evaluation_parameters.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/evaluation_parse_args.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/model_evaluators/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/model_evaluators/bert_model_evaluators.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/model_evaluators/frequency_model_evaluators.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/model_evaluators/hierarchical_bert_evaluators.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/model_evaluators/model_evaluators.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/model_evaluators/sequence_model_evaluators.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/transfer_learning_evaluation.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/keras_transformer/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/keras_transformer/bert.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/keras_transformer/extras.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/keras_transformer/position.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/med_extension/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/med_extension/schema_extension.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/bert_models.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/bert_models_visit_prediction.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/evaluation_models.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/hf_models/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/hf_models/config.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/hf_models/hf_cehrbert.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/hf_models/hf_modeling_outputs.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/hf_models/tokenization_hf_cehrbert.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/hf_models/tokenization_utils.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/hierachical_bert_model_v2.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/hierachical_phenotype_model_new.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/layers/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/layers/custom_layers.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/layers/hierarchical_custom_layers.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/loss_schedulers.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/models/parse_args.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/runners/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/tools/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/tools/download_omop_tables.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/trainers/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/trainers/model_trainer.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/trainers/train_cehr_bert.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/utils/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/utils/checkpoint_utils.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/utils/logging_utils.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/utils/model_utils.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/utils/stat_utils.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert.egg-info/dependency_links.txt +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert.egg-info/entry_points.txt +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert.egg-info/requires.txt +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert.egg-info/top_level.txt +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/integration_tests/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/integration_tests/runners/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/integration_tests/runners/hf_cehrbert_pretrain_runner_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/integration_tests/trainers/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/integration_tests/trainers/train_cehr_bert_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/bert_masked_language_modeling_learning_objective_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/hf_data_generator/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/hf_data_generator/hf_generate_start_end_index_mapping_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/hf_data_generator/hf_masked_language_modeling_mapping_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/hf_data_generator/hf_med_to_cehrbert_mapping_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/hf_data_generator/hf_sort_patient_sequence_dataset_mapping_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/hf_data_generator/meds_utils_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/hf_data_generator/omop_meds_generate_demographics_and_patient_blocks_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/visit_prediction_learning_objective_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/models/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/models/concept_value_decoder_layer_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/models/hf_models/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/models/hf_models/hf_cehrbert_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/models/hf_models/numeric_concept_statistics_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/models/hf_models/tokenization_hf_cehrbert_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/utils/__init__.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/utils/truncated_offline_statistics_test.py +0 -0
- {cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/utils/truncated_online_statistics_test.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cehrbert
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.6
|
|
4
4
|
Summary: CEHR-BERT: Incorporating temporal information from structured EHR data to improve prediction tasks
|
|
5
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
6
|
License: MIT License
|
|
@@ -199,7 +199,7 @@ PYTHONPATH=./:$PYTHONPATH spark-submit spark_apps/prediction_cohorts/hf_readmiss
|
|
|
199
199
|
|
|
200
200
|
```console
|
|
201
201
|
mkdir test_finetune_results;
|
|
202
|
-
python -m cehrbert.runners.
|
|
202
|
+
python -m cehrbert.runners.hf_cehrbert_finetune_runner sample_configs/hf_cehrbert_finetuning_runner_config.yaml
|
|
203
203
|
```
|
|
204
204
|
|
|
205
205
|
## Contact us
|
|
@@ -142,7 +142,7 @@ PYTHONPATH=./:$PYTHONPATH spark-submit spark_apps/prediction_cohorts/hf_readmiss
|
|
|
142
142
|
|
|
143
143
|
```console
|
|
144
144
|
mkdir test_finetune_results;
|
|
145
|
-
python -m cehrbert.runners.
|
|
145
|
+
python -m cehrbert.runners.hf_cehrbert_finetune_runner sample_configs/hf_cehrbert_finetuning_runner_config.yaml
|
|
146
146
|
```
|
|
147
147
|
|
|
148
148
|
## Contact us
|
|
@@ -15,7 +15,7 @@ min_frequency: 0
|
|
|
15
15
|
|
|
16
16
|
# Below is a list of Med-to-CehrBert related arguments
|
|
17
17
|
att_function_type: "cehrbert"
|
|
18
|
-
|
|
18
|
+
is_data_in_meds: false
|
|
19
19
|
inpatient_att_function_type: "mix"
|
|
20
20
|
include_auxiliary_token: true
|
|
21
21
|
include_demographic_prompt: false
|
|
@@ -15,7 +15,7 @@ min_frequency: 0
|
|
|
15
15
|
|
|
16
16
|
# Below is a list of Med-to-CehrBert related arguments
|
|
17
17
|
att_function_type: "cehrbert"
|
|
18
|
-
|
|
18
|
+
is_data_in_meds: false
|
|
19
19
|
inpatient_att_function_type: "none"
|
|
20
20
|
include_auxiliary_token: true
|
|
21
21
|
include_demographic_prompt: false
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/sample_configs/hf_cehrbert_pretrain_runner_meds_config.yaml
RENAMED
|
@@ -15,7 +15,7 @@ min_frequency: 0
|
|
|
15
15
|
|
|
16
16
|
# Below is a list of Med-to-CehrBert related arguments
|
|
17
17
|
att_function_type: "cehrbert"
|
|
18
|
-
|
|
18
|
+
is_data_in_meds: true
|
|
19
19
|
inpatient_att_function_type: "mix"
|
|
20
20
|
include_auxiliary_token: true
|
|
21
21
|
include_demographic_prompt: false
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
parquet_data_path = "patient_sequence"
|
|
2
|
+
qualified_concept_list_path = "qualified_concept_list"
|
|
3
|
+
time_attention_model_path = "time_aware_model.h5"
|
|
4
|
+
bert_model_validation_path = "bert_model.h5"
|
|
5
|
+
mortality_data_path = "mortality"
|
|
6
|
+
heart_failure_data_path = "heart_failure"
|
|
7
|
+
hospitalization_data_path = "hospitalization"
|
|
8
|
+
information_content_data_path = "information_content"
|
|
9
|
+
concept_similarity_path = "concept_similarity"
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/hf_dataset.py
RENAMED
|
@@ -38,15 +38,10 @@ def create_cehrbert_pretraining_dataset(
|
|
|
38
38
|
required_columns = TRANSFORMER_COLUMNS + CEHRBERT_COLUMNS
|
|
39
39
|
|
|
40
40
|
# Remove patients without any records
|
|
41
|
-
dataset = dataset
|
|
42
|
-
lambda batch: [num_of_concepts > 0 for num_of_concepts in batch["num_of_concepts"]],
|
|
43
|
-
num_proc=data_args.preprocessing_num_workers if not data_args.streaming else None,
|
|
44
|
-
batched=True,
|
|
45
|
-
batch_size=data_args.preprocessing_batch_size,
|
|
46
|
-
)
|
|
41
|
+
dataset = filter_dataset(dataset, data_args)
|
|
47
42
|
|
|
48
43
|
# If the data is already in meds, we don't need to sort the sequence anymore
|
|
49
|
-
if data_args.
|
|
44
|
+
if data_args.is_data_in_meds:
|
|
50
45
|
mapping_functions = [HFTokenizationMapping(concept_tokenizer, True)]
|
|
51
46
|
else:
|
|
52
47
|
mapping_functions = [
|
|
@@ -82,14 +77,9 @@ def create_cehrbert_finetuning_dataset(
|
|
|
82
77
|
required_columns = TRANSFORMER_COLUMNS + CEHRBERT_COLUMNS + FINETUNING_COLUMNS
|
|
83
78
|
|
|
84
79
|
# Remove patients without any records
|
|
85
|
-
dataset = dataset
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
batched=True,
|
|
89
|
-
batch_size=data_args.preprocessing_batch_size,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
if data_args.is_data_in_med:
|
|
80
|
+
dataset = filter_dataset(dataset, data_args)
|
|
81
|
+
|
|
82
|
+
if data_args.is_data_in_meds:
|
|
93
83
|
mapping_functions = [
|
|
94
84
|
HFFineTuningMapping(),
|
|
95
85
|
HFTokenizationMapping(concept_tokenizer, False),
|
|
@@ -120,6 +110,26 @@ def create_cehrbert_finetuning_dataset(
|
|
|
120
110
|
return dataset
|
|
121
111
|
|
|
122
112
|
|
|
113
|
+
def filter_dataset(dataset: Union[Dataset, DatasetDict], data_args: DataTrainingArguments):
|
|
114
|
+
# Remove patients without any records
|
|
115
|
+
# check if DatatsetDict or IterableDatasetDict, if so, filter each dataset
|
|
116
|
+
if isinstance(dataset, DatasetDict) and data_args.streaming:
|
|
117
|
+
for key in dataset.keys():
|
|
118
|
+
dataset[key] = dataset[key].filter(
|
|
119
|
+
lambda batch: [num_of_concepts > 0 for num_of_concepts in batch["num_of_concepts"]],
|
|
120
|
+
batched=True,
|
|
121
|
+
batch_size=data_args.preprocessing_batch_size,
|
|
122
|
+
)
|
|
123
|
+
else:
|
|
124
|
+
dataset = dataset.filter(
|
|
125
|
+
lambda batch: [num_of_concepts > 0 for num_of_concepts in batch["num_of_concepts"]],
|
|
126
|
+
num_proc=data_args.preprocessing_num_workers if not data_args.streaming else None,
|
|
127
|
+
batched=True,
|
|
128
|
+
batch_size=data_args.preprocessing_batch_size,
|
|
129
|
+
)
|
|
130
|
+
return dataset
|
|
131
|
+
|
|
132
|
+
|
|
123
133
|
def apply_cehrbert_dataset_mapping(
|
|
124
134
|
dataset: Union[DatasetDict, Dataset, IterableDataset, IterableDatasetDict],
|
|
125
135
|
mapping_function: DatasetMapping,
|
|
@@ -106,7 +106,7 @@ def main():
|
|
|
106
106
|
LOG.info("Prepared dataset loaded from disk...")
|
|
107
107
|
else:
|
|
108
108
|
# If the data is in the MEDS format, we need to convert it to the CEHR-BERT format
|
|
109
|
-
if data_args.
|
|
109
|
+
if data_args.is_data_in_meds:
|
|
110
110
|
meds_extension_path = get_meds_extension_path(
|
|
111
111
|
data_folder=os.path.expanduser(data_args.cohort_folder),
|
|
112
112
|
dataset_prepared_path=os.path.expanduser(data_args.dataset_prepared_path),
|
|
@@ -170,7 +170,7 @@ def main():
|
|
|
170
170
|
tokenizer = load_and_create_tokenizer(data_args=data_args, model_args=model_args, dataset=processed_dataset)
|
|
171
171
|
else:
|
|
172
172
|
# If the data is in the MEDS format, we need to convert it to the CEHR-BERT format
|
|
173
|
-
if data_args.
|
|
173
|
+
if data_args.is_data_in_meds:
|
|
174
174
|
meds_extension_path = get_meds_extension_path(
|
|
175
175
|
data_folder=os.path.expanduser(data_args.data_folder),
|
|
176
176
|
dataset_prepared_path=os.path.expanduser(data_args.dataset_prepared_path),
|
|
@@ -206,6 +206,7 @@ def main():
|
|
|
206
206
|
test_size=data_args.validation_split_percentage,
|
|
207
207
|
seed=training_args.seed,
|
|
208
208
|
)
|
|
209
|
+
dataset = DatasetDict({"train": dataset["train"], "validation": dataset["test"]})
|
|
209
210
|
else:
|
|
210
211
|
raise RuntimeError(
|
|
211
212
|
f"Can not split the data. If streaming is enabled, validation_split_num needs "
|
|
@@ -261,20 +262,11 @@ def main():
|
|
|
261
262
|
if not data_args.streaming:
|
|
262
263
|
processed_dataset.set_format("pt")
|
|
263
264
|
|
|
264
|
-
eval_dataset = None
|
|
265
|
-
if isinstance(processed_dataset, DatasetDict) or isinstance(processed_dataset, IterableDatasetDict):
|
|
266
|
-
train_dataset = processed_dataset["train"]
|
|
267
|
-
if "validation" in processed_dataset:
|
|
268
|
-
eval_dataset = processed_dataset["validation"]
|
|
269
|
-
else:
|
|
270
|
-
train_dataset = processed_dataset
|
|
271
|
-
|
|
272
265
|
trainer = Trainer(
|
|
273
266
|
model=model,
|
|
274
267
|
data_collator=collator,
|
|
275
|
-
train_dataset=
|
|
276
|
-
eval_dataset=
|
|
277
|
-
# compute_metrics=compute_metrics,
|
|
268
|
+
train_dataset=processed_dataset["train"],
|
|
269
|
+
eval_dataset=processed_dataset["validation"],
|
|
278
270
|
args=training_args,
|
|
279
271
|
)
|
|
280
272
|
|
|
@@ -90,9 +90,9 @@ class DataTrainingArguments:
|
|
|
90
90
|
"choices": f"choices={[e.value for e in AttType]}",
|
|
91
91
|
},
|
|
92
92
|
)
|
|
93
|
-
|
|
93
|
+
is_data_in_meds: Optional[bool] = dataclasses.field(
|
|
94
94
|
default=False,
|
|
95
|
-
metadata={"help": "The boolean indicator to indicate whether the data is in the
|
|
95
|
+
metadata={"help": "The boolean indicator to indicate whether the data is in the MEDS format"},
|
|
96
96
|
)
|
|
97
97
|
inpatient_att_function_type: Literal[
|
|
98
98
|
AttType.CEHR_BERT.value,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import dataclasses
|
|
1
2
|
import glob
|
|
2
3
|
import hashlib
|
|
3
4
|
import os
|
|
@@ -215,6 +216,67 @@ def remove_trailing_slashes(path: str) -> str:
|
|
|
215
216
|
return path.rstrip("/\\")
|
|
216
217
|
|
|
217
218
|
|
|
219
|
+
def parse_dynamic_arguments(
|
|
220
|
+
argument_classes: Tuple[dataclasses.dataclass, ...] = (DataTrainingArguments, ModelArguments, TrainingArguments)
|
|
221
|
+
) -> Tuple:
|
|
222
|
+
"""
|
|
223
|
+
Parses command-line arguments with extended flexibility, allowing for the inclusion of custom argument classes.
|
|
224
|
+
|
|
225
|
+
This function utilizes `HfArgumentParser` to parse arguments from command line input, JSON, or YAML files.
|
|
226
|
+
By default, it expects `ModelArguments`, `DataTrainingArguments`, and `TrainingArguments`, but it can be extended
|
|
227
|
+
with additional argument classes through the `argument_classes` parameter, making it suitable
|
|
228
|
+
for various custom setups.
|
|
229
|
+
|
|
230
|
+
Parameters:
|
|
231
|
+
argument_classes (Tuple[Type]): A tuple of argument classes to be parsed. Defaults to
|
|
232
|
+
`(ModelArguments, DataTrainingArguments, TrainingArguments)`. Additional argument classes can be specified
|
|
233
|
+
for greater flexibility in configuration.
|
|
234
|
+
|
|
235
|
+
Returns:
|
|
236
|
+
Tuple: A tuple of parsed arguments, one for each argument class provided. The order of the returned tuple
|
|
237
|
+
matches the order of the `argument_classes` parameter.
|
|
238
|
+
|
|
239
|
+
Raises:
|
|
240
|
+
FileNotFoundError: If the specified JSON or YAML file does not exist.
|
|
241
|
+
json.JSONDecodeError: If there is an error parsing a JSON file.
|
|
242
|
+
yaml.YAMLError: If there is an error parsing a YAML file.
|
|
243
|
+
Exception: For other issues that occur during argument parsing.
|
|
244
|
+
|
|
245
|
+
Example usage:
|
|
246
|
+
- Command-line: `python training_script.py --model_name_or_path bert-base-uncased --do_train`
|
|
247
|
+
- JSON file: `python training_script.py config.json`
|
|
248
|
+
- YAML file: `python training_script.py config.yaml`
|
|
249
|
+
|
|
250
|
+
Flexibility:
|
|
251
|
+
The function can be customized to include new argument classes as needed:
|
|
252
|
+
|
|
253
|
+
Example with a custom argument class:
|
|
254
|
+
```python
|
|
255
|
+
class CustomArguments:
|
|
256
|
+
# Define custom arguments here
|
|
257
|
+
pass
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
custom_args = parse_extended_args(
|
|
261
|
+
(ModelArguments, DataTrainingArguments, TrainingArguments, CustomArguments)
|
|
262
|
+
)
|
|
263
|
+
```
|
|
264
|
+
This example demonstrates how to include additional argument classes
|
|
265
|
+
beyond the defaults for a more tailored setup.
|
|
266
|
+
"""
|
|
267
|
+
parser = HfArgumentParser(argument_classes)
|
|
268
|
+
|
|
269
|
+
# Check if input is a JSON or YAML file
|
|
270
|
+
if len(sys.argv) == 2 and sys.argv[1].endswith(".json"):
|
|
271
|
+
args = parser.parse_json_file(json_file=os.path.expanduser(sys.argv[1]))
|
|
272
|
+
elif len(sys.argv) == 2 and sys.argv[1].endswith(".yaml"):
|
|
273
|
+
args = parser.parse_yaml_file(yaml_file=os.path.expanduser(sys.argv[1]))
|
|
274
|
+
else:
|
|
275
|
+
args = parser.parse_args_into_dataclasses()
|
|
276
|
+
|
|
277
|
+
return tuple(args)
|
|
278
|
+
|
|
279
|
+
|
|
218
280
|
def parse_runner_args() -> Tuple[DataTrainingArguments, ModelArguments, TrainingArguments]:
|
|
219
281
|
"""
|
|
220
282
|
Parses command line arguments provided to a script for training a model using the Hugging Face.
|
|
@@ -253,15 +315,9 @@ def parse_runner_args() -> Tuple[DataTrainingArguments, ModelArguments, Training
|
|
|
253
315
|
Or using a YAML configuration file:
|
|
254
316
|
$ python training_script.py config.yaml
|
|
255
317
|
"""
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
# let's parse it to get our arguments.
|
|
260
|
-
model_args, data_args, training_args = parser.parse_json_file(json_file=os.path.expanduser(sys.argv[1]))
|
|
261
|
-
elif len(sys.argv) == 2 and sys.argv[1].endswith(".yaml"):
|
|
262
|
-
model_args, data_args, training_args = parser.parse_yaml_file(yaml_file=os.path.expanduser(sys.argv[1]))
|
|
263
|
-
else:
|
|
264
|
-
model_args, data_args, training_args = parser.parse_args_into_dataclasses()
|
|
318
|
+
data_args, model_args, training_args = parse_dynamic_arguments(
|
|
319
|
+
(DataTrainingArguments, ModelArguments, TrainingArguments)
|
|
320
|
+
)
|
|
265
321
|
return data_args, model_args, training_args
|
|
266
322
|
|
|
267
323
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cehrbert
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.6
|
|
4
4
|
Summary: CEHR-BERT: Incorporating temporal information from structured EHR data to improve prediction tasks
|
|
5
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
6
|
License: MIT License
|
|
@@ -199,7 +199,7 @@ PYTHONPATH=./:$PYTHONPATH spark-submit spark_apps/prediction_cohorts/hf_readmiss
|
|
|
199
199
|
|
|
200
200
|
```console
|
|
201
201
|
mkdir test_finetune_results;
|
|
202
|
-
python -m cehrbert.runners.
|
|
202
|
+
python -m cehrbert.runners.hf_cehrbert_finetune_runner sample_configs/hf_cehrbert_finetuning_runner_config.yaml
|
|
203
203
|
```
|
|
204
204
|
|
|
205
205
|
## Contact us
|
|
@@ -29,6 +29,7 @@ src/cehrbert.egg-info/requires.txt
|
|
|
29
29
|
src/cehrbert.egg-info/top_level.txt
|
|
30
30
|
src/cehrbert/config/__init__.py
|
|
31
31
|
src/cehrbert/config/grid_search_config.py
|
|
32
|
+
src/cehrbert/config/output_names.py
|
|
32
33
|
src/cehrbert/data_generators/__init__.py
|
|
33
34
|
src/cehrbert/data_generators/data_classes.py
|
|
34
35
|
src/cehrbert/data_generators/data_generator_base.py
|
|
@@ -97,6 +98,7 @@ src/cehrbert/utils/stat_utils.py
|
|
|
97
98
|
tests/__init__.py
|
|
98
99
|
tests/integration_tests/__init__.py
|
|
99
100
|
tests/integration_tests/runners/__init__.py
|
|
101
|
+
tests/integration_tests/runners/hf_cehrbert_pretrain_runner_streaming_test.py
|
|
100
102
|
tests/integration_tests/runners/hf_cehrbert_pretrain_runner_test.py
|
|
101
103
|
tests/integration_tests/trainers/__init__.py
|
|
102
104
|
tests/integration_tests/trainers/train_cehr_bert_test.py
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
import unittest
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from datasets import disable_caching
|
|
9
|
+
|
|
10
|
+
from cehrbert.runners.hf_cehrbert_pretrain_runner import main
|
|
11
|
+
|
|
12
|
+
disable_caching()
|
|
13
|
+
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
|
14
|
+
os.environ["WANDB_MODE"] = "disabled"
|
|
15
|
+
os.environ["TRANSFORMERS_VERBOSITY"] = "info"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class HfCehrBertRunnerIntegrationTest(unittest.TestCase):
|
|
19
|
+
def setUp(self):
|
|
20
|
+
# Get the root folder of the project
|
|
21
|
+
root_folder = Path(os.path.abspath(__file__)).parent.parent.parent.parent
|
|
22
|
+
data_folder = os.path.join(root_folder, "sample_data", "pretrain")
|
|
23
|
+
# Create a temporary directory to store model and tokenizer
|
|
24
|
+
self.temp_dir = tempfile.mkdtemp()
|
|
25
|
+
self.model_folder_path = os.path.join(self.temp_dir, "model")
|
|
26
|
+
Path(self.model_folder_path).mkdir(parents=True, exist_ok=True)
|
|
27
|
+
self.dataset_prepared_path = os.path.join(self.temp_dir, "dataset_prepared_path")
|
|
28
|
+
Path(self.dataset_prepared_path).mkdir(parents=True, exist_ok=True)
|
|
29
|
+
sys.argv = [
|
|
30
|
+
"hf_cehrbert_pretraining_runner.py",
|
|
31
|
+
"--model_name_or_path",
|
|
32
|
+
self.model_folder_path,
|
|
33
|
+
"--tokenizer_name_or_path",
|
|
34
|
+
self.model_folder_path,
|
|
35
|
+
"--output_dir",
|
|
36
|
+
self.model_folder_path,
|
|
37
|
+
"--data_folder",
|
|
38
|
+
data_folder,
|
|
39
|
+
"--dataset_prepared_path",
|
|
40
|
+
self.dataset_prepared_path,
|
|
41
|
+
"--max_steps",
|
|
42
|
+
"10",
|
|
43
|
+
"--streaming",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
def tearDown(self):
|
|
47
|
+
# Remove the temporary directory
|
|
48
|
+
shutil.rmtree(self.temp_dir)
|
|
49
|
+
|
|
50
|
+
def test_train_model(self):
|
|
51
|
+
main()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if __name__ == "__main__":
|
|
55
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/meds_utils.py
RENAMED
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/data_generators/hf_data_generator/patient_block.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/model_evaluators/bert_model_evaluators.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/src/cehrbert/evaluations/model_evaluators/model_evaluators.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/data_generators/hf_data_generator/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/models/concept_value_decoder_layer_test.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/models/hf_models/tokenization_hf_cehrbert_test.py
RENAMED
|
File without changes
|
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/utils/truncated_offline_statistics_test.py
RENAMED
|
File without changes
|
{cehrbert-1.2.4 → cehrbert-1.2.6}/tests/unit_tests/utils/truncated_online_statistics_test.py
RENAMED
|
File without changes
|