code: def _global_stats_f1(results):
      total_true_entities = 0
      total_predicted_entities = 0
      total_precision = 0
      total_recall = 0
      total_f1 = 0
      total_correct = 0
      for tag in results:
          if tag == "__total__":
              continue
  
          n_pred = results[tag]["n_pred"]
          n_true = results[tag]["n_true"]
          total_correct += results[tag]["tp"]
          total_true_entities += n_true
          total_predicted_entities += n_pred
          total_precision += results[tag]["precision"] * n_pred
          total_recall += results[tag]["recall"] * n_true
          total_f1 += results[tag]["f1"] * n_true
      if total_true_entities > 0:
          accuracy = total_correct / total_true_entities * 100
          total_recall = total_recall / total_true_entities
      else:
          accuracy = 0
          total_recall = 0
      if total_predicted_entities > 0:
          total_precision = total_precision / total_predicted_entities
      else:
          total_precision = 0
  
      if total_precision + total_recall > 0:
          total_f1 = (
              2
              * total_precision
              * total_recall
              / (total_precision + total_recall)
          )
      else:
          total_f1 = 0
  
      total_res = {
          "n_predicted_entities": total_predicted_entities,
          "n_true_entities": total_true_entities,
          "precision": total_precision,
          "recall": total_recall,
          "f1": total_f1,
      }
      return (
          total_res,
          accuracy,
          total_true_entities,
          total_predicted_entities,
          total_correct,
      )
  
file_path: DeepPavlov/deeppavlov/metrics/fmeasure.py
imports: import itertools
  from collections import OrderedDict
  from itertools import chain
  from logging import getLogger
  import numpy
  from sklearn.metrics import f1_score
  from deeppavlov.core.common.metrics_registry import register_metric
label_desc: Use image node_id 4 for calling a global function with example usage: _global_stats_f1(results) and returns: total_res,  accuracy,  total_true_entities,  total_predicted_entities,  total_correct