jd['char_embedding_dim'], jd['char_lstm_hidden_dim'], 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))
optimizer.load_state_dict(checkpoint_file['optimizer']) model.cuda() packer = Repack() tot_length = sum(map(lambda t: len(t), dataset_loader)) best_dev_f1_jnt = float('-inf') best_test_f1_crf = float('-inf') best_test_f1_scrf = float('-inf') best_test_f1_jnt = float('-inf') start_time = time.time() early_stop_epochs = 0 epoch_list = range(args.start_epoch, args.start_epoch + args.epoch) evaluator = evaluator(packer, CRF_l_map, SCRF_l_map) for epoch_idx, args.start_epoch in enumerate(epoch_list): epoch_loss = 0 model.train() if dataset_loader_crf: for f_f, f_p, b_f, b_p, w_f, tg_v, mask_v, len_v, SCRF_labels, mask_SCRF_labels, cnn_features in tqdm( itertools.chain.from_iterable(dataset_loader_crf), mininterval=2, desc=' - Tot it %d (epoch %d)' % (tot_length, args.start_epoch), leave=False, file=sys.stderr): f_f, f_p, b_f, b_p, w_f, tg_v, mask_v, SCRF_labels, mask_SCRF_labels, cnn_features = packer.repack(f_f, f_p, b_f, b_p, w_f, tg_v, mask_v, len_v, SCRF_labels, mask_SCRF_labels, cnn_features, test=False) optimizer.zero_grad() loss = model(f_f, f_p, b_f, b_p, w_f, cnn_features, tg_v, mask_v,