code: def bio2_to_bioes(tags):
      """
      Convert the BIO2 tag sequence into a BIOES sequence.
  
      Args:
          tags: a list of tags in BIO2 format
  
      Returns:
          new_tags: a list of tags in BIOES format
      """
      new_tags = []
      for i, tag in enumerate(tags):
          if tag in EMPTY_OR_O_TAG:
              new_tags.append(tag)
          else:
              if len(tag) < 2:
                  raise Exception(f"Invalid BIO2 tag found: {tag}")
              else:
                  if tag[:2] in (
                      "I-",
                      "I_",
                  ):  # convert to E- if next tag is not I-
                      if i + 1 < len(tags) and tags[i + 1][:2] in (
                          "I-",
                          "I_",
                      ):
                          new_tags.append(
                              "I-" + tag[2:]
                          )  # compensate for underscores
                      else:
                          new_tags.append("E-" + tag[2:])
                  elif tag[:2] in (
                      "B-",
                      "B_",
                  ):  # convert to S- if next tag is not I-
                      if i + 1 < len(tags) and tags[i + 1][:2] in (
                          "I-",
                          "I_",
                      ):
                          new_tags.append("B-" + tag[2:])
                      else:
                          new_tags.append("S-" + tag[2:])
                  else:
                      raise Exception(f"Invalid IOB tag found: {tag}")
      return new_tags
  
file_path: stanza/stanza/models/ner/utils.py
imports: import logging
  from stanza.models.common.vocab import EMPTY
label_desc: Use image node_id 5 for calling a global function with example usage: bio2_to_bioes(tags) and returns: new_tags