code: def get_chunks(seq, tags):
      """Given a sequence of tags, group entities and their position
      Args:
          seq: np.array[4, 4, 0, 0, ...] sequence of labels
          tags: dict["O"] = 4
      Returns:
          list of (chunk_type, chunk_start, chunk_end)
      Example:
          seq = [4, 5, 0, 3]
          tags = {"B-PER": 4, "I-PER": 5, "B-LOC": 3}
          result = [("PER", 0, 2), ("LOC", 3, 4)]
      """
      default1 = tags["O"]
      idx_to_tag = {idx: tag for tag, idx in tags.items()}
      chunks = []
      chunk_type, chunk_start = None, None
      for i, tok in enumerate(seq):
          # End of a chunk 1
          if tok == default1 and chunk_type is not None:
              # Add a chunk.
              chunk = (chunk_type, chunk_start, i)
              chunks.append(chunk)
              chunk_type, chunk_start = None, None
  
          # End of a chunk + start of a chunk!
          elif tok != default1:
              res = get_chunk_type(tok, idx_to_tag)
              if len(res) == 1:
                  continue
              tok_chunk_class, ht = get_chunk_type(tok, idx_to_tag)
              tok_chunk_type = ht
              if chunk_type is None:
                  chunk_type, chunk_start = tok_chunk_type, i
              elif (
                  tok_chunk_type != chunk_type or tok_chunk_class == "B"
              ):
                  chunk = (chunk_type, chunk_start, i)
                  chunks.append(chunk)
                  chunk_type, chunk_start = tok_chunk_type, i
          else:
              pass
      # end condition
      if chunk_type is not None:
          chunk = (chunk_type, chunk_start, len(seq))
          chunks.append(chunk)
  
      return chunks
  
label_desc: Use image node_id 2 for calling a global function with example usage: get_chunks(seq, tags) and returns: chunks