def convert_to_jsonl(task, split):
  """Convert to jsonl from reading the task."""

  delimiter_range_pair = rendering_utils.get_default_delimiter_range_pair(
      task,
      rendering_utils.DelimiterType.text,
  )

  normalize_fn = functools.partial(
      rendering_utils.normalize,
      delimiter_range_pair=delimiter_range_pair,
      task=task,
  )

  print(f"***** {task} *****")
  vocab = t5.data.get_default_vocabulary()

  sequence_length = ast.literal_eval(FLAGS.sequence_length)
  dataset = task.get_dataset(
      sequence_length=sequence_length,
      split=split,
      use_cached=False,
      shuffle=False,
      num_epochs=1,
  )

  print(f"*** {split} ***")
  print("* features *")

  count = 0
  step = 500

  with tf.io.gfile.GFile(FLAGS.output_prefix + "_inputonly.jsonl",
                         "w") as inputonly_f:
    with tf.io.gfile.GFile(FLAGS.output_prefix + "_inputlabels.jsonl",
                           "w") as inputlabels_f:

      for raw_example in dataset:
        count += 1
        if count % step == 0:
          print(f"processed {count} examples..")
        inputs = tf_utils.maybe_decode(
            vocab.decode_tf(raw_example["inputs"]).numpy())
        targets = tf_utils.maybe_decode(
            vocab.decode_tf(raw_example["targets"]).numpy())

        normalized_inputs, normalized_targets = normalize_fn(inputs, targets)

        input_only_example = {
            "inputs": inputs,
            "normalized_inputs": normalized_inputs,
        }

        inputonly_f.write(json.dumps(input_only_example) + "\n")

        example = {
            "inputs": inputs,
            "targets": targets,
            "normalized_inputs": normalized_inputs,
            "normalized_targets": normalized_targets,
        }

        inputlabels_f.write(json.dumps(example) + "\n")
Convert to jsonl from reading the task.
language/fruit/convert_task_to_jsonl.py