def on_epoch_end(self, epoch, logs=None): print("pridict_dev") pred_dev_y = model.predict( [dev_x_indices, dev_x_segments, dev_entity1_pos, dev_entity2_pos], batch_size=batch_size, verbose=0) # best_threshold, best_scores = threshold_search(y_develop,pred_dev_y) precision, recall, best_score = f1(dev_y, (pred_dev_y > 0.5).astype(int)) print( "epoch###################################################################################################" ) print("- dev F1 Score: {:.4f}".format(best_score)) logging.info("- dev F1 Score: " + str(best_score)) pred_test_y = model.predict([ test_x_indices, test_x_segments, test_entity1_pos, test_entity2_pos ], batch_size=batch_size, verbose=0) p, r, f = f1(test_y, (pred_test_y > 0.5).astype(int)) print("- Val F1 Score: {:.4f}".format(f)) logging.info("- Val p Score:" + str(p)) logging.info("- Val r Score:" + str(r)) logging.info("- Val F1 Score:" + str(f)) if f > 0.6: save_file("bert_hua_cea_" + str(f) + "_predict", pred_test_y) model.save('./models/bert_hua_cea_' + str(f) + '.h5')
def post_process(predict_file): test_entity = load_pkl('test_doc_entity_list') true_y=load_pkl('tests_y') file = open('../result/' + predict_file, 'rb') predict = pickle.load(file) file.close() test = load_pkl('test_doc_entity') y,y_dict=ansisy_predict(predict,test_entity) doc_dict=ansis_doc(test) new_y = match(y,y_dict,test_entity,doc_dict) # p, r, f = f1(true_y, (predict > 0.5).astype(int)) p1, r1, f_1 = f1(true_y, new_y) # print(f) print(f_1) print("///////") return new_y,true_y
def post2(predict_file, delete_list,true_y,predict): # true_y = load_pkl('tests_y') # file = open('../result/' + predict_file, 'rb') # predict = pickle.load(file) # file.close() new_pre=[] new_y=[] index=0 for i in range(len(predict)): if i not in delete_list: new_pre.append(predict[i]) new_y.append(true_y[i]) new_pre=np.array(new_pre) new_y = np.array(new_y) # p, r, f = f1(true_y, (predict > 0.5).astype(int)) p1, r1, f_1 = f1(new_y, (new_pre > 0.5).astype(int)) # print(f) print(f_1)
intre_predict.append(1) else: intre_predict.append(0) true_y = true_y.tolist() for i in range(len(true_y)): if i in list: temp = true_y[i][0] intre_true_y.append(true_y[i][0]) return intre_predict, intre_true_y if __name__ == "__main__": test_inter_sen_list = load_pkl('test_delete_list') list = test_inter_sen_list[0] file = open('../result/' + '0.5632286995515694_predict', 'rb') predict = pickle.load(file) file.close() true_y = load_pkl('tests_y') intra_predict, intra_true_y = intra_sen_classify(list, predict, true_y) intre_predict, intre_true_y = inter_sen_classify(list, predict, true_y) p1, r1, f_1 = f1(intra_true_y, intra_predict) print(f_1) p2, r2, f_2 = f1(intre_true_y, intre_predict) print(f_2) print()