code: def convert_bio_tags_to_conll_format(labels):
      """
      Converts BIO formatted SRL tags to the format required for evaluation with the
      official CONLL 2005 perl script. Spans are represented by bracketed labels,
      with the labels of words inside spans being the same as those outside spans.
      Beginning spans always have a opening bracket and a closing asterisk (e.g. "(ARG-1*" )
      and closing spans always have a closing bracket (e.g. "*)" ). This applies even for
      length 1 spans, (e.g "(ARG-0*)").
  
      A full example of the conversion performed:
  
      [B-ARG-1, I-ARG-1, I-ARG-1, I-ARG-1, I-ARG-1, O]
      [ "(ARG-1*", "*", "*", "*", "*)", "*"]
  
      Parameters
      ----------
      labels : List[str], required.
          A list of BIO tags to convert to the CONLL span based format.
  
      Returns
      -------
      A list of labels in the CONLL span based format.
      """
      sentence_length = len(labels)
      conll_labels = []
      for i, label in enumerate(labels):
          if label == "O":
              conll_labels.append("*")
              continue
          new_label = "*"
          # Are we at the beginning of a new span, at the first word in the sentence,
          # or is the label different from the previous one? If so, we are seeing a new label.
          if (
              label[0] == "B"
              or i == 0
              or label[1:] != labels[i - 1][1:]
          ):
              new_label = "(" + label[2:] + new_label
          # Are we at the end of the sentence, is the next word a new span, or is the next
          # word not in a span? If so, we need to close the label span.
          if (
              i == sentence_length - 1
              or labels[i + 1][0] == "B"
              or label[1:] != labels[i + 1][1:]
          ):
              new_label = new_label + ")"
          conll_labels.append(new_label)
      return conll_labels
  
imports: from __future__ import absolute_import
  import torch
  from torch.nn.modules import Linear, Dropout
  import torch.nn.functional
  from allennlp.common.checks import check_dimensions_match
  from allennlp.data import Vocabulary
  from allennlp.modules import Seq2SeqEncoder, TimeDistributed, TextFieldEmbedder
  from allennlp.modules.token_embedders import Embedding
  from allennlp.models.model import Model
  from allennlp.nn import InitializerApplicator, RegularizerApplicator
  from allennlp.nn.util import get_text_field_mask, sequence_cross_entropy_with_logits
  from allennlp.nn.util import get_lengths_from_binary_sequence_mask, viterbi_decode
  from allennlp.training.metrics import SpanBasedF1Measure
label_desc: Use image node_id 2 for calling a global function with example usage: convert_bio_tags_to_conll_format(labels) and returns: conll_labels