forked from rishabgit/genomic-info-from-papers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprecision.py
68 lines (55 loc) · 1.96 KB
/
precision.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from sklearn.metrics import precision_recall_fscore_support
def precision(mf_mut_extract, tmvar_mut_extract, custom_mut_extract, bow_mut_extract):
## # 3 Testing
## Using the IDP4+ dataset downloaded and setup in notebook 1.
nala_db = pd.read_csv('data/nala/nala_binary.csv').to_numpy()
## ### 3.1 RegEx
y_true = []
y_pred = []
print('Total sentences to process: ', len(nala_db))
for i, row in enumerate(nala_db):
if (i+1) % 500 == 0: print(f"{i+1}", end = " ")
sentence = row[0]
true = row[1]
if regex_block(settings, sentence):
pred = 1
else:
pred = 0
y_true.append(true)
y_pred.append(pred)
precision_recall_fscore_support(y_true, y_pred, average='binary')
# 3.3 RegEx (custom) + NER
#y_true = []
#y_pred = []
#start_time = time.time()
#print('Total sentences to process: ', len(nala_db))
#for i, row in enumerate(nala_db):
#if (i+1) % 500 == 0: print(f"{i+1}", end = " ")
#if (i+1) % 1000 == 0:
#print('Time for 1000 lines:', int((time.time() - start_time)/60))
#start_time = time.time()
#sentence = row[0]
#true = row[1]
#if regex_block(sentence) or ner_mutations(sentence):
#pred = 1
#else:
#pred = 0
#y_true.append(true)
#y_pred.append(pred)
#precision_recall_fscore_support(y_true, y_pred, average='binary')
# 3.2 BioBERT NER
y_true = []
y_pred = []
print('Total sentences to process: ', len(nala_db))
for i, row in enumerate(nala_db):
if (i+1) % 500 == 0: print(f"{i+1}", end = " ")
sentence = row[0]
true = row[1]
if ner_mutations(nala_ner, sentence):
pred = 1
else:
pred = 0
y_true.append(true)
y_pred.append(pred)
precision_recall_fscore_support(y_true, y_pred, average='binary')
# taking too long to execute - not tested