Beispiel #1
0
    evaluator = Evaluator(true_labels=test_true_labels, sentences=test_sentence_inputs, aspects=test_aspect_text_inputs)

    epoch = 1
    while epoch <= 50:
        model = m.train_model(sentence_inputs=train_sentence_inputs,
                              position_inputs= train_positions,
                              aspect_input=train_aspects,
                              labels=train_aspect_labels,
                              model=model)
        results = m.get_predict(sentence_inputs=test_sentence_inputs,
                            position_inputs=test_positions,
                            aspect_input=test_aspects,
                            model=model)
        print("\n--epoch"+str(epoch)+"--")
        F, acc = evaluator.get_macro_f1(predictions=results, epoch=epoch)
        if epoch % 2 == 0:
            print("current max f1 score"+str(evaluator.max_F1))
            print("max f1 is gained in epoch"+str(evaluator.max_F1_epoch))
            print("current max acc"+str(evaluator.max_acc))
            print("max acc is gained in epoch"+str(evaluator.max_acc_epoch))
        print("happy ending")

        if acc > 0.8000:
            model.save_weights(model_path+"_acc_"+str(acc*100)+"_F_"+str(F*100)+"_"+str(epoch))
        elif F > 0.7100:
            model.save_weights(model_path + "_acc_" + str(acc * 100) + "_F_" + str(F * 100) + "_" + str(epoch))
        epoch += 1