code: def convert_bio_to_spans(bio_sequence: List[str]) -> List[Span]:
      """
      Process the output and convert to spans for evaluation.
      """
      spans = []  # (label, startindex, endindex)
      cur_start = None
      cur_label = None
      N = len(bio_sequence)
      for t in range(N + 1):
          if (cur_start is not None) and (
              t == N or re.search("^[BO]", bio_sequence[t])
          ):
              assert cur_label is not None
              spans.append(Span(cur_label, cur_start, t))
              cur_start = None
              cur_label = None
          if t == N:
              continue
          assert bio_sequence[t]
          if bio_sequence[t][0] not in ("B", "I", "O"):
              bio_sequence[t] = "O"
          if bio_sequence[t].startswith("B"):
              cur_start = t
              cur_label = re.sub("^B-?", "", bio_sequence[t]).strip()
          if bio_sequence[t].startswith("I"):
              if cur_start is None:
                  newseq = bio_sequence[:]
                  newseq[t] = "B" + newseq[t][1:]
                  return convert_bio_to_spans(newseq)
              continuation_label = re.sub("^I-?", "", bio_sequence[t])
              if continuation_label != cur_label:
                  newseq = bio_sequence[:]
                  newseq[t] = "B" + newseq[t][1:]
                  return convert_bio_to_spans(newseq)
  
      # should have exited for last span ending at end by now
      assert cur_start is None
      return spans
  
imports: import itertools
  import re
  from collections import Counter
  from typing import Dict, List, NamedTuple
  from pytext.common.constants import DatasetFieldName, SpecialTokens, Stage
  from pytext.data import CommonMetadata
  from pytext.metrics import AllConfusions, compute_classification_metrics, compute_multi_label_multi_class_soft_metrics, Confusions, LabelPrediction, PRF1Metrics
  from pytext.metrics.intent_slot_metrics import compute_prf1_metrics, Node, NodesPredictionPair, Span
  from pytext.utils.data import merge_token_labels_to_slot, parse_slot_string
  from .channel import Channel, ConsoleChannel, FileChannel
  from .metric_reporter import MetricReporter
label_desc: Use image node_id 2 for calling a global function with example usage: convert_bio_to_spans(bio_sequence) and returns: spans, convert_bio_to_spans, convert_bio_to_spans