Exemple #1
0
def on_debug(session: Session):
    """Add session configs to nboost response for debugging."""
    for config in session.cli_configs:
        session.add_nboost_response(config, getattr(session, config))

    session.add_nboost_response('query', session.query)
    session.add_nboost_response('topk', session.stats['topk'])
    session.add_nboost_response('cvalues', session.cvalues)
Exemple #2
0
def on_qa(session: Session, qa_model: QAModel):
    """Returns the qa time."""

    if session.cvalues:
        start_time = time.perf_counter()
        answer, start_pos, stop_pos, score = qa_model.get_answer(session.query, session.cvalues[0])
        session.stats['qa_time'] = time.perf_counter() - start_time

        if score > session.qa_threshold:
            session.add_nboost_response('answer_text', answer)
            session.add_nboost_response('answer_start_pos', start_pos)
            session.add_nboost_response('answer_stop_pos', stop_pos)

        if session.cids:
            first_choice_id = session.cids[0]
            if first_choice_id in session.qa_cids:
                qa_start_pos, qa_end_pos = session.qa_cids[first_choice_id]
                session.stats['qa_overlap'] = calculate_overlap(qa_start_pos,
                                                                qa_end_pos,
                                                                qa_start_pos,
                                                                qa_end_pos)