code: def sequence_f1(true, predicted, span_type="token", average=None):
      """
      If average = None, return per-class F1 scores, otherwise
      return the requested model-level score.
      """
      if average == "micro":
          return micro_f1(true, predicted, span_type)
  
      f1s_by_class = per_class_f1(true, predicted, span_type)
      f1s = [
          value.get("f1-score") for key, value in f1s_by_class.items()
      ]
      supports = [
          value.get("support") for key, value in f1s_by_class.items()
      ]
  
      if average == "weighted":
          return np.average(np.array(f1s), weights=np.array(supports))
      if average == "macro":
          return np.average(f1s)
      else:
          return f1s_by_class
  
imports: import os
  import copy
  from functools import partial
  from collections import defaultdict, OrderedDict
  import numpy
  from sklearn.metrics import confusion_matrix
  from tensorflow.python.platform import gfile
  from tensorflow.python.summary import summary_iterator
  import tabulate
  from finetune.encoding.input_encoder import get_spacy
label_desc: Use image node_id 12 for calling a global function with example usage: sequence_f1(true, predicted, span_type, average) and returns: micro_f1, np, np, f1s_by_class