code: def merge_spans(sent, pred, for_visualizer=False):
      """Merge subsequent predictions."""
      if isinstance(pred, str):
          # For string values, we assume that it is json-encoded string of the sentences.
          try:
              pred = json.loads(pred)
          except Exception as exp:
              raise RuntimeError(
                  f"The received entity annotations is {pred}, "
                  f"which can not be encoded with the json format. "
                  f"Check your input again, or running `json.loads(pred)` to verify your data."
              )
      spans = {}
      last_start = -1
      last_end = -1
      last_label = ""
      for entity in pred:
          entity_group = entity["entity_group"]
          start = entity["start"]
          end = entity["end"]
          if (
              last_start >= 0
              and not for_visualizer
              and (not re.match("B-", entity_group, re.IGNORECASE))
              and (
                  (
                      re.match("I-", entity_group, re.IGNORECASE)
                      and last_label[2:] == entity_group[2:]
                  )
                  or last_label == entity_group
              )
              and (
                  sent[last_end:start].isspace() or (last_end == start)
              )
          ):
              last_end = end
          else:
              last_start = start
              last_end = end
              last_label = entity_group
  
          if re.match("B-", last_label, re.IGNORECASE) or re.match(
              "I-", last_label, re.IGNORECASE
          ):
              spans.update({last_start: (last_end, last_label[2:])})
          else:
              spans.update({last_start: (last_end, last_label)})
      return spans
  
file_path: autogluon/multimodal/src/autogluon/multimodal/utils/misc.py
imports: import json
  import logging
  import os
  import re
  import numpy
  import pandas
  import torch
  from scipy.special import expit, softmax
label_desc: Use image node_id 7 for calling a global function with example usage: merge_spans(sent, pred, for_visualizer) and returns: spans