Esempio n. 1
0
  def __init__(self, model_dir, train_path=None, dev_path=None, test_path=None,
               cleanup=False):
    """Create a Problem.

    Args:
      was_reversed: bool, whether to reverse inputs and targets.
      was_copy: bool, whether to copy inputs to targets. Can be composed with
        was_reversed so that if both are true, the targets become the inputs,
        which are then copied to targets so that the task is targets->targets.
    """
    super(GraphemeToPhonemeProblem, self).__init__()
    self._encoders = None
    self._hparams = None
    self._feature_info = None
    self._model_dir = model_dir
    self.train_path, self.dev_path, self.test_path = train_path, dev_path,\
        test_path
    vocab_filename = os.path.join(self._model_dir, "vocab.g2p")
    if train_path:
      self.train_path, self.dev_path, self.test_path = create_data_files(
          init_train_path=train_path, init_dev_path=dev_path,
          init_test_path=test_path,cleanup=cleanup)
      self.source_vocab, self.target_vocab = g2p_encoder.load_create_vocabs(
          vocab_filename, train_path=self.train_path, dev_path=self.dev_path,
          test_path=self.test_path)
    elif not os.path.exists(os.path.join(self._model_dir, "checkpoint")):
      raise StandardError("Model not found in {}".format(self._model_dir))
    else:
      self.source_vocab, self.target_vocab = g2p_encoder.load_create_vocabs(
          vocab_filename)
Esempio n. 2
0
    def __init__(self, model_dir, file_path, is_training):
        """Create a Problem.

    Args:
      was_reversed: bool, whether to reverse inputs and targets.
      was_copy: bool, whether to copy inputs to targets. Can be composed with
        was_reversed so that if both are true, the targets become the inputs,
        which are then copied to targets so that the task is targets->targets.
    """
        super(GraphemeToPhonemeProblem, self).__init__()
        self._encoders = None
        self._hparams = None
        self._feature_info = None
        self._model_dir = model_dir
        self.file_path = file_path
        vocab_filename = os.path.join(self._model_dir, "vocab.g2p")
        if is_training:
            self.source_vocab, self.target_vocab = g2p_encoder.load_create_vocabs(
                vocab_filename, data_path=file_path)
        else:
            self.source_vocab, self.target_vocab = g2p_encoder.load_create_vocabs(
                vocab_filename)