bert_max_doc_str_max_str_pos_clean_doc_noise_doc/run_doc_qa.py
def doc_normalization(results, unique_id_to_qid):
    """Normalizes each RawResult using the qid."""

    qid_to_start_logits = collections.defaultdict(list)
    qid_to_end_logits = collections.defaultdict(list)

    for result in results:
        qid = unique_id_to_qid.get(result.unique_id, None)
        if not qid:
            raise ValueError("Unknown qid for unique_id {0}".format(
                result.unique_id))
        qid_to_start_logits[qid].extend(result.start_logits)
        qid_to_end_logits[qid].extend(result.end_logits)

    # Normalizes the scores.
    qid_to_doc_start_score = collections.defaultdict(float)
    qid_to_doc_end_score = collections.defaultdict(float)

    for qid in qid_to_start_logits:
        start_logits = qid_to_start_logits[qid]
        end_logits = qid_to_end_logits[qid]

        qid_to_doc_start_score[qid] = logsumexp(start_logits)
        qid_to_doc_end_score[qid] = logsumexp(end_logits)

    def normalize(scores, normalization_score):
        return [score - normalization_score for score in scores]

    def normalized_result_generator(result_list):
        """The generator function for normalizing the results."""
        for result in result_list:
            qid = unique_id_to_qid[result.unique_id]
            doc_start_score = qid_to_doc_start_score[qid]
            doc_end_score = qid_to_doc_end_score[qid]
            yield RawResult(
                unique_id=result.unique_id,
                start_logits=normalize(result.start_logits, doc_start_score),
                end_logits=normalize(result.end_logits, doc_end_score)
            )

    # Iterates for the second time to apply the document level normalization.
    new_results = [norm_result
                   for norm_result in normalized_result_generator(results)]

    return new_results
Normalizes each RawResult using the qid.
Normalizes each RawResult using the qid.
Normalizes each RawResult using the qid .
def doc_normalization(results, unique_id_to_qid):
    qid_to_start_logits = collections.defaultdict(list)
    qid_to_end_logits = collections.defaultdict(list)
    for result in results:
        qid = unique_id_to_qid.get(result.unique_id, None)
        if not qid:
            raise ValueError("Unknown qid for unique_id {0}".format(
                result.unique_id))
        qid_to_start_logits[qid].extend(result.start_logits)
        qid_to_end_logits[qid].extend(result.end_logits)
    qid_to_doc_start_score = collections.defaultdict(float)
    qid_to_doc_end_score = collections.defaultdict(float)
    for qid in qid_to_start_logits:
        start_logits = qid_to_start_logits[qid]
        end_logits = qid_to_end_logits[qid]
        qid_to_doc_start_score[qid] = logsumexp(start_logits)
        qid_to_doc_end_score[qid] = logsumexp(end_logits)
    def normalize(scores, normalization_score):
        return [score - normalization_score for score in scores]
    def normalized_result_generator(result_list):
        for result in result_list:
            qid = unique_id_to_qid[result.unique_id]
            doc_start_score = qid_to_doc_start_score[qid]
            doc_end_score = qid_to_doc_end_score[qid]
            yield RawResult(
                unique_id=result.unique_id,
                start_logits=normalize(result.start_logits, doc_start_score),
                end_logits=normalize(result.end_logits, doc_end_score)
            )
    new_results = [norm_result
                   for norm_result in normalized_result_generator(results)]
    return new_results
def doc_normalization ( results , unique_id_to_qid ) : qid_to_start_logits = collections . defaultdict ( list ) qid_to_end_logits = collections . defaultdict ( list ) for result in results : qid = unique_id_to_qid . get ( result . unique_id , None ) if not qid : raise ValueError ( "Unknown qid for unique_id {0}" . format ( result . unique_id ) ) qid_to_start_logits [ qid ] . extend ( result . start_logits ) qid_to_end_logits [ qid ] . extend ( result . end_logits ) qid_to_doc_start_score = collections . defaultdict ( float ) qid_to_doc_end_score = collections . defaultdict ( float ) for qid in qid_to_start_logits : start_logits = qid_to_start_logits [ qid ] end_logits = qid_to_end_logits [ qid ] qid_to_doc_start_score [ qid ] = logsumexp ( start_logits ) qid_to_doc_end_score [ qid ] = logsumexp ( end_logits ) def normalize ( scores , normalization_score ) : return [ score - normalization_score for score in scores ] def normalized_result_generator ( result_list ) : """The generator function for normalizing the results.""" for result in result_list : qid = unique_id_to_qid [ result . unique_id ] doc_start_score = qid_to_doc_start_score [ qid ] doc_end_score = qid_to_doc_end_score [ qid ] yield RawResult ( unique_id = result . unique_id , start_logits = normalize ( result . start_logits , doc_start_score ) , end_logits = normalize ( result . end_logits , doc_end_score ) ) new_results = [ norm_result for norm_result in normalized_result_generator ( results ) ] return new_results
Normalizes each RawResult using the qid.
Normalizes each RawResult using the qid .
"""Normalizes each RawResult using the qid.""" # Normalizes the scores. """The generator function for normalizing the results.""" # Iterates for the second time to apply the document level normalization.
results
unique_id_to_qid