code: def generate_and_write_preds_for_bucc2018(
      runner,
      output_dir: str,
      bucc_val_metrics_path: str,
      skip_if_done: bool = False,
  ):
      """Generate predictions (test) for Bucc2018 and write them in XTREME submission format"""
      preds_pickle_path = os.path.join(
          output_dir, "bucc2018_test_preds.p"
      )
      if skip_if_done and os.path.exists(preds_pickle_path):
          print(f"Skipping cause {preds_pickle_path} exists")
          return
      else:
          print(f"{preds_pickle_path} does not exist")
      if bucc_val_metrics_path is None:
          # Recompute thresholds:
          val_results_dict = runner.run_val(
              task_name_list=runner.jiant_task_container.task_run_config.val_task_list,
              return_preds=True,
          )
          jiant_evaluate.write_preds(
              eval_results_dict=val_results_dict,
              path=os.path.join(output_dir, "bucc2018_val_preds.p"),
          )
          thresholds_dict = {
              task_name: task_results["metrics"].minor["best-threshold"]
              for task_name, task_results in val_results_dict.items()
          }
      else:
          val_metrics = py_io.read_json(bucc_val_metrics_path)
          thresholds_dict = {
              task_name: val_metrics[task_name]["metrics"]["minor"][
                  "best-threshold"
              ]
              for task_name in runner.jiant_task_container.task_run_config.val_task_list
          }
  
      preds_output_dir = os.path.join(output_dir, "preds", "bucc2018")
      os.makedirs(preds_output_dir, exist_ok=True)
      test_results_dict = runner.run_test(
          task_name_list=runner.jiant_task_container.task_run_config.test_task_list,
      )
      jiant_evaluate.write_preds(
          eval_results_dict=test_results_dict,
          path=preds_pickle_path,
      )
      for task_name, task_results in test_results_dict.items():
          bitext = bucc2018_lib.bucc_extract(
              cand2score=task_results["preds"],
              th=thresholds_dict[task_name],
          )
          lang = runner.jiant_task_container.task_dict[
              task_name
          ].language
          with open(
              os.path.join(preds_output_dir, f"test-{lang}.tsv"), "w"
          ) as f:
              for src, trg in bitext:
                  f.write(f"{src}\t{trg}\n")
      print(
          f"Wrote Bucc2018 preds for {len(test_results_dict)} languages"
      )
  
imports: import os
  import numpy
  import torch
  import zconf
  import jiant.utils.python.io
  from jiant.utils.display import maybe_tqdm
  import jiant.shared.initialization
  import jiant.shared.model_resolution
  import jiant.proj.main.components.container_setup
  import jiant.proj.main.runner
  from jiant.proj.main.runscript import setup_runner
  import jiant.tasks.lib.templates.squad_style.core
  import jiant.tasks.lib.bucc2018
  import jiant.tasks
  import jiant.proj.main.components.evaluate
  from jiant.proj.main.modeling.primary import wrap_jiant_forward
label_desc: Use image node_id 7 for calling a global function with example usage: generate_and_write_preds_for_bucc2018(runner, output_dir, bucc_val_metrics_path, skip_if_done) without return types