示例#1
0
if __name__ == '__main__':
    tf.logging.set_verbosity(tf.logging.INFO)

    # Convert directory into checkpoints
    from_ckpt = FLAGS.from_ckpt
    to_ckpt = FLAGS.to_ckpt
    if tf.gfile.IsDirectory(FLAGS.from_ckpt):
        from_ckpt = tf.train.latest_checkpoint(FLAGS.from_ckpt)
    if tf.gfile.IsDirectory(FLAGS.to_ckpt):
        to_ckpt = tf.train.latest_checkpoint(FLAGS.to_ckpt)

    if FLAGS.backtranslate_interactively:
        decoding.backtranslate_interactively(FLAGS.from_problem,
                                             FLAGS.to_problem,
                                             FLAGS.from_data_dir,
                                             FLAGS.to_data_dir,
                                             FLAGS.from_ckpt, FLAGS.to_ckpt)
    else:
        # For back translation from file, we need a temporary file in the other language
        # before back-translating into the source language.
        tmp_file = os.path.join('{}.tmp.txt'.format(
            FLAGS.paraphrase_from_file))

        # Step 1: Translating from source language to the other language.
        decoding.t2t_decoder(FLAGS.from_problem, FLAGS.from_data_dir,
                             FLAGS.paraphrase_from_file, tmp_file, from_ckpt)

        # Step 2: Translating from the other language (tmp_file) to source.
        decoding.t2t_decoder(FLAGS.to_problem, FLAGS.to_data_dir, tmp_file,
                             FLAGS.paraphrase_to_file, to_ckpt)
示例#2
0
        from_data_dir, to_data_dir = FLAGS.envi_data_dir, FLAGS.vien_data_dir
        from_problem, to_problem = FLAGS.envi_problem, FLAGS.vien_problem
        from_ckpt, to_ckpt = FLAGS.envi_ckpt, FLAGS.vien_ckpt
        proxy_lang = 'vi'
    else:
        raise ValueError('Not supported language: {}'.format(lang))

    # Convert directory into checkpoints
    if tf.gfile.IsDirectory(from_ckpt):
        from_ckpt = tf.train.latest_checkpoint(from_ckpt)
    if tf.gfile.IsDirectory(to_ckpt):
        to_ckpt = tf.train.latest_checkpoint(to_ckpt)

    if FLAGS.backtranslate_interactively:
        decoding.backtranslate_interactively(from_problem, to_problem,
                                             from_data_dir, to_data_dir,
                                             from_ckpt, to_ckpt)
    else:
        # For back translation from file, we need a temporary file in the other language
        # before back-translating into the source language.
        tmp_file = os.path.join('{}.tmp.{}.txt'.format(
            FLAGS.paraphrase_from_file, proxy_lang))

        # Step 1: Translating from source language to the other language.
        if not tf.gfile.Exists(tmp_file):
            decoding.t2t_decoder(from_problem, from_data_dir,
                                 FLAGS.paraphrase_from_file, tmp_file,
                                 from_ckpt)

        # Step 2: Translating from the other language (tmp_file) to source.
        decoding.t2t_decoder(to_problem, to_data_dir, tmp_file,