class_docstr: Sentence-level relation extraction dataset
docstr: Args:
      pred_score: [sent_num, label_num]
      use_name: if True, `pred_result` contains predicted relation names instead of ids
  Return:
      {'acc': xx}
docstr_tok: ["Args",":","pred_score",":","[","sent_num",",","label_num","]","use_name",":","if","True",",","`","pred_result","`","contains","predicted","relation","names","instead","of","ids","Return",":","{","'acc","'",":","xx","}"]
code: def eval(self, pred_score, threshold=0.5, use_name=False):
      """
      Args:
          pred_score: [sent_num, label_num]
          use_name: if True, `pred_result` contains predicted relation names instead of ids
      Return:
          {'acc': xx}
      """
      assert len(self.data) == len(pred_score)
      pred_score = np.array(pred_score)
  
      # Calculate AUC
      sorted_result = []
      total = 0
      for sent_id in range(len(self.data)):
          for rel in self.rel2id:
              if rel not in [
                  "NA",
                  "na",
                  "N/A",
                  "None",
                  "none",
                  "n/a",
                  "no_relation",
              ]:
                  sorted_result.append(
                      {
                          "sent_id": sent_id,
                          "relation": rel,
                          "score": pred_score[sent_id][
                              self.rel2id[rel]
                          ],
                      }
                  )
                  if "anno_relation_list" in self.data[sent_id]:
                      if (
                          rel
                          in self.data[sent_id]["anno_relation_list"]
                      ):
                          total += 1
                  else:
                      if rel == self.data[sent_id]["relation"]:
                          total += 1
  
      sorted_result.sort(key=lambda x: x["score"], reverse=True)
      prec = []
      rec = []
      correct = 0
      for i, item in enumerate(sorted_result):
          if "anno_relation_list" in self.data[item["sent_id"]]:
              if (
                  item["relation"]
                  in self.data[item["sent_id"]]["anno_relation_list"]
              ):
                  correct += 1
          else:
              if (
                  item["relation"]
                  == self.data[item["sent_id"]]["relation"]
              ):
                  correct += 1
          prec.append(float(correct) / float(i + 1))
          rec.append(float(correct) / float(total))
      auc = sklearn.metrics.auc(x=rec, y=prec)
      np_prec = np.array(prec)
      np_rec = np.array(rec)
      max_micro_f1 = (
          2 * np_prec * np_rec / (np_prec + np_rec + 1e-20)
      ).max()
      max_micro_f1_threshold = sorted_result[
          (2 * np_prec * np_rec / (np_prec + np_rec + 1e-20)).argmax()
      ]["score"]
      mean_prec = np_prec.mean()
  
      # Calculate F1
      pred_result_vec = np.zeros(
          (len(self.data), len(self.rel2id)), dtype=np.int
      )
      pred_result_vec[pred_score >= threshold] = 1
      label_vec = []
      for item in self.data:
          if "anno_relation_list" in item:
              label_vec.append(
                  np.array(item["anno_relation_vec"], dtype=np.int)
              )
          else:
              one_hot = np.zeros((len(self.rel2id)), dtype=np.int)
              one_hot[self.rel2id[item["relation"]]] = 1
              label_vec.append(one_hot)
      label_vec = np.stack(label_vec, 0)
      assert label_vec.shape == pred_result_vec.shape
  
      micro_p = sklearn.metrics.precision_score(
          label_vec,
          pred_result_vec,
          labels=list(range(1, len(self.rel2id))),
          average="micro",
      )
      micro_r = sklearn.metrics.recall_score(
          label_vec,
          pred_result_vec,
          labels=list(range(1, len(self.rel2id))),
          average="micro",
      )
      micro_f1 = sklearn.metrics.f1_score(
          label_vec,
          pred_result_vec,
          labels=list(range(1, len(self.rel2id))),
          average="micro",
      )
  
      macro_p = sklearn.metrics.precision_score(
          label_vec,
          pred_result_vec,
          labels=list(range(1, len(self.rel2id))),
          average="macro",
      )
      macro_r = sklearn.metrics.recall_score(
          label_vec,
          pred_result_vec,
          labels=list(range(1, len(self.rel2id))),
          average="macro",
      )
      macro_f1 = sklearn.metrics.f1_score(
          label_vec,
          pred_result_vec,
          labels=list(range(1, len(self.rel2id))),
          average="macro",
      )
  
      acc = (label_vec == pred_result_vec).mean()
  
      result = {
          "acc": acc,
          "micro_p": micro_p,
          "micro_r": micro_r,
          "micro_f1": micro_f1,
          "macro_p": macro_p,
          "macro_r": macro_r,
          "macro_f1": macro_f1,
          "np_prec": np_prec,
          "np_rec": np_rec,
          "max_micro_f1": max_micro_f1,
          "max_micro_f1_threshold": max_micro_f1_threshold,
          "auc": auc,
          "p@100": np_prec[99],
          "p@200": np_prec[199],
          "p@300": np_prec[299],
      }
      logging.info("Evaluation result: {}.".format(result))
      return result
  
imports: import torch
  import torch.utils.data
  import os, random, json, logging
  import numpy
  import sklearn.metrics
label_desc: Use image node_id 5 for calling the MultiLabelSentenceREDataset obj's underlying member method code with example usage: obj.eval(pred_score, threshold, use_name) and returns: result