def answer_with_doc(self, question: str, doc: str) -> Tuple[np.ndarray, List[WebParagraph]]:
""" Answer a question using the given text as a document """
self.log.info("Answering question \"%s\" with a given document" % question)
# Tokenize
question = self.tokenizer.tokenize_paragraph_flat(question)
context = [self.tokenizer.tokenize_with_inverse(x, False) for x in self._split_regex.split(doc)]
# Split into super-paragraphs
context = self._split_document(context, "User", None)
# Select top paragraphs
context = self.paragraph_selector.prune(question, context)
if len(context) == 0:
raise ValueError("Unable to process documents")
# Select the top answer span
t0 = time.perf_counter()
span_scores = self._get_span_scores(question, context)
self.log.info("Computing answer spans took %.5f seconds" % (time.perf_counter() - t0))
return span_scores
评论列表
文章目录