Beispiel #1
0
        jd['cnn_filter_num'], jd['char_lstm_layers'], jd['char_lstm'],
        jd['dropout_ratio'], jd['high_way'],
        jd['highway_layers'], CRF_l_map['<start>'], CRF_l_map['<pad>'],
        len(CRF_l_map), SCRF_l_map, jd['scrf_dense_dim'], in_doc_words,
        jd['index_embeds_dim'], jd['allowspan'], SCRF_l_map['<START>'],
        SCRF_l_map['<STOP>'], jd['grconv'])

    print('load model')
    model.load_state_dict(checkpoint_file['state_dict'])

    #model.cuda()
    model.to(local_device)
    packer = Repack()

    evaluator = evaluator(packer, CRF_l_map, SCRF_l_map)

    print('dev...')
    dev_f1_crf, dev_pre_crf, dev_rec_crf, dev_acc_crf, dev_f1_scrf, dev_pre_scrf, dev_rec_scrf, dev_acc_scrf, dev_f1_jnt, dev_pre_jnt, dev_rec_jnt, dev_acc_jnt = \
            evaluator.calc_score(model, dev_dataset_loader)
    print('test...')
    test_f1_crf, test_pre_crf, test_rec_crf, test_acc_crf, test_f1_scrf, test_pre_scrf, test_rec_scrf, test_acc_scrf, test_f1_jnt, test_pre_jnt, test_rec_jnt, test_acc_jnt = \
            evaluator.calc_score(model, test_dataset_loader)

    print(' dev_f1: %.4f\n' % (dev_f1_crf))
    print(' dev_f1_scrf: %.4f\n' % (dev_f1_scrf))
    print(' dev_f1_jnt: %.4f\n' % (dev_f1_jnt))

    print(' test_f1: %.4f\n' % (test_f1_crf))
    print(' test_f1_scrf: %.4f\n' % (test_f1_scrf))
    print(' test_f1_jnt: %.4f\n' % (test_f1_jnt))
Beispiel #2
0
            loss = model(f_f, f_p, b_f, b_p, w_f, cnn_features, tg_v, mask_v,
                         mask_v.long().sum(0), SCRF_labels, mask_SCRF_labels, onlycrf=False)

            epoch_loss += utils.to_scalar(loss)
            loss.backward()
            nn.utils.clip_grad_norm(model.parameters(), args.clip_grad)
            optimizer.step()

        epoch_loss /= tot_length
        print('epoch_loss: ', epoch_loss)

        utils.adjust_learning_rate(optimizer, args.lr / (1 + (args.start_epoch + 1) * args.lr_decay))


        dev_f1_crf, dev_pre_crf, dev_rec_crf, dev_acc_crf, dev_f1_scrf, dev_pre_scrf, dev_rec_scrf, dev_acc_scrf, dev_f1_jnt, dev_pre_jnt, dev_rec_jnt, dev_acc_jnt = \
                evaluator.calc_score(model, dev_dataset_loader)

        if dev_f1_jnt > best_dev_f1_jnt:
            early_stop_epochs = 0
            test_f1_crf, test_pre_crf, test_rec_crf, test_acc_crf, test_f1_scrf, test_pre_scrf, test_rec_scrf, test_acc_scrf, test_f1_jnt, test_pre_jnt, test_rec_jnt, test_acc_jnt = \
                        evaluator.calc_score(model, test_dataset_loader)

            best_test_f1_crf = test_f1_crf
            best_test_f1_scrf = test_f1_scrf

            best_dev_f1_jnt = dev_f1_jnt
            best_test_f1_jnt = test_f1_jnt

            try:
                utils.save_checkpoint({
                        'epoch': args.start_epoch,