Example #1
0
 def test_train(self):
   model_dir = os.path.abspath("tests/models/train")
   if not os.path.exists(model_dir):
     os.makedirs(model_dir)
   train_path = os.path.abspath("tests/data/toydict.train")
   dev_path = os.path.abspath("tests/data/toydict.test")
   params = Params(model_dir, train_path)
   g2p_trainer_utils.save_params(model_dir, params.hparams)
   g2p_model = G2PModel(params, train_path=train_path, dev_path=dev_path,
                        test_path=dev_path)
   g2p_model.train()
   shutil.rmtree(model_dir)
Example #2
0
  def test_train(self):
    model_dir = os.path.abspath("tests/models/train")
    if not os.path.exists(model_dir):
      os.makedirs(model_dir)
    train_path = os.path.abspath("tests/data/toydict.train")
    dev_path = os.path.abspath("tests/data/toydict.test")
    params = Params(model_dir, train_path)
    g2p_trainer_utils.save_params(model_dir, params.hparams)
    g2p_model = G2PModel(params, train_path=train_path, dev_path=dev_path,
                         test_path=dev_path)
    g2p_model.train()

    shutil.rmtree(model_dir, ignore_errors=True)
Example #3
0
def main(_=[]):
    """Main function.
  """
    tf.logging.set_verbosity(tf.logging.INFO)
    file_path = FLAGS.train or FLAGS.decode or FLAGS.evaluate
    test_path = FLAGS.decode or FLAGS.evaluate or FLAGS.test

    if not FLAGS.model_dir:
        raise RuntimeError("Model directory not specified.")

    if FLAGS.reinit and os.path.exists(FLAGS.model_dir):
        shutil.rmtree(FLAGS.model_dir)

    if not os.path.exists(FLAGS.model_dir):
        os.makedirs(FLAGS.model_dir)

    params = Params(FLAGS.model_dir, file_path, flags=FLAGS)

    if FLAGS.train:
        g2p_trainer_utils.save_params(FLAGS.model_dir, params.hparams)
        g2p_model = G2PModel(params,
                             train_path=FLAGS.train,
                             dev_path=FLAGS.valid,
                             test_path=test_path,
                             cleanup=FLAGS.cleanup,
                             p2g_mode=FLAGS.p2g)
        g2p_model.train()

    else:
        params.hparams = g2p_trainer_utils.load_params(FLAGS.model_dir)
        g2p_model = G2PModel(params, test_path=test_path, p2g_mode=FLAGS.p2g)

        if FLAGS.freeze:
            g2p_model.freeze()

        elif FLAGS.interactive:
            g2p_model.interactive()

        elif FLAGS.decode:
            g2p_model.decode(output_file_path=FLAGS.output)

        elif FLAGS.evaluate:
            g2p_model.evaluate()
Example #4
0
def main(_=[]):
  """Main function.
  """
  tf.logging.set_verbosity(tf.logging.INFO)
  file_path = FLAGS.train or FLAGS.decode or FLAGS.evaluate
  test_path = FLAGS.decode or FLAGS.evaluate or FLAGS.test

  if not FLAGS.model_dir:
    raise RuntimeError("Model directory not specified.")

  if FLAGS.reinit and os.path.exists(FLAGS.model_dir):
    shutil.rmtree(FLAGS.model_dir)

  if not os.path.exists(FLAGS.model_dir):
    os.makedirs(FLAGS.model_dir)

  params = Params(FLAGS.model_dir, file_path, flags=FLAGS)

  if FLAGS.train:
    g2p_trainer_utils.save_params(FLAGS.model_dir, params.hparams)
    g2p_model = G2PModel(params, train_path=FLAGS.train, dev_path=FLAGS.valid,
                         test_path=test_path, cleanup=FLAGS.cleanup,
                         p2g_mode=FLAGS.p2g)
    g2p_model.train()

  else:
    params.hparams = g2p_trainer_utils.load_params(FLAGS.model_dir)
    g2p_model = G2PModel(params, test_path=test_path, p2g_mode=FLAGS.p2g)

    if FLAGS.freeze:
      g2p_model.freeze()

    elif FLAGS.interactive:
      g2p_model.interactive()

    elif FLAGS.decode:
      g2p_model.decode(output_file_path=FLAGS.output)

    elif FLAGS.evaluate:
      g2p_model.evaluate()