class_docstr: Creates a Dataset for GPT architecture based Generative QA 
class_docstr_tok: ["Creates","a","Dataset","for","GPT","architecture","based","Generative","QA"]
docstr: Formats all spans extracted from a single context as:
      `context: <context span text> question: <question text> answer:<answer text>`
  <answer text> is set as:
      - blank if in inference mode, else
      - EOS token if answer text is not present in context span
          and the check flag is set to true, else
      - formatted answer
docstr_tok: ["Formats","all","spans","extracted","from","a","single","context","as",":","`","context",":","<","context","span","text",">","question",":","<","question","text",">","answer",":","<","answer","text",">","`","<","answer","text",">","is","set","as",":","-","blank","if","in","inference","mode",",","else","-","EOS","token","if","answer","text","is","not","present","in","context","span","and","the","check","flag","is","set","to","true",",","else","-","formatted","answer"]
code: def _encode_all_context_spans(
      self,
      unique_id,
      context_spans,
      context_tokens,
      context_prefix,
      formatted_query,
      answer_prefix,
      formatted_answer,
      example,
      example_index,
  ):
      """
      Formats all spans extracted from a single context as:
          `context: <context span text> question: <question text> answer:<answer text>`
      <answer text> is set as:
          - blank if in inference mode, else
          - EOS token if answer text is not present in context span
              and the check flag is set to true, else
          - formatted answer
      """
  
      for context_span_idx, context_span in enumerate(context_spans):
          context_span_tokens = context_tokens[
              context_span.start : context_span.start
              + context_span.length
          ]
          context_span_text = (
              self.tokenizer.tokenizer.convert_tokens_to_string(
                  context_span_tokens
              )
          )
  
          input_without_answer = f"{context_prefix}{context_span_text}{formatted_query}{answer_prefix}"
          _, training_mask_end = self._get_truncated_sentence_and_len(
              input_without_answer, self.max_seq_length
          )
  
          is_answer_in_context_check = (
              self.check_if_answer_in_context  # checks if the flag for this check is set
              and example.answer_text  # checks if answer text is valid, i.e. question is not unanswerable
              and example.answer_text
              not in context_span_text  # checks if answer text is a substring of context
          )
  
          if self.mode == INFERENCE_MODE:
              input_to_encode = input_without_answer
          elif is_answer_in_context_check:
              input_to_encode = f"{input_without_answer}{self.tokenizer.tokenizer.eos_token}"
          else:
              input_to_encode = (
                  f"{input_without_answer}{formatted_answer}"
              )
  
          encoded_input_dict = self.tokenizer.tokenizer(
              input_to_encode,
              truncation=True,
              max_length=self.max_seq_length,
              padding="max_length",
              return_tensors="pt",
          )
          input_ids = torch.squeeze(encoded_input_dict["input_ids"])
          input_attn_mask = torch.squeeze(
              encoded_input_dict["attention_mask"]
          )
  
          labels = GPTQADataset.update_labels_for_no_pad_loss(
              input_ids, training_mask_end, input_attn_mask
          )
  
          # create dictionary features
          feature = {
              "unique_id": unique_id,
              "input_ids": input_ids,
              "input_attn_mask": input_attn_mask,
              "training_mask_end": training_mask_end,
              "labels": labels,
              "example_index": example_index,
              "context_span_index": context_span_idx,
              "is_impossible": example.is_impossible,
          }
  
          self.features.append(feature)
          unique_id += 1
  
      return unique_id
  
imports: import copy
  import os
  import numpy
  import torch
  from tqdm import trange
  from nemo.collections.nlp.data.question_answering.data_processor.qa_processing import INFERENCE_MODE, TRAINING_MODE
  from nemo.collections.nlp.data.question_answering.dataset.qa_dataset import QADataset
  from nemo.collections.nlp.data.question_answering.input_example.qa_gpt_input_example import GPTQAInputExample
  from nemo.utils import logging
label_desc: Use image node_id 7 for calling the GPTQADataset obj's underlying member method code with example usage: obj._encode_all_context_spans(unique_id, context_spans, context_tokens, context_prefix, formatted_query, answer_prefix, formatted_answer, example, example_index) and returns: unique_id