class_docstr: Creates a Dataset for T5/BART architecture based Generative QA 
class_docstr_tok: ["Creates","a","Dataset","for","T5\/BART","architecture","based","Generative","QA"]
docstr: Answer is set and encoded as:
      - blank if in inference mode, else
      - blank if question is unanswerable given context, else
      - blank if answer text is not present in context span
          and the check flag is set to true, else
      - formatted answer
docstr_tok: ["Answer","is","set","and","encoded","as",":","-","blank","if","in","inference","mode",",","else","-","blank","if","question","is","unanswerable","given","context",",","else","-","blank","if","answer","text","is","not","present","in","context","span","and","the","check","flag","is","set","to","true",",","else","-","formatted","answer"]
code: def _encode_answer(self, example, context_span_text):
      """
      Answer is set and encoded as:
          - blank if in inference mode, else
          - blank if question is unanswerable given context, else
          - blank if answer text is not present in context span
              and the check flag is set to true, else
          - formatted answer
      """
  
      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
          or example.is_impossible  # question not answerable given context
          or is_answer_in_context_check
      ):
          target = ""
      else:
          target = example.answer_text
  
      encoded_output_dict = self.tokenizer.tokenizer(
          target,
          truncation=True,
          max_length=self.max_answer_length,
          padding="max_length",
          return_tensors="pt",
      )
      labels = torch.squeeze(encoded_output_dict["input_ids"])
      labels[labels == self.tokenizer.tokenizer.pad_token_id] = -100
  
      return labels
  
file_path: NeMo/nemo/collections/nlp/data/question_answering/dataset/qa_s2s_dataset.py
imports: 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_s2s_input_example import S2SQAInputExample
  from nemo.utils import logging
label_desc: Use image node_id 7 for calling the S2SQADataset obj's underlying member method code with example usage: obj._encode_answer(example, context_span_text) and returns: labels