code: def _prepare_train_features(
      self,
      tokenizer,
      samples: Any,
      tokenized_samples: Any,
      pad_on_right: bool,
  ):
      # Since one example might give us several features if it has a long context, we need a map from a feature to
      # its corresponding example. This key gives us just that.
      sample_mapping = tokenized_samples.pop(
          "overflow_to_sample_mapping"
      )
      # The offset mappings will give us a map from token to character position in the original context. This will
      # help us compute the start_positions and end_positions.
      offset_mapping = tokenized_samples.pop("offset_mapping")
  
      # Let's label those examples!
      tokenized_samples["start_positions"] = []
      tokenized_samples["end_positions"] = []
  
      for i, offsets in enumerate(offset_mapping):
          # We will label impossible answers with the index of the CLS token.
          input_ids = tokenized_samples["input_ids"][i]
          cls_index = input_ids.index(tokenizer.cls_token_id)
  
          # Grab the sequence corresponding to that example (to know what is the context and what is the question).
          sequence_ids = tokenized_samples.sequence_ids(i)
  
          # One example can give several spans, this is the index of the example containing this span of text.
          sample_index = sample_mapping[i]
          answers = samples["answer"][sample_index]
          # If no answers are given, set the cls_index as answer.
          if len(answers["answer_start"]) == 0:
              tokenized_samples["start_positions"].append(cls_index)
              tokenized_samples["end_positions"].append(cls_index)
          else:
              # Start/end character index of the answer in the text.
              start_char = answers["answer_start"][0]
              end_char = start_char + len(answers["text"][0])
  
              # Start token index of the current span in the text.
              token_start_index = 0
              while sequence_ids[token_start_index] != (
                  1 if pad_on_right else 0
              ):
                  token_start_index += 1
  
              # End token index of the current span in the text.
              token_end_index = len(input_ids) - 1
              while sequence_ids[token_end_index] != (
                  1 if pad_on_right else 0
              ):
                  token_end_index -= 1
  
              # Detect if the answer is out of the span (in which case this feature is labeled with the CLS index).
              if not (
                  offsets[token_start_index][0] <= start_char
                  and offsets[token_end_index][1] >= end_char
              ):
                  tokenized_samples["start_positions"].append(cls_index)
                  tokenized_samples["end_positions"].append(cls_index)
              else:
                  # Otherwise, move the token_start_index and token_end_index to the two ends of the answer.
                  # Note: we could go after the last offset if the answer is the last word (edge case).
                  while (
                      token_start_index < len(offsets)
                      and offsets[token_start_index][0] <= start_char
                  ):
                      token_start_index += 1
                  tokenized_samples["start_positions"].append(
                      token_start_index - 1
                  )
                  while offsets[token_end_index][1] >= end_char:
                      token_end_index -= 1
                  tokenized_samples["end_positions"].append(
                      token_end_index + 1
                  )
  
      return tokenized_samples, sample_mapping, offset_mapping
  
file_path: lightning-flash/src/flash/text/question_answering/collate.py
imports: from dataclasses import dataclass
  from typing import Any, Optional, Union
  from flash.core.data.io.input import DataKeys
  from flash.core.integrations.transformers.collate import TransformersCollate
  from flash.core.model import Task
label_desc: Use image node_id 1 for calling the TextQuestionAnsweringCollate obj's underlying member method code with example usage: obj._prepare_train_features(tokenizer, samples, tokenized_samples, pad_on_right) and returns: tokenized_samples,  sample_mapping,  offset_mapping