Esempio n. 1
0
        use_small = True
        gpu = args.gpu
        batch_size = 16
    else:
        use_small = False
        gpu = args.gpu
        batch_size = 64

    dev_sql, dev_table, dev_db, test_sql, test_table, test_db = load_dataset(
        use_small=use_small, mode='test')
    #train_sql, train_table, train_db, dev_sql, dev_table, dev_db = load_dataset(use_small=use_small, mode='test')
    model_bert, tokenizer, bert_config = get_bert(bert_path)
    model = SQLNet(N_word=n_word,
                   use_ca=args.ca,
                   gpu=gpu,
                   trainable_emb=args.train_emb)

    model_path = 'saved_model/best_model'
    print("Loading from %s" % model_path)
    model.load_state_dict(torch.load(model_path, map_location='cpu'))
    print("Loaded model from %s" % model_path)
    dev_acc = epoch_acc(model_bert, tokenizer, model, batch_size, dev_sql,
                        dev_table, dev_db, args.mode_type)
    print('Dev Logic Form Accuracy: %.3f, Execution Accuracy: %.3f' %
          (dev_acc[1], dev_acc[2]))

    print("Start to predict test set")
    predict_test(model_bert, tokenizer, model, batch_size, test_sql,
                 test_table, args.output_dir)
    print("Output path of prediction result is %s" % args.output_dir)
Esempio n. 2
0
        '/media/yinshuai/d8644f6c-5a97-4e12-909b-b61d2271b61c/nlp-datasets/nlp2sql/char_embedding'
    )

    model = SQLNet(word_emb,
                   N_word=n_word,
                   use_ca=args.ca,
                   gpu=gpu,
                   trainable_emb=args.train_emb)
    optimizer = torch.optim.Adam(model.parameters(),
                                 lr=learning_rate,
                                 weight_decay=0)

    if args.restore:
        model_path = 'saved_model/best_model_32'
        print "Loading trained model from %s" % model_path
        model.load_state_dict(torch.load(model_path))

    # used to record best score of each sub-task
    best_sn, best_sc, best_sa, best_wn, best_wc, best_wo, best_wv, best_wr = 0, 0, 0, 0, 0, 0, 0, 0
    best_sn_idx, best_sc_idx, best_sa_idx, best_wn_idx, best_wc_idx, best_wo_idx, best_wv_idx, best_wr_idx = 0, 0, 0, 0, 0, 0, 0, 0
    best_lf, best_lf_idx = 0.0, 0
    best_ex, best_ex_idx = 0.0, 0

    print "#" * 20 + "  Star to Train  " + "#" * 20
    for i in range(args.epoch):
        print 'Epoch %d' % (i + 1)
        # train on the train dataset
        # train_sql: a json list treated from train.json
        # train_table: a dict treated from table.json
        train_loss = epoch_train(model, optimizer, batch_size, train_sql,
                                 train_table)