code: def bucc_eval(candidates2score, gold, threshold=None):
      # Adapted From: https://github.com/google-research/xtreme/blob/
      #               522434d1aece34131d997a97ce7e9242a51a688a/third_party/utils_retrieve.py
      if threshold is not None:
          print(" - using threshold {}".format(threshold))
      else:
          threshold = bucc_optimize(candidates2score, gold)
  
      gold = set(gold)
      bitexts = bucc_extract(candidates2score, threshold)
      ncorrect = len(gold.intersection(bitexts))
      if ncorrect > 0:
          precision = ncorrect / len(bitexts)
          recall = ncorrect / len(gold)
          f1 = 2 * precision * recall / (precision + recall)
      else:
          precision = recall = f1 = 0
      return {
          "best-threshold": threshold,
          "precision": precision,
          "recall": recall,
          "F1": f1,
      }
  
imports: import hashlib
  import numpy
  import torch
  from dataclasses import dataclass
  from typing import List
  from jiant.tasks.core import BaseExample, BaseTokenizedExample, BaseDataRow, BatchMixin, Task, TaskTypes
  from jiant.tasks.lib.templates.shared import construct_single_input_tokens_and_segment_ids, create_input_set_from_tokens_and_segments
  from jiant.utils.python.io import read_file, read_file_lines
label_desc: Use image node_id 2 for calling a global function with example usage: bucc_eval(candidates2score, gold, threshold) and returns: dict