class_docstr: Base class for QA
class_docstr_tok: ["Base","class","for","QA"]
docstr: ```
  submit question to obtain candidate answers
  
  Args:
    question(str): question in the form of a string
    query(str): Optional. If not None, words in query will be used to retrieve contexts instead of words in question
    batch_size(int):  number of question-context pairs fed to model at each iteration
                      Default:8
                      Increase for faster answer-retrieval.
                      Decrease to reduce memory (if out-of-memory errors occur).
    n_docs_considered(int): number of top search results that will
                            be searched for answer
                            Default:10
    n_answers(int): maximum number of candidate answers to return
                    Default:50
    raw_confidence(bool): If True, show raw confidence score of each answer. It could be used to
                          mitigate very high confidence on first answer when softmax is used.
                          If False, perform softmax on raw confidence scores.
                          Default: False
    rerank_threshold(int): rerank top answers with confidence >= rerank_threshold
                           based on semantic similarity between question and answer.
                           This can help bump the correct answer closer to the top.
                           Default:0.015. This should be changed to somethink like 6.0
                           if raw_confidence=True.
                           If None, no re-ranking is performed.
    include_np(bool):  If True, noun phrases will be extracted from question and included
                       in query that retrieves documents likely to contain candidate answers.
                       This may be useful if you ask a question about artificial intelligence
                       and the answers returned pertain just to intelligence, for example.
                       Note: include_np=True requires textblob be installed.
                       Default:False
  Returns:
    list
  ```
docstr_tok: ["``","`","submit","question","to","obtain","candidate","answers","Args",":","question","(","str",")",":","question","in","the","form","of","a","string","query","(","str",")",":","Optional",".","If","not","None",",","words","in","query","will","be","used","to","retrieve","contexts","instead","of","words","in","question","batch_size","(","int",")",":","number","of","question-context","pairs","fed","to","model","at","each","iteration","Default:8","Increase","for","faster","answer-retrieval",".","Decrease","to","reduce","memory","(","if","out-of-memory","errors","occur",")",".","n_docs_considered","(","int",")",":","number","of","top","search","results","that","will","be","searched","for","answer","Default:10","n_answers","(","int",")",":","maximum","number","of","candidate","answers","to","return","Default:50","raw_confidence","(","bool",")",":","If","True",",","show","raw","confidence","score","of","each","answer",".","It","could","be","used","to","mitigate","very","high","confidence","on","first","answer","when","softmax","is","used",".","If","False",",","perform","softmax","on","raw","confidence","scores",".","Default",":","False","rerank_threshold","(","int",")",":","rerank","top","answers","with","confidence",">","=","rerank_threshold","based","on","semantic","similarity","between","question","and","answer",".","This","can","help","bump","the","correct","answer","closer","to","the","top",".","Default:0.015",".","This","should","be","changed","to","somethink","like","6.0","if","raw_confidence=True",".","If","None",",","no","re-ranking","is","performed",".","include_np","(","bool",")",":","If","True",",","noun","phrases","will","be","extracted","from","question","and","included","in","query","that","retrieves","documents","likely","to","contain","candidate","answers",".","This","may","be","useful","if","you","ask","a","question","about","artificial","intelligence","and","the","answers","returned","pertain","just","to","intelligence",",","for","example",".","Note",":","include_np=True","requires","textblob","be","installed",".","Default",":","False","Returns",":","list","``","`"]
code: def ask(
      self,
      question,
      query=None,
      batch_size=8,
      n_docs_considered=10,
      n_answers=50,
      raw_confidence=False,
      rerank_threshold=0.015,
      include_np=False,
  ):
      """
      ```
      submit question to obtain candidate answers
  
      Args:
        question(str): question in the form of a string
        query(str): Optional. If not None, words in query will be used to retrieve contexts instead of words in question
        batch_size(int):  number of question-context pairs fed to model at each iteration
                          Default:8
                          Increase for faster answer-retrieval.
                          Decrease to reduce memory (if out-of-memory errors occur).
        n_docs_considered(int): number of top search results that will
                                be searched for answer
                                Default:10
        n_answers(int): maximum number of candidate answers to return
                        Default:50
        raw_confidence(bool): If True, show raw confidence score of each answer. It could be used to
                              mitigate very high confidence on first answer when softmax is used.
                              If False, perform softmax on raw confidence scores.
                              Default: False
        rerank_threshold(int): rerank top answers with confidence >= rerank_threshold
                               based on semantic similarity between question and answer.
                               This can help bump the correct answer closer to the top.
                               Default:0.015. This should be changed to somethink like 6.0
                               if raw_confidence=True.
                               If None, no re-ranking is performed.
        include_np(bool):  If True, noun phrases will be extracted from question and included
                           in query that retrieves documents likely to contain candidate answers.
                           This may be useful if you ask a question about artificial intelligence
                           and the answers returned pertain just to intelligence, for example.
                           Note: include_np=True requires textblob be installed.
                           Default:False
      Returns:
        list
      ```
      """
      # sanity check
      if (
          raw_confidence
          and rerank_threshold is not None
          and rerank_threshold < 1.00
      ):
          warnings.warn(
              "Raw confidence is used, but rerank_threshold value is below 1.00: are you sure you this is what you wanted?"
          )
  
      # locate candidate document contexts
      doc_results = self.search(
          process_question(
              query if query is not None else question,
              include_np=include_np,
          ),
          limit=n_docs_considered,
      )
      if not doc_results:
          warnings.warn(
              "No documents matched words in question (or query if supplied)"
          )
          return []
  
      # extract paragraphs as contexts
      contexts, refs = self._split_contexts(doc_results)
  
      # batchify contexts
      context_batches = self._batchify(contexts, batch_size=batch_size)
  
      # locate candidate answers
      answers = []
      mb = master_bar(range(1))
      answer_batches = []
      for i in mb:
          idx = 0
          for batch_id, contexts in enumerate(
              progress_bar(context_batches, parent=mb)
          ):
              answer_batch = self.predict_squad(contexts, question)
              answer_batches.extend(answer_batch)
              for answer in answer_batch:
                  idx += 1
                  if (
                      not answer["answer"]
                      or answer["confidence"] < -100
                  ):
                      continue
                  answer["confidence"] = answer["confidence"]
                  answer["reference"] = refs[idx - 1]
                  answer = self._expand_answer(answer)
                  answers.append(answer)
  
              mb.child.comment = f"generating candidate answers"
  
      if not answers:
          return answers  # fix for #307
      answers = sorted(
          answers, key=lambda k: k["confidence"], reverse=True
      )
      if n_answers is not None:
          answers = answers[:n_answers]
  
      # transform confidence scores
      if not raw_confidence:
          confidences = [a["confidence"] for a in answers]
          max_conf = max(confidences)
          total = 0.0
          exp_scores = []
          for c in confidences:
              s = np.exp(c - max_conf)
              exp_scores.append(s)
          total = sum(exp_scores)
          for idx, c in enumerate(confidences):
              answers[idx]["confidence"] = exp_scores[idx] / total
  
      if rerank_threshold is None or self.te is None:
          return answers
  
      # re-rank
      top_confidences = [
          a["confidence"]
          for idx, a in enumerate(answers)
          if a["confidence"] > rerank_threshold
      ]
      v1 = self.te.embed(question, word_level=False)
      for idx, answer in enumerate(answers):
          # if idx >= rerank_top_n:
          if answer["confidence"] <= rerank_threshold:
              answer["similarity_score"] = 0.0
              continue
          v2 = self.te.embed(answer["full_answer"], word_level=False)
          score = v1 @ v2.T / (np.linalg.norm(v1) * np.linalg.norm(v2))
          answer["similarity_score"] = float(np.squeeze(score))
          answer["confidence"] = top_confidences[idx]
      answers = sorted(
          answers,
          key=lambda k: (k["similarity_score"], k["confidence"]),
          reverse=True,
      )
      for idx, confidence in enumerate(top_confidences):
          answers[idx]["confidence"] = confidence
  
      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 10 for calling the ExtractiveQABase obj's underlying member method code with example usage: obj.ask(question, query, batch_size, n_docs_considered, n_answers, raw_confidence, rerank_threshold, include_np) and returns: answers, list, answers, answers