def from_lossy(
      self,
      predictions,
      is_rir,
      is_direct,
      train_examples = None,
      test_examples = None
  ):
    """Prepares data to recover original programs from lossy IRs by seq2seq_2.

    Args:
      predictions: test set predictions, to be concatenated to the utterance as
        input to seq2seq_2. These are expected to be: (1) lossy IRs if
          is_direct=True and is_rir=False, (2) lossy+reversible IRs if
          is_direct=True and is_rir=True, (3) reversible IRs if is_direct=False
          and is_rir=True or (4) programs in the original formalism if
          is_direct=False and is_rir=False.
      is_rir: whether the representation from which to predict programs has gone
        through the reversible transformation.
      is_direct: If True, test predictions are expected to be lossy.
      train_examples: to be supplied incase is_rir=True, and holds examples in
        their reversible IR.
      test_examples: to be supplied incase is_rir=True, and holds examples in
        their reversible IR.

    Returns:
      A tuple of train and test examples used to train seq2seq_2 for predicting
      programs given the utterance and the lossy IR.
    """

    def concat_lirs(examples, lirs):
      """Concatenates the lossy IR to the utterance."""
      examples_concatenated = []
      for example, lir in zip(examples, lirs):
        source = "{} coarse: {}".format(example.utterance, lir)
        target = example.program
        examples_concatenated.append(Example(source, target))
      return examples_concatenated

    if not train_examples or not test_examples:
      train_examples, test_examples = self.train_examples, self.test_examples
    # Use gold lossy IRs for the training set.
    train_examples_lossy, _ = self.to_lossy(
        is_rir=is_rir,
        train_examples=train_examples,
        test_examples=test_examples)
    if is_direct:
      prediction_lirs = predictions
    # For the indirect approach, predictions are not in their lossy IR, so
    # the lossy transformation is applied.
    else:
      prediction_lirs = [
          self.f_lossy(prediction, is_rir) for prediction in predictions
      ]

    train_examples_concatenated = concat_lirs(
        train_examples, [example.program for example in train_examples_lossy])
    test_examples_concatenated = concat_lirs(test_examples, prediction_lirs)
    return train_examples_concatenated, test_examples_concatenated
Prepares data to recover original programs from lossy IRs by seq2seq_2.

    Args:
      predictions: test set predictions, to be concatenated to the utterance as
        input to seq2seq_2. These are expected to be: (1) lossy IRs if
          is_direct=True and is_rir=False, (2) lossy+reversible IRs if
          is_direct=True and is_rir=True, (3) reversible IRs if is_direct=False
          and is_rir=True or (4) programs in the original formalism if
          is_direct=False and is_rir=False.
      is_rir: whether the representation from which to predict programs has gone
        through the reversible transformation.
      is_direct: If True, test predictions are expected to be lossy.
      train_examples: to be supplied incase is_rir=True, and holds examples in
        their reversible IR.
      test_examples: to be supplied incase is_rir=True, and holds examples in
        their reversible IR.

    Returns:
      A tuple of train and test examples used to train seq2seq_2 for predicting
      programs given the utterance and the lossy IR.
    
language/compir/dataset_parsers/dataset_parser.py