class_docstr: Produces encoded labels for a BIO tagging based grouping formulation.
class_docstr_tok: ["Produces","encoded","labels","for","a","BIO","tagging","based","grouping","formulation","."]
code: def transform(self, out, labels):
      labels, groups = labels
  
      # Add a group_start value to every label for the sequence labeler
      # None -> Not in group, True -> Start of group, False -> In group
      # This could potentially be pulled out of the sequence labeler
      for label in labels:
          label["group_start"] = None
      for group in groups:
          if not is_continuous(group):
              continue
  
          # Gather entities inside group
          # Note that we assume groups are made up of only entities
          group_start = min([t["start"] for t in group["spans"]])
          group_end = max([t["end"] for t in group["spans"]])
          group_labels = []
          for label in labels:
              if (
                  label["start"] >= group_start
                  and label["end"] <= group_end
              ):
                  group_labels.append(label)
          # Add group_start information
          if group_labels:
              group_labels = sorted(
                  group_labels, key=lambda x: x["start"]
              )
              group_labels[0]["group_start"] = True
              for label in group_labels[1:]:
                  label["group_start"] = False
  
      ret = super().transform(out, labels)
      # Un-do the changes to the underlying data
      for label in labels:
          del label["group_start"]
      return ret
  
imports: from abc import ABCMeta
  import logging
  import json
  import numpy
  from finetune.encoding.target_encoders import BaseEncoder, Seq2SeqLabelEncoder, SequenceLabelingEncoder
label_desc: Use image node_id 3 for calling the GroupSequenceLabelingEncoder obj's underlying member method code with example usage: obj.transform(out, labels) and returns: ret