def test(model_dir,
         input_path,
         output_path,
         beam_size=4,
         max_dec_len=60,
         dec_alpha=0.6):
    gpt2 = GPT2(config_path)
    generator = beam_search_generator(gpt2,
                                      beam_size=beam_size,
                                      model_directory=model_dir,
                                      max_dec_len=max_dec_len,
                                      dec_alpha=dec_alpha)
    sess = generator.build_graph_and_restore(
        eos_id=gpt2.text_enc.encode('\n')[0])
    lines = read_file_lines(input_path)
    result = []
    for line in lines:
        result.append(generator.generate(sess, line))
    sess.close()
    write_file_lines(output_path, result)
Exemple #2
0
def test(
        config_path,
        input_num,
        model_dir='./models/ori_rule/formality_infer/',
        input_path='../training_data/dif_models/eval.ori_rule',
        output_path='../evaluate/gyafc_model_outputs/fr_out/formal.gpt.cat_ori_rule.old',
        beam_size=4,
        max_dec_len=60,
        dec_alpha=0.6):
    gpt2 = NMT_GPT(config_path=config_path, input_num=input_num)
    generator = beam_search_generator(gpt2,
                                      beam_size=beam_size,
                                      model_directory=model_dir,
                                      max_dec_len=max_dec_len,
                                      dec_alpha=dec_alpha)
    sess = generator.build_graph_and_restore(
        eos_id=gpt2.text_enc.encode('\n')[0])
    lines = read_file_lines(input_path)
    result = []
    for line in lines:
        result.append(generator.generate(sess, line, multi_pls=True))
        print(line + ' ||| ' + result[-1].strip())
    sess.close()
    write_file_lines(output_path, result)