Example #1
0
        ga.train(train, dev, gtrain, dir_name, batch_size, glove, beam_size, 
               epoch_size, dev_sample_size, cmodel, gen_epochs)

    if method == 'augment':
        gtrain = gm.gen_train(len(train[0]), g_hidden_size, latent_size, glove, hypo_len, version)
        gtrain.load_weights(dir_name + '/weights.hdf5')
        gtest = gm.gen_test(gtrain, glove, batch_size)
        augment.new_generate_save(dev, dir_name, augment_file_size, gtest, beam_size, hypo_len, 
                                  latent_size, cmodel, wi, 'dev', len(dev[0]), aug_threshold)
        augment.new_generate_save(train, dir_name, augment_file_size, gtest, beam_size, hypo_len,
                                  latent_size, cmodel, wi, 'train', len(train[0]), aug_threshold)
     
    if method == 'train_class':
       for t in thresholds:
           if type(t) == str and t[0] == 'a':
               aug_train, aug_dev = augment.load_dataset(dir_name, True, 2**30, 2**30, wi, prem_len, hypo_len)
               aug_dev = aa.filter_adverserial(aug_dev, t, len(dev[0]), dir_name, glove, a_hidden_size)
               aug_train = aa.filter_adverserial(aug_train, t, len(train[0]), dir_name, glove, a_hidden_size)
           else:
               aug_train, aug_dev = augment.load_dataset(dir_name, t, len(train[0]), len(dev[0]), wi, prem_len, hypo_len)
           
           aug_cmodel = cm.attention_model(c_hidden_size, glove)
           ca.train(aug_train, aug_dev, aug_cmodel, dir_name + '/threshold' + str(t), batch_size)

    if method == 'train_discriminator':
        aug_train, aug_dev = augment.load_dataset(dir_name, 0.0, len(train[0]), len(dev[0]), wi, prem_len, hypo_len)
        aa.adverse_model_train(dir_name, train, aug_train, dev, aug_dev, a_hidden_size, glove)
      
    if method == 'evaluate':
        csvf =  open(dir_name + '/total_eval.csv', 'wb')
        writer = csv.writer(csvf)
Example #2
0
def evaluate_model(dir_name, dev, wi, metrics):
    aug_train, aug_dev = augment.load_dataset(dir_name, 0.0, len(dev[0]),
                                              len(dev[0]), wi, 25, 15)
    gts, res = process_input(dev[1], aug_dev[1], wi)
    return evaluate(gts, res, metrics)
Example #3
0
    if method == 'augment':
        gtrain = gm.gen_train(len(train[0]), g_hidden_size, latent_size, glove,
                              hypo_len, version)
        gtrain.load_weights(dir_name + '/weights.hdf5')
        gtest = gm.gen_test(gtrain, glove, batch_size)
        augment.new_generate_save(dev, dir_name, augment_file_size, gtest,
                                  beam_size, hypo_len, latent_size, cmodel, wi,
                                  'dev', len(dev[0]), aug_threshold)
        augment.new_generate_save(train, dir_name, augment_file_size, gtest,
                                  beam_size, hypo_len, latent_size, cmodel, wi,
                                  'train', len(train[0]), aug_threshold)

    if method == 'train_class':
        for t in thresholds:
            if type(t) == str and t[0] == 'a':
                aug_train, aug_dev = augment.load_dataset(
                    dir_name, True, 2**30, 2**30, wi, prem_len, hypo_len)
                aug_dev = aa.filter_adverserial(aug_dev, t, len(dev[0]),
                                                dir_name, glove, a_hidden_size)
                aug_train = aa.filter_adverserial(aug_train, t, len(train[0]),
                                                  dir_name, glove,
                                                  a_hidden_size)
            else:
                aug_train, aug_dev = augment.load_dataset(
                    dir_name, t, len(train[0]), len(dev[0]), wi, prem_len,
                    hypo_len)

            aug_cmodel = cm.attention_model(c_hidden_size, glove)
            ca.train(aug_train, aug_dev, aug_cmodel,
                     dir_name + '/threshold' + str(t), batch_size)

    if method == 'train_adverse':
Example #4
0
def evaluate_model(dir_name, dev, wi, metrics):
    aug_train, aug_dev = augment.load_dataset(dir_name, 0.0, len(dev[0]), len(dev[0]), wi, 25, 15)
    gts, res = process_input(dev[1], aug_dev[1], wi)
    return evaluate(gts, res, metrics)