code: def get_ner_stats(all_gt, all_predictions):
      stats = {}
      cnt = 0
      for gt, pred in zip(all_gt, all_predictions):
          entities_true = defaultdict(set)
          entities_pred = defaultdict(set)
          for type_name, entity_info1, entity_info2 in gt:
              entities_true[type_name].add((entity_info1, entity_info2))
          for type_name, entity_info1, entity_info2 in pred:
              entities_pred[type_name].add((entity_info1, entity_info2))
          target_names = sorted(
              set(entities_true.keys()) | set(entities_pred.keys())
          )
          for tag_name in target_names:
              _ = stats.setdefault(tag_name, {})
              _ = stats[tag_name].setdefault("tp", [])
              _ = stats[tag_name].setdefault("gt_cnt", [])
              _ = stats[tag_name].setdefault("pred_cnt", [])
              entities_true_type = entities_true.get(tag_name, set())
              entities_pred_type = entities_pred.get(tag_name, set())
              stats[tag_name]["tp"].append(
                  len(entities_true_type & entities_pred_type)
              )
              stats[tag_name]["pred_cnt"].append(
                  len(entities_pred_type)
              )
              stats[tag_name]["gt_cnt"].append(len(entities_true_type))
      return stats
  
file_path: espnet/egs2/slue-voxpopuli/asr1/local/eval_utils.py
imports: from collections import defaultdict
  from typing import List
  import editdistance
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: get_ner_stats(all_gt, all_predictions) and returns: stats