wmotte commited on
Commit
2052ba5
1 Parent(s): b8f8d63

Test results

Browse files
Files changed (2) hide show
  1. example.py +64 -0
  2. test_results.txt +16 -0
example.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ # load NERDA functionality
4
+ from NERDA.models import NERDA
5
+
6
+ ###
7
+ # Load finetuned model, based on microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract
8
+ ##
9
+ def load_finetuned_model():
10
+
11
+ # model file
12
+ finetuned_model = 'model/trained_ner_model.bin'
13
+
14
+ # the IOB tagging scheme: words that are beginning of named entities
15
+ # are tagged with 'B-' and words 'inside' (=continuations of)
16
+ # named entities are tagged with 'I-'.
17
+ tag_scheme = [ 'B-Patient',
18
+ 'I-Patient',
19
+ 'B-Intervention',
20
+ 'I-Intervention',
21
+ 'B-Control',
22
+ 'I-Control',
23
+ 'B-Outcome',
24
+ 'I-Outcome' ]
25
+
26
+ # outside text
27
+ tag_outside = 'O'
28
+
29
+ # base transformer model
30
+ transformer_name = 'microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract'
31
+
32
+ # max length of abstract
33
+ max_len = 512
34
+
35
+ # define model
36
+ model = NERDA(
37
+ tag_scheme = tag_scheme,
38
+ tag_outside = tag_outside,
39
+ max_len = max_len,
40
+ transformer = transformer_name )
41
+
42
+ # load from file
43
+ model.load_network_from_file( finetuned_model )
44
+
45
+ return( model )
46
+
47
+
48
+ # load finetuned model
49
+ model = load_finetuned_model()
50
+
51
+ # example text
52
+ text = 'Long-term outcomes after repeat doses of antenatal corticosteroids. Previous trials have shown that repeat courses of antenatal corticosteroids improve some neonatal outcomes in preterm infants but reduce birth weight and increase the risk of intrauterine growth restriction. We report long-term follow-up results of children enrolled in a randomized trial comparing single and repeat courses of antenatal corticosteroids. Women at 23 through 31 weeks of gestation who remained pregnant 7 days after an initial course of corticosteroids were randomly assigned to weekly courses of betamethasone, consisting of 12 mg given intramuscularly and repeated once at 24 hours, or an identical-appearing placebo. '
53
+
54
+ # predict PICO labels
55
+ pred = model.predict_text( text )
56
+
57
+ # print( pred[ 1 ] ) ->
58
+ #
59
+ # [
60
+ # ['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
61
+ # ['O', 'O', 'O', 'O', 'O', 'B-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],
62
+ # ['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-Intervention', 'O', 'B-Control', 'I-Control', 'I-Control', 'I-Intervention', 'I-Intervention', 'I-Intervention'],
63
+ # ['B-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'I-Patient', 'O', 'O', 'O', 'O', 'B-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'I-Intervention', 'O', 'O', 'I-Control', 'I-Control', 'I-Control']
64
+ # ]
test_results.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Fine-tuned PICO-model on test set:
2
+
3
+ Level F1-Score Precision Recall
4
+ -----------------------------------------------
5
+ B-Patient 0.723539 0.687688 0.763333
6
+ I-Patient 0.771008 0.736578 0.808815
7
+
8
+ B-Intervention 0.617827 0.606715 0.629353
9
+ I-Intervention 0.704173 0.695672 0.712885
10
+
11
+ B-Control 0.593176 0.556650 0.634831
12
+ I-Control 0.623557 0.639810 0.608108
13
+
14
+ B-Outcome 0.494802 0.504237 0.485714
15
+ I-Outcome 0.563809 0.630212 0.510065
16
+