class_docstr: This is a simple class of models that tags individual words in text.
code: def _post_process_batch_after_prediction(self, batch, label_name):
      if self.span_prediction_problem:
          for sentence in batch:
              # internal variables
              previous_tag = "O-"
              current_span: List[Token] = []
  
              for token in sentence:
                  bioes_tag = token.get_label(label_name).value
  
                  # non-set tags are OUT tags
                  if (
                      bioes_tag == ""
                      or bioes_tag == "O"
                      or bioes_tag == "_"
                  ):
                      bioes_tag = "O-"
  
                  # anything that is not OUT is IN
                  in_span = bioes_tag != "O-"
  
                  # does this prediction start a new span?
                  starts_new_span = False
  
                  if bioes_tag[:2] in {"B-", "S-"} or (
                      in_span
                      and previous_tag[2:] != bioes_tag[2:]
                      and (
                          bioes_tag[:2] == "I-"
                          or previous_tag[2:] == "S-"
                      )
                  ):
                      # B- and S- always start new spans
                      # if the predicted class changes, I- starts a new span
                      # if the predicted class changes and S- was previous tag, start a new span
                      starts_new_span = True
  
                  # if an existing span is ended (either by reaching O or starting a new span)
                  if (starts_new_span or not in_span) and len(
                      current_span
                  ) > 0:
                      sentence[
                          current_span[0].idx - 1 : current_span[-1].idx
                      ].set_label(label_name, previous_tag[2:])
                      # reset for-loop variables for new span
                      current_span = []
  
                  if in_span:
                      current_span.append(token)
  
                  # remember previous tag
                  previous_tag = bioes_tag
  
                  token.remove_labels(label_name)
                  token.remove_labels(self.label_type)
  
              # if there is a span at end of sentence, add it
              if len(current_span) > 0:
                  sentence[
                      current_span[0].idx - 1 : current_span[-1].idx
                  ].set_label(label_name, previous_tag[2:])
  
imports: import logging
  from pathlib import Path
  from typing import Any, Dict, List, Union
  import torch
  from deprecated.sphinx import deprecated
  import flair.nn
  from flair.data import Dictionary, Sentence, Span, Token
  from flair.embeddings import TokenEmbeddings
label_desc: Use image node_id 8 for calling the TokenClassifier obj's underlying member method code with example usage: obj._post_process_batch_after_prediction(batch, label_name) without return types