def preprocess_example(self, example, mode, hparams):
    if self.has_inputs:
        inputs = []
        for (name, _) in self.score_encoders():
            inputs.append(tf.expand_dims(example[name], axis=1))
            del example[name]
        example['inputs'] = tf.stack(inputs, axis=2)
    if (self.random_crop_in_train and (mode == tf.estimator.ModeKeys.TRAIN)):
        assert (not self.has_inputs)
        max_offset = tf.maximum((tf.shape(example['targets'])[0] - hparams.max_target_seq_length), 0)
        offset = tf.cond((max_offset > 0), (lambda : tf.random_uniform([], maxval=max_offset, dtype=tf.int32)), (lambda : 0))
        example['targets'] = example['targets'][offset:(offset + hparams.max_target_seq_length)]
        return example
    elif (self.split_in_eval and (mode == tf.estimator.ModeKeys.EVAL)):
        assert (not self.has_inputs)
        length = tf.shape(example['targets'])[0]
        extra_length = tf.mod(length, hparams.max_target_seq_length)
        examples = {'targets': tf.reshape(example['targets'][:(length - extra_length)], [(- 1), hparams.max_target_seq_length, 1, 1])}
        extra_example = {'targets': tf.reshape(example['targets'][(- extra_length):], [1, (- 1), 1, 1])}
        dataset = tf.data.Dataset.from_tensor_slices(examples)
        extra_dataset = tf.data.Dataset.from_tensor_slices(extra_example)
        return dataset.concatenate(extra_dataset)
    else:
        return super(Score2PerfProblem, self).preprocess_example(example, mode, hparams)
def preprocess_example(self, example, mode, hparams):
    if self.has_inputs:
        inputs = []
        for (name, _) in self.score_encoders():
            inputs.append(tf.expand_dims(example[name], axis=1))
            del example[name]
        example['inputs'] = tf.stack(inputs, axis=2)
    if (self.random_crop_in_train and (mode == tf.estimator.ModeKeys.TRAIN)):
        assert (not self.has_inputs)
        max_offset = tf.maximum((tf.shape(example['targets'])[0] - hparams.max_target_seq_length), 0)
        offset = tf.cond((max_offset > 0), (lambda : tf.random_uniform([], maxval=max_offset, dtype=tf.int32)), (lambda : 0))
        example['targets'] = example['targets'][offset:(offset + hparams.max_target_seq_length)]
        return example
    elif (self.split_in_eval and (mode == tf.estimator.ModeKeys.EVAL)):
        assert (not self.has_inputs)
        length = tf.shape(example['targets'])[0]
        extra_length = tf.mod(length, hparams.max_target_seq_length)
        examples = {'targets': tf.reshape(example['targets'][:(length - extra_length)], [(- 1), hparams.max_target_seq_length, 1, 1])}
        extra_example = {'targets': tf.reshape(example['targets'][(- extra_length):], [1, (- 1), 1, 1])}
        dataset = tf.data.Dataset.from_tensor_slices(examples)
        extra_dataset = tf.data.Dataset.from_tensor_slices(extra_example)
        return dataset.concatenate(extra_dataset)
    else:
        return super(Score2PerfProblem, self).preprocess_example(example, mode, hparams)