class_docstr: Base class for QA
class_docstr_tok: ["Base","class","for","QA"]
docstr: Generates candidate answers to the <question> provided given <documents> as contexts.
docstr_tok: ["Generates","candidate","answers","to","the","<","question",">","provided","given","<","documents",">","as","contexts","."]
code: def predict_squad(self, documents, question):
      """
      Generates candidate answers to the <question> provided given <documents> as contexts.
      """
      if isinstance(documents, str):
          documents = [documents]
      sequences = [[question, d] for d in documents]
      batch = self.tokenizer.batch_encode_plus(
          sequences,
          return_tensors=self.framework,
          max_length=self.maxlen,
          truncation="only_second",
          padding=True,
      )
      batch = (
          batch.to(self.torch_device)
          if self.framework == "pt"
          else batch
      )
      tokens_batch = list(
          map(self.tokenizer.convert_ids_to_tokens, batch["input_ids"])
      )
  
      # Added from: https://github.com/huggingface/transformers/commit/16ce15ed4bd0865d24a94aa839a44cf0f400ef50
      if U.get_hf_model_name(self.model_name) in [
          "xlm",
          "roberta",
          "distilbert",
      ]:
          start_scores, end_scores = self.model(
              batch["input_ids"],
              attention_mask=batch["attention_mask"],
              return_dict=False,
          )
      else:
          start_scores, end_scores = self.model(
              batch["input_ids"],
              attention_mask=batch["attention_mask"],
              token_type_ids=batch["token_type_ids"],
              return_dict=False,
          )
      start_scores = (
          start_scores.cpu().detach().numpy()
          if self.framework == "pt"
          else start_scores.numpy()
      )
      end_scores = (
          end_scores.cpu().detach().numpy()
          if self.framework == "pt"
          else end_scores.numpy()
      )
      start_scores = start_scores[:, 1:-1]
      end_scores = end_scores[:, 1:-1]
  
      # normalize logits and spans to retrieve the answer
      # start_scores = np.exp(start_scores - np.log(np.sum(np.exp(start_scores), axis=-1, keepdims=True))) # from HF pipeline
      # end_scores = np.exp(end_scores - np.log(np.sum(np.exp(end_scores), axis=-1, keepdims=True)))             # from HF pipeline
      answer_starts = np.argmax(start_scores, axis=1)
      answer_ends = np.argmax(end_scores, axis=1)
  
      answers = []
      for i, tokens in enumerate(tokens_batch):
          answer_start = answer_starts[i]
          answer_end = answer_ends[i]
          answer = self._reconstruct_text(
              tokens, answer_start, answer_end + 2
          )
          if answer.startswith(". ") or answer.startswith(", "):
              answer = answer[2:]
          sep_index = tokens.index("[SEP]")
          full_txt_tokens = tokens[sep_index + 1 :]
          paragraph_bert = self._reconstruct_text(full_txt_tokens)
  
          ans = {}
          ans["answer"] = answer
          if (
              answer.startswith("[CLS]")
              or answer_end < sep_index
              or answer.endswith("[SEP]")
          ):
              ans["confidence"] = LOWCONF
          else:
              # confidence = torch.max(start_scores) + torch.max(end_scores)
              # confidence = np.log(confidence.item())
              # ans['confidence'] = start_scores[i,answer_start]*end_scores[i,answer_end]
              ans["confidence"] = (
                  start_scores[i, answer_start]
                  + end_scores[i, answer_end]
              )
  
          ans["start"] = answer_start
          ans["end"] = answer_end
          ans["context"] = paragraph_bert
          answers.append(ans)
      # if len(answers) == 1: answers = answers[0]
      return answers
  
imports: from transformers import AutoModelForQuestionAnswering, AutoTokenizer, TFAutoModelForQuestionAnswering
  from whoosh import index, qparser
  from whoosh.fields import *
  from whoosh.qparser import QueryParser
  from ...None import utils
  from ...imports import *
  from ...torch_base import TorchBase
  from ..None import preprocessor
  from ..None import textutils
  from itertools import chain, zip_longest
label_desc: Use image node_id 3 for calling the ExtractiveQABase obj's underlying member method code with example usage: obj.predict_squad(documents, question) and returns: answers