code: def weighted_avg(class_metrics):
      """
      Takes a dictionary of class metrics and calculates weighted F1
  
      :param class_metrics: A dictionary of class metrics as produced by
      calc_class_metrics()
      :return: Weighted F1
      """
      classes = list(class_metrics.keys())
      f1s = [class_metrics[c]["f1-score"] for c in classes]
      supports = [class_metrics[c]["support"] for c in classes]
      return np.average(f1s, weights=supports)
  
imports: from copy import deepcopy
  from collections import namedtuple
  import numpy
  from scipy.optimize import linear_sum_assignment
  from finetune.util.metrics import _convert_to_token_list, _get_unique_classes, calc_precision, calc_recall, calc_f1
label_desc: Use image node_id 15 for calling a global function with example usage: weighted_avg(class_metrics) and returns: np