-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_med_sket.py
51 lines (41 loc) · 2.79 KB
/
run_med_sket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import argparse
import warnings
from sket.sket import SKET
warnings.filterwarnings("ignore", message=r"\[W008\]", category=UserWarning)
parser = argparse.ArgumentParser()
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=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=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=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('--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()
def main():
# set SKET
sket = SKET(args.use_case, args.src_lang, args.spacy_model, args.w2v_model, args.fasttext_model, args.bert_model, args.string_model, args.gpu)
if args.dataset: # use dataset from file path
dataset = args.dataset
else: # use sample "stream" dataset
dataset = {
"text": "polyp 40 cm: tubular adenoma with moderate dysplasia.",
'gender': 'F',
'age': 56,
'id': 'test_colon'
}
# use SKET pipeline to extract concepts, labels, and graphs from dataset
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.')
else:
print('full pipeline.')
if __name__ == "__main__":
main()