@@ -127,9 +127,9 @@ def train(self, textfile, annotfile, glovefile, runname):
127127 # Get training and test sequences
128128 cr = CorpusReader (textfile , annotfile )
129129 train = cr .trainseqs
130- test = cr .testseqs
130+ # test = cr.testseqs
131131
132- seqs = train + test
132+ seqs = train # +test
133133
134134 # Initialise some stuff
135135 toklist = []
@@ -268,55 +268,7 @@ def train(self, textfile, annotfile, glovefile, runname):
268268 print ("Trained at" , datetime .now (), "Loss" , totloss /
269269 div , "Accuracy" , totacc / div , file = sys .stderr )
270270 self .model .save ("epoch_%s_%s.h5" % (epoch , runname ))
271- # Evaluate
272- tp_all = 0
273- fp_all = 0
274- fn_all = 0
275- for i in range (len (test )):
276- enttype = None
277- entstart = 0
278- ts = test [i ]
279- ents = [("E" , i [2 ], i [3 ]) for i in ts ["ents" ]]
280- mm = model .predict (
281- [np .array ([ts ["wordn" ]]), np .array ([ts ["ni" ]])])[0 ]
282-
283- pseq = {}
284- pseq ["tokens" ] = ts ["tokens" ]
285- pseq ["tokstart" ] = ts ["tokstart" ]
286- pseq ["tokend" ] = ts ["tokend" ]
287- pseq ["tagfeat" ] = mm
288-
289- pents , pxe = sobie_scores_to_char_ents (pseq , 0.5 , ts ["ss" ])
290- tp = 0
291- fp = 0
292- fn = 0
293- tofind = set (ents )
294- for ent in pents :
295- if ent in tofind :
296- tp += 1
297- else :
298- fp += 1
299- fn = len (tofind ) - tp
300- tp_all += tp
301- fp_all += fp
302- fn_all += fn
303-
304- try :
305- f = (2 * tp_all / (tp_all + tp_all + fp_all + fn_all ))
306- print ("TP" , tp_all , "FP" , fp_all , "FN" , fn_all , "F" , f , "Precision" ,
307- tp_all / (tp_all + fp_all ), "Recall" , tp_all / (tp_all + fn_all ), file = sys .stderr )
308- except (ZeroDivisionError ):
309- print ('No metabolite labelled.' )
310- f = 0
311- if f > best_f :
312- print ("Best so far" , file = sys .stderr )
313- best_f = f
314- best_epoch = epoch
315-
316- if best_epoch > - 1 :
317- shutil .copyfile ("epoch_%s_%s.h5" %
318- (best_epoch , runname ), "metabolistem_%s.h5" % runname )
319-
271+
320272 def load (self , jfile , mfile ):
321273 """
322274 Load in model data.
0 commit comments