Update Mimic4Dataset.py
Browse files- Mimic4Dataset.py +38 -2
Mimic4Dataset.py
CHANGED
@@ -28,6 +28,7 @@ _HOMEPAGE = "https://huggingface.co/datasets/thbndi/Mimic4Dataset"
|
|
28 |
_CITATION = "https://proceedings.mlr.press/v193/gupta22a.html"
|
29 |
_GIT_URL = "https://github.com/healthylaife/MIMIC-IV-Data-Pipeline"
|
30 |
|
|
|
31 |
_DATA_GEN = f"{_BASE_URL}/data_generation_icu_modify.py"
|
32 |
_DATA_GEN_HOSP= f"{_BASE_URL}/data_generation_modify.py"
|
33 |
_DAY_INT= f"{_BASE_URL}/day_intervals_cohort_v22.py"
|
@@ -164,6 +165,10 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
164 |
|
165 |
|
166 |
#####################downloads modules from hub
|
|
|
|
|
|
|
|
|
167 |
if not os.path.exists('./model/data_generation_icu_modify.py'):
|
168 |
file_path, head = urlretrieve(_DATA_GEN, "data_generation_icu_modify.py")
|
169 |
shutil.move(file_path, './model')
|
@@ -506,7 +511,39 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
506 |
'CHART/LAB': lab,
|
507 |
'OUT': out,
|
508 |
}
|
509 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
510 |
#############################################################################################################################
|
511 |
def _info(self):
|
512 |
self.path = self.init_cohort()
|
@@ -520,7 +557,6 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
520 |
else:
|
521 |
return self._info_raw()
|
522 |
|
523 |
-
|
524 |
def _split_generators(self, dl_manager):
|
525 |
data_dir = "./data/dict/"+self.config.name.replace(" ","_")
|
526 |
if self.val_size > 0 :
|
|
|
28 |
_CITATION = "https://proceedings.mlr.press/v193/gupta22a.html"
|
29 |
_GIT_URL = "https://github.com/healthylaife/MIMIC-IV-Data-Pipeline"
|
30 |
|
31 |
+
_ICD_CODE = f"{_BASE_URL}/icd10.txt"
|
32 |
_DATA_GEN = f"{_BASE_URL}/data_generation_icu_modify.py"
|
33 |
_DATA_GEN_HOSP= f"{_BASE_URL}/data_generation_modify.py"
|
34 |
_DAY_INT= f"{_BASE_URL}/day_intervals_cohort_v22.py"
|
|
|
165 |
|
166 |
|
167 |
#####################downloads modules from hub
|
168 |
+
if not os.path.exists('./icd10.txt'):
|
169 |
+
file_path, head = urlretrieve(_ICD_CODE, "icd10.txt")
|
170 |
+
shutil.move(file_path, './')
|
171 |
+
|
172 |
if not os.path.exists('./model/data_generation_icu_modify.py'):
|
173 |
file_path, head = urlretrieve(_DATA_GEN, "data_generation_icu_modify.py")
|
174 |
shutil.move(file_path, './model')
|
|
|
511 |
'CHART/LAB': lab,
|
512 |
'OUT': out,
|
513 |
}
|
514 |
+
######################################################text##############################################################
|
515 |
+
def _info_text(self):
|
516 |
+
features = datasets.Features(
|
517 |
+
{
|
518 |
+
"label": datasets.ClassLabel(num_classes=2,names=["0", "1"]),
|
519 |
+
"COND" : datasets.Value(dtype='string', id=None),
|
520 |
+
}
|
521 |
+
)
|
522 |
+
return datasets.DatasetInfo(
|
523 |
+
description=_DESCRIPTION,
|
524 |
+
features=features,
|
525 |
+
homepage=_HOMEPAGE,
|
526 |
+
citation=_CITATION,
|
527 |
+
)
|
528 |
+
|
529 |
+
def _generate_examples_text(self, filepath):
|
530 |
+
icd = pd.read_csv('icd10.txt',names=['code','description'],sep='\t')
|
531 |
+
with open(filepath, 'rb') as fp:
|
532 |
+
dico = pickle.load(fp)
|
533 |
+
for key, data in dico.items():
|
534 |
+
conds = data['Cond']['fids']
|
535 |
+
text=[]
|
536 |
+
for code in conds:
|
537 |
+
desc = icd[icd['code']==code]
|
538 |
+
if not desc.empty:
|
539 |
+
text.append(desc['description'].to_string(index=False))
|
540 |
+
template = 'The patient is diagnosed with {}.'
|
541 |
+
text = template.format('; '.join(text))
|
542 |
+
yield int(key),{
|
543 |
+
'label' : data['label'],
|
544 |
+
'COND': text,
|
545 |
+
}
|
546 |
+
|
547 |
#############################################################################################################################
|
548 |
def _info(self):
|
549 |
self.path = self.init_cohort()
|
|
|
557 |
else:
|
558 |
return self._info_raw()
|
559 |
|
|
|
560 |
def _split_generators(self, dl_manager):
|
561 |
data_dir = "./data/dict/"+self.config.name.replace(" ","_")
|
562 |
if self.val_size > 0 :
|