BERT_rationale_benchmark/models/pipeline/pipeline_utils.py
def annotations_to_evidence_identification(annotations: List[Annotation],
                                           documents: Dict[str, List[List[Any]]]
                                           ) -> Dict[str, Dict[str, List[SentenceEvidence]]]:
    """Converts Corpus-Level annotations to Sentence Level relevance judgments.

    As this module is about a pipelined approach for evidence identification,
    inputs to both an evidence identifier and evidence classifier need to be to
    be on a sentence level, this module converts data to be that form.

    The return type is of the form
        annotation id -> docid -> [sentence level annotations]
    """
    ret = defaultdict(dict)  # annotation id -> docid -> sentences
    for ann in annotations:
        ann_id = ann.annotation_id
        for ev_group in ann.evidences:
            for ev in ev_group:
                if len(ev.text) == 0:
                    continue
                if ev.docid not in ret[ann_id]:
                    ret[ann.annotation_id][ev.docid] = []
                    # populate the document with "not evidence"; to be filled in later
                    for index, sent in enumerate(documents[ev.docid]):
                        ret[ann.annotation_id][ev.docid].append(SentenceEvidence(
                            kls=0,
                            query=ann.query,
                            ann_id=ann.annotation_id,
                            docid=ev.docid,
                            index=index,
                            sentence=sent))
                # define the evidence sections of the document
                for s in range(ev.start_sentence, ev.end_sentence):
                    ret[ann.annotation_id][ev.docid][s] = SentenceEvidence(
                        kls=1,
                        ann_id=ann.annotation_id,
                        query=ann.query,
                        docid=ev.docid,
                        index=ret[ann.annotation_id][ev.docid][s].index,
                        sentence=ret[ann.annotation_id][ev.docid][s].sentence)
    return ret
Converts Corpus-Level annotations to Sentence Level relevance judgments.

    As this module is about a pipelined approach for evidence identification,
    inputs to both an evidence identifier and evidence classifier need to be to
    be on a sentence level, this module converts data to be that form.

    The return type is of the form
        annotation id -> docid -> [sentence level annotations]
    
Converts Corpus-Level annotations to Sentence Level relevance judgments.
As this module is about a pipelined approach for evidence identification,
inputs to both an evidence identifier and evidence classifier need to be to
be on a sentence level, this module converts data to be that form.

The return type is of the form
annotation id -> docid -> [sentence level annotations]
Converts Corpus - Level annotations to Sentence Level relevance judgments . As this module is about a pipelined approach for evidence identification inputs to both an evidence identifier and evidence classifier need to be to be on a sentence level this module converts data to be that form . The return type is of the form annotation id - > docid - > [ sentence level annotations ]
def annotations_to_evidence_identification(annotations: List[Annotation],
                                           documents: Dict[str, List[List[Any]]]
                                           ) -> Dict[str, Dict[str, List[SentenceEvidence]]]:
    ret = defaultdict(dict)  
    for ann in annotations:
        ann_id = ann.annotation_id
        for ev_group in ann.evidences:
            for ev in ev_group:
                if len(ev.text) == 0:
                    continue
                if ev.docid not in ret[ann_id]:
                    ret[ann.annotation_id][ev.docid] = []
                    for index, sent in enumerate(documents[ev.docid]):
                        ret[ann.annotation_id][ev.docid].append(SentenceEvidence(
                            kls=0,
                            query=ann.query,
                            ann_id=ann.annotation_id,
                            docid=ev.docid,
                            index=index,
                            sentence=sent))
                for s in range(ev.start_sentence, ev.end_sentence):
                    ret[ann.annotation_id][ev.docid][s] = SentenceEvidence(
                        kls=1,
                        ann_id=ann.annotation_id,
                        query=ann.query,
                        docid=ev.docid,
                        index=ret[ann.annotation_id][ev.docid][s].index,
                        sentence=ret[ann.annotation_id][ev.docid][s].sentence)
    return ret
def annotations_to_evidence_identification ( annotations : List [ Annotation ] , documents : Dict [ str , List [ List [ Any ] ] ] ) -> Dict [ str , Dict [ str , List [ SentenceEvidence ] ] ] : ret = defaultdict ( dict ) for ann in annotations : ann_id = ann . annotation_id for ev_group in ann . evidences : for ev in ev_group : if len ( ev . text ) == 0 : continue if ev . docid not in ret [ ann_id ] : ret [ ann . annotation_id ] [ ev . docid ] = [ ] for index , sent in enumerate ( documents [ ev . docid ] ) : ret [ ann . annotation_id ] [ ev . docid ] . append ( SentenceEvidence ( kls = 0 , query = ann . query , ann_id = ann . annotation_id , docid = ev . docid , index = index , sentence = sent ) ) for s in range ( ev . start_sentence , ev . end_sentence ) : ret [ ann . annotation_id ] [ ev . docid ] [ s ] = SentenceEvidence ( kls = 1 , ann_id = ann . annotation_id , query = ann . query , docid = ev . docid , index = ret [ ann . annotation_id ] [ ev . docid ] [ s ] . index , sentence = ret [ ann . annotation_id ] [ ev . docid ] [ s ] . sentence ) return ret
Converts Corpus-Level annotations to Sentence Level relevance judgments.
Converts Corpus - Level annotations to Sentence Level relevance judgments .
"""Converts Corpus-Level annotations to Sentence Level relevance judgments.

    As this module is about a pipelined approach for evidence identification,
    inputs to both an evidence identifier and evidence classifier need to be to
    be on a sentence level, this module converts data to be that form.

    The return type is of the form
        annotation id -> docid -> [sentence level annotations]
    """ # annotation id -> docid -> sentences # populate the document with "not evidence"; to be filled in later # define the evidence sections of the document
annotations
List[Annotation]
documents
Dict[str, List[List[Any]]]