code: def _adjust_span_to_chunk(
      orig_span: Span,
      chunk: Chunk,
      output_space: str,
      input_space: str,
      output_space_text: str,
  ):
      span = copy.deepcopy(orig_span)
      ideal_adj_start = (
          span["start"]
          - chunk[input_space]["start"]
          + chunk[output_space]["start"]
      )
      adj_start = max(ideal_adj_start, chunk[output_space]["start"])
      adj_end = min(
          span["end"]
          - chunk[input_space]["start"]
          + chunk[output_space]["start"],
          chunk[output_space]["end"],
      )
      if "text" in span:
          span["text"] = span["text"][
              adj_start - ideal_adj_start : adj_end - ideal_adj_start
          ]
          if output_space_text is not None:
              assert (
                  span["text"] == output_space_text[adj_start:adj_end]
              ), (
                  span["text"],
                  output_space_text[adj_start:adj_end],
                  orig_span,
                  ">>",
                  span,
              )
      span["start"] = adj_start
      span["end"] = adj_end
      return span
  
imports: import copy
  import functools
  import os
  import tempfile
  import typing
  import sys
  from finetune.base_models import TableRoBERTa
  from finetune.util.metrics import sequences_overlap
  from finetune.scheduler import Scheduler
  from finetune.encoding.input_encoder import BaseEncoder
  from finetune import SequenceLabeler
label_desc: Use image node_id 2 for calling a global function with example usage: _adjust_span_to_chunk(orig_span, chunk, output_space, input_space, output_space_text) and returns: span