code: def f1_score(true, pred_result, rel2id):
      correct = 0
      total = len(true)
      correct_positive = 0
      pred_positive = 0
      gold_positive = 0
      neg = -1
      for name in [
          "NA",
          "na",
          "no_relation",
          "Other",
          "Others",
          "false",
          "unanswerable",
      ]:
          if name in rel2id:
              neg = rel2id[name]
              break
      for i in range(total):
          golden = true[i]
          if golden == pred_result[i]:
              correct += 1
              if golden != neg:
                  correct_positive += 1
          if golden != neg:
              gold_positive += 1
          if pred_result[i] != neg:
              pred_positive += 1
      acc = float(correct) / float(total)
      try:
          micro_p = float(correct_positive) / float(pred_positive)
      except:
          micro_p = 0
      try:
          micro_r = float(correct_positive) / float(gold_positive)
      except:
          micro_r = 0
      try:
          micro_f1 = 2 * micro_p * micro_r / (micro_p + micro_r)
      except:
          micro_f1 = 0
      result = {
          "acc": acc,
          "micro_p": micro_p,
          "micro_r": micro_r,
          "micro_f1": micro_f1,
      }
      return result
  
file_path: DeepKE/example/llm/UnleashLLMRE/gpt3ICL.py
imports: import openai
  import json
  import random
  import time
  from tqdm import tqdm
  from collections import Counter
  import argparse
  import numpy
  import copy
  import os
label_desc: Use image node_id 2 for calling a global function with example usage: f1_score(true, pred_result, rel2id) and returns: result