code: def _convert_to_token_list(annotations, doc_idx=None):
      nlp = get_spacy()
      tokens = []
      annotations = copy.deepcopy(annotations)
  
      for annotation in annotations:
          start_idx = annotation.get("start")
          tokens.extend(
              [
                  {
                      "start": start_idx + token.idx,
                      "end": start_idx + token.idx + len(token.text),
                      "text": token.text,
                      "label": annotation.get("label"),
                      "doc_idx": doc_idx,
                  }
                  for token in nlp(annotation.get("text"))
              ]
          )
  
      return tokens
  
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 2 for calling a global function with example usage: _convert_to_token_list(annotations, doc_idx) and returns: tokens