code: def main(_):
      t5.data.add_global_cache_dirs(FLAGS.additional_task_cache_dirs)
      out_file = os.path.join(
          FLAGS.out_dir,
          "{}.{{extension}}".format(FILE_NAME_MAP[FLAGS.tfds_name]),
      )
  
      ds = t5.data.TaskRegistry.get_dataset(
          FLAGS.task,
          _FAKE_LEN,
          FLAGS.split,
          use_cached=FLAGS.cached,
          shuffle=False,
      )
      examples = [{k: v.numpy() for k, v in ex.items()} for ex in ds]
  
      with tf.io.gfile.GFile(FLAGS.predictions_file) as f:
          prediction_lines = f.readlines()
      if FLAGS.tfds_name == "record":
          # record just uses raw strings
          predictions = [l.strip() for l in prediction_lines]
      else:
          # everything else uses Python code strings
          predictions = [
              ast.literal_eval(l.strip()) for l in prediction_lines
          ]
  
      if FLAGS.tfds_name in USES_TEXT:
          if FLAGS.super:
              builder_configs = (
                  tfds.text.super_glue.SuperGlue.builder_configs
              )
          else:
              builder_configs = tfds.text.glue.Glue.builder_configs
          label_classes = builder_configs[FLAGS.tfds_name].label_classes
          predictions = [label_classes[p] for p in predictions]
      elif FLAGS.tfds_name in ["boolq", "wic"]:
          predictions = [("false", "true")[p] for p in predictions]
      elif FLAGS.tfds_name == "wsc":
          predictions = [("False", "True")[p] for p in predictions]
      elif FLAGS.tfds_name == "multirc":
          # multirc is so different from the rest that we special-case everything
          rows = collections.defaultdict(
              lambda: collections.defaultdict(dict)
          )
          predictions = [int(p["value"]) for p in predictions]
          for p, e in zip(predictions, examples):
              e = {
                  k: int(e["idx/" + k])
                  for k in ["paragraph", "question", "answer"]
              }
              rows[e["paragraph"]][e["question"]][e["answer"]] = p
          with tf.io.gfile.GFile(
              out_file.format(extension="jsonl"), "w"
          ) as f:
              for pidx, passage in rows.items():
                  qs = [
                      {
                          "idx": i,
                          "answers": [
                              {"idx": j, "label": q[j]} for j in q
                          ],
                      }
                      for i, q in passage.items()
                  ]
                  f.write(
                      json.dumps(
                          {"idx": pidx, "passage": {"questions": qs}}
                      )
                      + os.linesep
                  )
          return
  
      if len(predictions) != len(examples):
          raise ValueError(
              "Number of predictions in {} ({}) != of examples in {} split of {} "
              "({}).".format(
                  FLAGS.predictions_file,
                  len(predictions),
                  FLAGS.split,
                  FLAGS.task,
                  len(examples),
              )
          )
  
      if "record" in FLAGS.task:
          indices = [ex["idx/query"] for ex in examples]
      else:
          indices = [ex.get("idx", None) for ex in examples]
  
      if FLAGS.super:
          lines = [
              json.dumps({"idx": int(i), "label": p}) + os.linesep
              for i, p in zip(indices, predictions)
          ]
          with tf.io.gfile.GFile(
              out_file.format(extension="jsonl"), "w"
          ) as f:
              for line in lines:
                  f.write(line)
      else:
          with tf.io.gfile.GFile(
              out_file.format(extension="tsv"), "w"
          ) as out_file:
              tsv_writer = csv.writer(out_file, delimiter="\t")
              tsv_writer.writerow(["index", "prediction"])
              tsv_writer.writerows(
                  [i, p] for i, p in zip(indices, predictions)
              )
  
file_path: text-to-text-transfer-transformer/t5/scripts/prepare_glue_submission.py
imports: import ast
  import collections
  import csv
  import json
  import os
  from absl import app
  from absl import flags
  import t5.data
  import t5.data.tasks
  import tensorflow
  import tensorflow_datasets
label_desc: Use image node_id 1 for calling a global function with example usage: main(_) without return types