Update Mimic4Dataset.py
Browse files- Mimic4Dataset.py +2 -42
Mimic4Dataset.py
CHANGED
@@ -11,7 +11,7 @@ from sklearn.preprocessing import LabelEncoder
|
|
11 |
import yaml
|
12 |
from .dataset_utils import vocab, concat_data, generate_deep, generate_ml
|
13 |
from .task_cohort import create_cohort
|
14 |
-
|
15 |
|
16 |
|
17 |
_DESCRIPTION = """\
|
@@ -507,39 +507,6 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
507 |
'OUT': out,
|
508 |
}
|
509 |
|
510 |
-
#############################################################################################################################
|
511 |
-
def _info_text(self):
|
512 |
-
features = datasets.Features(
|
513 |
-
{
|
514 |
-
"label": datasets.ClassLabel(num_classes=2,names=["0", "1"]),
|
515 |
-
"COND" : datasets.Value(dtype='string', id=None),
|
516 |
-
}
|
517 |
-
)
|
518 |
-
return datasets.DatasetInfo(
|
519 |
-
description=_DESCRIPTION,
|
520 |
-
features=features,
|
521 |
-
homepage=_HOMEPAGE,
|
522 |
-
citation=_CITATION,
|
523 |
-
)
|
524 |
-
|
525 |
-
def _generate_examples_text(self, filepath):
|
526 |
-
icd = pd.read_csv('icd10.txt',names=['code','description'],sep='\t')
|
527 |
-
with open(filepath, 'rb') as fp:
|
528 |
-
dico = pickle.load(fp)
|
529 |
-
for key, data in dico.items():
|
530 |
-
conds = data['Cond']['fids']
|
531 |
-
text=[]
|
532 |
-
for code in conds:
|
533 |
-
desc = icd[icd['code']==code]
|
534 |
-
if not desc.empty:
|
535 |
-
text.append(desc['description'].to_string(index=False))
|
536 |
-
template = 'The patient is diagnosed with {}.'
|
537 |
-
text = template.format('; '.join(text))
|
538 |
-
|
539 |
-
yield int(key),{
|
540 |
-
'label' : data['label'],
|
541 |
-
'COND': text,
|
542 |
-
}
|
543 |
#############################################################################################################################
|
544 |
def _info(self):
|
545 |
self.path = self.init_cohort()
|
@@ -549,10 +516,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
549 |
|
550 |
elif self.encoding == 'tensor' :
|
551 |
return self._info_deep()
|
552 |
-
|
553 |
-
elif self.encoding == 'text' :
|
554 |
-
return self._info_text()
|
555 |
-
|
556 |
else:
|
557 |
return self._info_raw()
|
558 |
|
@@ -577,9 +541,5 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
577 |
|
578 |
elif self.encoding == 'tensor' :
|
579 |
yield from self._generate_examples_deep(filepath)
|
580 |
-
|
581 |
-
elif self.encoding == 'text' :
|
582 |
-
yield from self._generate_examples_text(filepath)
|
583 |
-
|
584 |
else :
|
585 |
yield from self._generate_examples_raw(filepath)
|
|
|
11 |
import yaml
|
12 |
from .dataset_utils import vocab, concat_data, generate_deep, generate_ml
|
13 |
from .task_cohort import create_cohort
|
14 |
+
|
15 |
|
16 |
|
17 |
_DESCRIPTION = """\
|
|
|
507 |
'OUT': out,
|
508 |
}
|
509 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
510 |
#############################################################################################################################
|
511 |
def _info(self):
|
512 |
self.path = self.init_cohort()
|
|
|
516 |
|
517 |
elif self.encoding == 'tensor' :
|
518 |
return self._info_deep()
|
519 |
+
|
|
|
|
|
|
|
520 |
else:
|
521 |
return self._info_raw()
|
522 |
|
|
|
541 |
|
542 |
elif self.encoding == 'tensor' :
|
543 |
yield from self._generate_examples_deep(filepath)
|
|
|
|
|
|
|
|
|
544 |
else :
|
545 |
yield from self._generate_examples_raw(filepath)
|