(  # pylint: disable=invalid-name
    dataset_path=None,
    train=True,
    cumulative=False,
    rationale=False,
    correct_answer=False,
    correct_answer_given_reasoning=False,
    partial_reasoning=True,
    order_prediction=False)
return aqua_yield_examples
Prepares Aqua inputs.

  Args:
    dataset_path: a path with the Aqua dataset.
    train: if True, then generate training examples, otherwhise generate
      validation examples (the dataset has also a test set).
    cumulative: if set to True, then generate examples in the format input -
      problem + step1 + step3 + step3 target - step4 If set to False, then
      examples are in the format input - problem, target - all operations.
    rationale: if set to True, then input is the problem and the target is the
      rationale.
    correct_answer: if set to True, then input is the problem plus all possible
      answers and the target is the correct answer.
    correct_answer_given_reasoning: if set to True, then input is the problem
      plus reasoning (aka rationale) plus all possible answers and the target is
      the correct answer.
    partial_reasoning: an additional option related to
      correct_answer_given_reasoning; if set to True, then we take a random
      prefix of the reasoning.
    order_prediction: if set to True, then input is the problem and a list of
      all operations; with probability 0.5 two operations are swapped; the task
      consists in detecting whether the operations were swapped. A similar
      additional task was considered in https://arxiv.org/pdf/1909.11942.pdf and
        in a recent work of Piotr Piękos, henrykm@ and mateuszm@.

  Returns:
    aqua_yield_examples: a generator of Aqua examples; the generator yields
    non-tokenized examples - they can be further processed using for example
    the tokenize function from this module
Prepares Aqua inputs.
Prepares Aqua inputs .
def CreateAquaInputs(  # pylint: disable=invalid-name
    dataset_path=None,
    train=True,
    cumulative=False,
    rationale=False,
    correct_answer=False,
    correct_answer_given_reasoning=False,
    partial_reasoning=True,
    order_prediction=False):
  """Prepares Aqua inputs.

  Args:
    dataset_path: a path with the Aqua dataset.
    train: if True, then generate training examples, otherwhise generate
      validation examples (the dataset has also a test set).
    cumulative: if set to True, then generate examples in the format input -
      problem + step1 + step3 + step3 target - step4 If set to False, then
      examples are in the format input - problem, target - all operations.
    rationale: if set to True, then input is the problem and the target is the
      rationale.
    correct_answer: if set to True, then input is the problem plus all possible
      answers and the target is the correct answer.
    correct_answer_given_reasoning: if set to True, then input is the problem
      plus reasoning (aka rationale) plus all possible answers and the target is
      the correct answer.
    partial_reasoning: an additional option related to
      correct_answer_given_reasoning; if set to True, then we take a random
      prefix of the reasoning.
    order_prediction: if set to True, then input is the problem and a list of
      all operations; with probability 0.5 two operations are swapped; the task
      consists in detecting whether the operations were swapped. A similar
      additional task was considered in https://arxiv.org/pdf/1909.11942.pdf and
        in a recent work of Piotr Piękos, henrykm@ and mateuszm@.

  Returns:
    aqua_yield_examples: a generator of Aqua examples; the generator yields
    non-tokenized examples - they can be further processed using for example
    the tokenize function from this module
  """
  if train:
    dataset_path = os.path.join(dataset_path, 'train.json')
  else:
    dataset_path = os.path.join(dataset_path, 'dev.json')
  # Opening with GFile allows to use remotely stored files, e.g.
  # in a gs bucket.
  dataset_handle = tf.io.gfile.GFile(dataset_path, 'r')
  dataset = []
  for line in dataset_handle:
    dataset.append(json.loads(line))

  def aqua_yield_examples(generator=None):
    del generator
    while True:
      for example in itertools.cycle(dataset):
        input_prefix = example['question']
        steps = example['rationale'].split('\n')
        if cumulative:
          for i in range(len(steps)):
            input_values = 'infer cumulative rationale: ' + input_prefix
            target_values = steps[i]
            input_prefix += ' ' + steps[i]
            yield input_values, target_values, np.array([1] *
                                                        len(target_values))
        elif rationale:
          input_values = 'infer full rationale: ' + input_prefix
          target_values = example['rationale']
          yield input_values, target_values, np.array([1] * len(target_values))
        elif correct_answer:
          input_values = 'infer correct answer: ' + input_prefix
          input_values += ' ' + ' '.join(example['options'])
          target_values = example['correct']
          yield input_values, target_values, np.array([1] * len(target_values))
        elif correct_answer_given_reasoning:
          input_values = 'infer correct answer given reasoning: ' + input_prefix
          if partial_reasoning:
            reasoning_list = example['rationale'].split('\n')
            reasoning_list = reasoning_list[0:np.random
                                            .randint(0, len(reasoning_list))]
            reasoning = '\n'.join(reasoning_list)
          else:
            reasoning = example['rationale']
          input_values += ' ' + example['rationale'] + ' ' + ' '.join(
              example['options'])
          target_values = example['correct']
          yield input_values, target_values, np.array([1] * len(target_values))
        elif order_prediction:
          if np.random.uniform() < 0.5 and len(steps) >= 2:
            idx = range(len(steps))
            i1, i2 = random.sample(idx, 2)
            steps[i1], steps[i2] = steps[i2], steps[i1]
            target_values = 'not_ordered'
          else:
            target_values = 'ordered'
          input_values = 'order prediction: ' + input_prefix + ' ' + '\n'.join(
              steps)
          yield input_values, target_values, np.array([1] * len(target_values))
        else:
          raise ValueError(
              'One of the boolean parameters of the Aqua generator must be set to True.'
          )

  return aqua_yield_examples
def CreateAquaInputs ( # pylint: disable=invalid-name dataset_path = None , train = True , cumulative = False , rationale = False , correct_answer = False , correct_answer_given_reasoning = False , partial_reasoning = True , order_prediction = False ) : if train : dataset_path = os . path . join ( dataset_path , 'train.json' ) else : dataset_path = os . path . join ( dataset_path , 'dev.json' ) # Opening with GFile allows to use remotely stored files, e.g. # in a gs bucket. dataset_handle = tf . io . gfile . GFile ( dataset_path , 'r' ) dataset = [ ] for line in dataset_handle : dataset . append ( json . loads ( line ) ) def aqua_yield_examples ( generator = None ) : del generator while True : for example in itertools . cycle ( dataset ) : input_prefix = example [ 'question' ] steps = example [ 'rationale' ] . split ( '\n' ) if cumulative : for i in range ( len ( steps ) ) : input_values = 'infer cumulative rationale: ' + input_prefix target_values = steps [ i ] input_prefix += ' ' + steps [ i ] yield input_values , target_values , np . array ( [ 1 ] * len ( target_values ) ) elif rationale : input_values = 'infer full rationale: ' + input_prefix target_values = example [ 'rationale' ] yield input_values , target_values , np . array ( [ 1 ] * len ( target_values ) ) elif correct_answer : input_values = 'infer correct answer: ' + input_prefix input_values += ' ' + ' ' . join ( example [ 'options' ] ) target_values = example [ 'correct' ] yield input_values , target_values , np . array ( [ 1 ] * len ( target_values ) ) elif correct_answer_given_reasoning : input_values = 'infer correct answer given reasoning: ' + input_prefix if partial_reasoning : reasoning_list = example [ 'rationale' ] . split ( '\n' ) reasoning_list = reasoning_list [ 0 : np . random . randint ( 0 , len ( reasoning_list ) ) ] reasoning = '\n' . join ( reasoning_list ) else : reasoning = example [ 'rationale' ] input_values += ' ' + example [ 'rationale' ] + ' ' + ' ' . join ( example [ 'options' ] ) target_values = example [ 'correct' ] yield input_values , target_values , np . array ( [ 1 ] * len ( target_values ) ) elif order_prediction : if np . random . uniform ( ) < 0.5 and len ( steps ) >= 2 : idx = range ( len ( steps ) ) i1 , i2 = random . sample ( idx , 2 ) steps [ i1 ] , steps [ i2 ] = steps [ i2 ] , steps [ i1 ] target_values = 'not_ordered' else : target_values = 'ordered' input_values = 'order prediction: ' + input_prefix + ' ' + '\n' . join ( steps ) yield input_values , target_values , np . array ( [ 1 ] * len ( target_values ) ) else : raise ValueError ( 'One of the boolean parameters of the Aqua generator must be set to True.' ) return aqua_yield_examples