qa_system.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:document-qa 作者: allenai 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号