code: def sequence_labeling_token_confusion(text, true, predicted):
      nlp = get_spacy()
      none_class = "<None>"
      unique_classes = _get_unique_classes(true, predicted)
      unique_classes.append(none_class)
  
      true_per_token_all = []
      pred_per_token_all = []
  
      for i, (text_i, true_list, pred_list) in enumerate(
          zip(text, true, predicted)
      ):
          tokens = nlp(text_i)
          true_per_token = []
          pred_per_token = []
          for token in tokens:
              token_start_end = {
                  "start": token.idx,
                  "end": token.idx + len(token.text),
              }
              for true_i in true_list:
                  if sequences_overlap(token_start_end, true_i):
                      true_per_token.append(true_i["label"])
                      break
              else:
                  true_per_token.append(none_class)
  
              for pred_i in pred_list:
                  if sequences_overlap(token_start_end, pred_i):
                      pred_per_token.append(pred_i["label"])
                      break
              else:
                  pred_per_token.append(none_class)
          true_per_token_all.extend(true_per_token)
          pred_per_token_all.extend(pred_per_token)
      cm = confusion_matrix(
          y_true=true_per_token_all,
          y_pred=pred_per_token_all,
          labels=unique_classes,
      )
      return tabulate.tabulate(
          [["Predicted\nTrue", *unique_classes]]
          + [[l, *r] for l, r in zip(unique_classes, cm)]
      )
  
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 3 for calling a global function with example usage: sequence_labeling_token_confusion(text, true, predicted) and returns: tabulate