code: def get_passage_offsets(
      doc_offsets, doc_stride, passage_len_t, doc_text
  ):
      """
      Get spans (start and end offsets) for passages by applying a sliding window function.
      The sliding window moves in steps of doc_stride.
      Returns a list of dictionaries which each describe the start, end and id of a passage
      that is formed when chunking a document using a sliding window approach.
      """
  
      passage_spans = []
      passage_id = 0
      doc_len_t = len(doc_offsets)
      while True:
          passage_start_t = passage_id * doc_stride
          passage_end_t = passage_start_t + passage_len_t
          passage_start_c = doc_offsets[passage_start_t]
  
          # If passage_end_t points to the last token in the passage, define passage_end_c as the length of the document
          if passage_end_t >= doc_len_t - 1:
              passage_end_c = len(doc_text)
  
          # Get document text up to the first token that is outside the passage. Strip of whitespace.
          # Use the length of this text as the passage_end_c
          else:
              end_ch_idx = doc_offsets[passage_end_t + 1]
              raw_passage_text = doc_text[:end_ch_idx]
              passage_end_c = len(raw_passage_text.strip())
  
          passage_span = {
              "passage_start_t": passage_start_t,
              "passage_end_t": passage_end_t,
              "passage_start_c": passage_start_c,
              "passage_end_c": passage_end_c,
              "passage_id": passage_id,
          }
          passage_spans.append(passage_span)
          passage_id += 1
          # If the end idx is greater than or equal to the length of the passage
          if passage_end_t >= doc_len_t:
              break
      return passage_spans
  
file_path: FARM/farm/data_handler/samples.py
imports: from transformers.models.bert.tokenization_bert import whitespace_tokenize
  from farm.visual.ascii.images import SAMPLE
  import numpy
  import logging
label_desc: Use image node_id 4 for calling a global function with example usage: get_passage_offsets(doc_offsets, doc_stride, passage_len_t, doc_text) and returns: passage_spans