code: def match_tokens_with_char_spans(
      token_offsets: np.ndarray, spans: np.ndarray
  ) -> np.ndarray:
      """Match the span offsets with the character-level offsets.
  
      For each span, we perform the following:
  
      1: Cutoff the boundary
  
          span[0] = max(span[0], token_offsets[0, 0])
          span[1] = min(span[1], token_offsets[-1, 1])
  
      2: Find start + end
  
      We try to select the smallest number of tokens that cover the entity, i.e.,
      we will find start + end, in which tokens[start:end + 1] covers the span.
  
      We will use the following algorithm:
  
          For "start", we search for
              token_offsets[start, 0] <= span[0] < token_offsets[start + 1, 0]
  
          For "end", we search for:
              token_offsets[end - 1, 1] < spans[1] <= token_offsets[end, 1]
  
      Parameters
      ----------
      token_offsets
          The offsets of the input tokens. Must be sorted.
          That is, it will satisfy
              1. token_offsets[i][0] <= token_offsets[i][1]
              2. token_offsets[i][0] <= token_offsets[i + 1][0]
              3. token_offsets[i][1] <= token_offsets[i + 1][1]
          Shape (#num_tokens, 2)
      spans
          The character-level offsets (begin/end) of the selected spans.
          Shape (#spans, 2)
  
      Returns
      -------
      token_start_ends
          The token-level starts and ends. The end will also be used.
          Shape (#spans, 2)
      """
      if not isinstance(token_offsets, np.ndarray):
          token_offsets = np.array(token_offsets)
      if not isinstance(spans, np.ndarray):
          spans = np.array(spans)
      offsets_starts = token_offsets[:, 0]
      offsets_ends = token_offsets[:, 1]
      span_char_starts = spans[:, 0]
      span_char_ends = spans[:, 1]
  
      # Truncate the span
      span_char_starts = np.maximum(offsets_starts[0], span_char_starts)
      span_char_ends = np.minimum(offsets_ends[-1], span_char_ends)
  
      # Search for valid start + end
      span_token_starts = (
          np.searchsorted(
              offsets_starts, span_char_starts, side="right"
          )
          - 1
      )
      span_token_ends = np.searchsorted(
          offsets_ends, span_char_ends, side="left"
      )
      return np.concatenate(
          (
              np.expand_dims(span_token_starts, axis=-1),
              np.expand_dims(span_token_ends, axis=-1),
          ),
          axis=-1,
      )
  
label_desc: Use image node_id 2 for calling a global function with example usage: match_tokens_with_char_spans(token_offsets, spans) and returns: np