Skip to content

Commit

Permalink
[v2] Added Celiac Disease use case
Browse files Browse the repository at this point in the history
Added Celiac Disease use case
  • Loading branch information
mntlra committed Apr 18, 2023
1 parent f6619c7 commit d9a3fcc
Show file tree
Hide file tree
Showing 15 changed files with 8,730 additions and 13,418 deletions.
4 changes: 2 additions & 2 deletions compute_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np

parser = argparse.ArgumentParser()
parser.add_argument('--outputs', default='./outputs/concepts/refined/colon/*.json', type=str, help='SKET results file.')
parser.add_argument('--use_case', default='colon', choices=['colon', 'cervix', 'lung'], help='Considered use-case.')
parser.add_argument('--outputs', default='./outputs/concepts/refined/aoec/colon/*.json', type=str, help='SKET results file.')
parser.add_argument('--use_case', default='colon', choices=['colon', 'cervix', 'lung', 'celiac'], help='Considered use-case.')
args = parser.parse_args()


Expand Down
3 changes: 3 additions & 0 deletions dataset/original/celiac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Celiac datasets

Put here datasets containing Celiac Disease pathology reports.
41 changes: 26 additions & 15 deletions evaluate_sket.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@


parser = argparse.ArgumentParser()
parser.add_argument('--gt', default='./ground_truth/lung/aoec/lung_labels_allDS.json', type=str, help='Ground truth file.')
parser.add_argument('--outputs', default='./outputs/labels/aoec/lung/*.json', type=str, help='SKET results file.')
parser.add_argument('--use_case', default='lung', choices=['colon', 'cervix', 'lung'], help='Considered use-case.')
parser.add_argument('--gt', default='./ground_truth/celiac/aoec/celiac_labels_allDS.json', type=str, help='Ground truth file.')
parser.add_argument('--outputs', default='./outputs/labels/aoec/celiac/*.json', type=str, help='SKET results file.')
parser.add_argument('--use_case', default='celiac', choices=['colon', 'cervix', 'lung', 'celiac'], help='Considered use-case.')
parser.add_argument('--hospital', default='aoec', choices=['aoec', 'radboud'], help='Considered hospital.')
parser.add_argument('--debug', default=False, action='store_true', help='Whether to use evaluation for debugging purposes.')
args = parser.parse_args()
Expand Down Expand Up @@ -41,6 +41,11 @@
'Cancer - non-small cell cancer, squamous cell carcinoma': 'cancer_nscc_squamous',
'Cancer - small cell cancer': 'cancer_scc',
'Cancer - non-small cell cancer, large cell carcinoma': 'cancer_nscc_large'
},
'celiac': {
'Normal': 'normal',
'Celiac disease': 'celiac_disease',
'Non-specific duodenitis': 'duodenitis',
}
}

Expand All @@ -56,22 +61,25 @@ def main():

gt = {}
# prepare ground-truth for evaluation
if args.use_case == 'colon' and args.hospital == 'aoec':
gt = ground_truth
if args.hospital == 'aoec' or args.use_case == 'celiac':
ground_truth = ground_truth['groundtruths']
else:
ground_truth = ground_truth['ground_truth']
for data in ground_truth:
for data in ground_truth:
if args.hospital == 'aoec' or args.use_case == 'celiac':
rid = data['id_report']
else:
rid = data['report_id_not_hashed']

if len(rid.split('_')) == 3 and args.hospital == 'aoec': # contains codeint info not present within new processed reports
rid = rid.split('_')
rid = rid[0] + '_' + rid[2]
if len(rid.split('_')) == 3 and args.hospital == 'aoec': # contains codeint info not present within new processed reports
rid = rid.split('_')
rid = rid[0] + '_' + rid[2]

gt[rid] = {label2class[args.use_case][label]: 0 for label in label2class[args.use_case].keys()}
for datum in data['labels']:
label = label2class[args.use_case][datum['label']]
if label in gt[rid]:
gt[rid][label] = 1
gt[rid] = {label2class[args.use_case][label]: 0 for label in label2class[args.use_case].keys()}
for datum in data['labels']:
label = label2class[args.use_case][datum['label']]
if label in gt[rid]:
gt[rid][label] = 1
# gt name
gt_name = args.gt.split('/')[-1].split('.')[0]

Expand All @@ -93,14 +101,16 @@ def main():
for rid, rdata in rs.items():
if args.use_case == 'colon' and args.hospital == 'aoec' and '2ndDS' in args.gt:
rid = rid.split('_')[0]
if args.hospital == 'radboud' and args.use_case == 'colon':
if args.hospital == 'radboud':
sket[rid] = rdata['labels']
else:
sket[rid] = rdata

# fix class order to avoid inconsistencies
rids = list(sket.keys())
classes = list(sket[rids[0]].keys())
if args.use_case == 'celiac':
classes.remove('inconclusive')

# obtain ground-truth and SKET scores
gt_scores = []
Expand All @@ -118,6 +128,7 @@ def main():
if args.debug:
first = True
for c in classes:
#if c != 'inconclusive':
gt_rscores.append(gt[rid][c])
sket_rscores.append(sket[rid][c])
if args.debug: # perform debugging
Expand Down
23 changes: 12 additions & 11 deletions run_med_sket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
warnings.filterwarnings("ignore", message=r"\[W008\]", category=UserWarning)

parser = argparse.ArgumentParser()
parser.add_argument('--src_lang', default='it', type=str, help='Considered source language.')
parser.add_argument('--use_case', default='colon', choices=['colon', 'cervix', 'lung'], help='Considered use-case.')
parser.add_argument('--src_lang', default='en', type=str, help='Considered source language.')
parser.add_argument('--use_case', default='celiac', choices=['colon', 'cervix', 'lung', 'celiac'], help='Considered use-case.')
parser.add_argument('--spacy_model', default='en_core_sci_sm', type=str, help='Considered NLP spacy model.')
parser.add_argument('--w2v_model', default=False, action='store_true', help='Considered word2vec model.')
parser.add_argument('--w2v_model', default=True, action='store_true', help='Considered word2vec model.')
parser.add_argument('--fasttext_model', default=None, type=str, help='File path for FastText model.')
parser.add_argument('--bert_model', default=None, type=str, help='Considered BERT model.')
parser.add_argument('--string_model', default=False, action='store_true', help='Considered string matching model.')
parser.add_argument('--string_model', default=True, action='store_true', help='Considered string matching model.')
parser.add_argument('--gpu', default=None, type=int, help='Considered GPU device. If not specified (default to None), use CPU instead.')
parser.add_argument('--thr', default=0.9, type=float, help='Similarity threshold.')
parser.add_argument('--store', default=False, action='store_true', help='Whether to store concepts, labels, and graphs.')
parser.add_argument('--thr', default=1.8, type=float, help='Similarity threshold.')
parser.add_argument('--store', default=True, action='store_true', help='Whether to store concepts, labels, and graphs.')
parser.add_argument('--rdf_format', default='all', choices=['n3', 'trig', 'turtle', 'all'], help='Whether to specify the rdf format for graph serialization. If "all" is specified, serialize w/ the three different formats')
parser.add_argument('--raw', default=False, action='store_true', help='Whether to consider full pipeline or not.')
parser.add_argument('--debug', default=False, action='store_true', help='Whether to use flags for debugging.')
parser.add_argument('--dataset', default='', type=str, help='Dataset file path.')
parser.add_argument('--preprocess', default=True, action='store_true', help='Whether to preprocess input data or not.')
parser.add_argument('--dataset', default=None, type=str, help='Dataset file path.')
args = parser.parse_args()


Expand All @@ -31,14 +32,14 @@ def main():
dataset = args.dataset
else: # use sample "stream" dataset
dataset = {
'text': 'adenocarcinoma con displasia lieve, focalmente severa. Risultati ottenuti con biopsia al colon.',
'gender': 'M',
"text": "polyp 40 cm: tubular adenoma with moderate dysplasia.",
'gender': 'F',
'age': 56,
'id': 'test'
'id': 'test_colon'
}

# use SKET pipeline to extract concepts, labels, and graphs from dataset
sket.med_pipeline(dataset, args.src_lang, args.use_case, args.thr, args.store, args.rdf_format, args.raw, args.debug)
sket.med_pipeline(dataset, args.preprocess, args.src_lang, args.use_case, args.thr, args.store, args.rdf_format, args.raw, args.debug)

if args.raw:
print('processed data up to concepts.')
Expand Down
16 changes: 8 additions & 8 deletions run_sket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
warnings.filterwarnings("ignore", message=r"\[W008\]", category=UserWarning)

parser = argparse.ArgumentParser()
parser.add_argument('--dataset', default='./dataset/original/colon/radboud/ExaMode_3rdDS_Radboudumc_Colon_2ndBatch.xlsx', type=str, help='Dataset file.')
parser.add_argument('--sheet', default='Sheet1', type=str, help='Considered dataset sheet.')
parser.add_argument('--dataset', default='./dataset/original/celiac/aoec/ExaMode_0thDS_AOEC_Celiac.xlsx', type=str, help='Dataset file.')
parser.add_argument('--sheet', default='Sheet 1', type=str, help='Considered dataset sheet.')
parser.add_argument('--header', default=0, type=str, help='Header row within dataset.')
parser.add_argument('--ver', default=1, type=str, help='Considered versioning for operations.')
parser.add_argument('--use_case', default='colon', choices=['colon', 'cervix', 'lung'], help='Considered use-case.')
parser.add_argument('--hospital', default='radboud', choices=['aoec', 'radboud'], help='Considered hospital.')
parser.add_argument('--ver', default=2, type=str, help='Considered versioning for operations.')
parser.add_argument('--use_case', default='celiac', choices=['colon', 'cervix', 'lung', 'celiac'], help='Considered use-case.')
parser.add_argument('--hospital', default='aoec', choices=['aoec', 'radboud'], help='Considered hospital.')
parser.add_argument('--spacy_model', default='en_core_sci_sm', type=str, help='Considered NLP spacy model.')
parser.add_argument('--w2v_model', default=False, action='store_true', help='Considered word2vec model.')
parser.add_argument('--w2v_model', default=True, action='store_true', help='Considered word2vec model.')
parser.add_argument('--fasttext_model', default=None, type=str, help='File path for FastText model.')
parser.add_argument('--bert_model', default=None, type=str, help='Considered BERT model.')
parser.add_argument('--string_model', default=False, action='store_true', help='Considered string matching model.')
parser.add_argument('--string_model', default=True, action='store_true', help='Considered string matching model.')
parser.add_argument('--gpu', default=None, type=int, help='Considered GPU device. If not specified (default to None), use CPU instead.')
parser.add_argument('--thr', default=2.0, type=float, help='Similarity threshold.')
parser.add_argument('--thr', default=1.8, type=float, help='Similarity threshold.')
parser.add_argument('--raw', default=False, action='store_true', help='Whether to return concepts within semantic areas (deployment) or mentions+concepts (debugging)')
parser.add_argument('--debug', default=False, action='store_true', help='Whether to use flags for debugging.')
args = parser.parse_args()
Expand Down
Loading

0 comments on commit d9a3fcc

Please sign in to comment.