BERT_rationale_benchmark/models/pipeline/pipeline_utils.py
def annotations_to_evidence_classification(annotations: List[Annotation],
                                           documents: Dict[str, List[List[Any]]],
                                           class_interner: Dict[str, int],
                                           include_all: bool
                                           ) -> 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 = []
    for ann in annotations:
        ann_id = ann.annotation_id
        docids = set(ev.docid for ev in chain.from_iterable(ann.evidences))
        annotations_for_doc = defaultdict(list)
        for d in docids:
            for index, sent in enumerate(documents[d]):
                annotations_for_doc[d].append(
                    SentenceEvidence(
                        kls=class_interner[ann.classification],
                        query=ann.query,
                        ann_id=ann.annotation_id,
                        docid=d,
                        index=index,
                        sentence=tuple(sent)))
        if include_all:
            ret.extend(chain.from_iterable(annotations_for_doc.values()))
        else:
            contributes = set()
            for ev in chain.from_iterable(ann.evidences):
                for index in range(ev.start_sentence, ev.end_sentence):
                    contributes.add(annotations_for_doc[ev.docid][index])
            ret.extend(contributes)
    assert len(ret) > 0
    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_classification(annotations: List[Annotation],
                                           documents: Dict[str, List[List[Any]]],
                                           class_interner: Dict[str, int],
                                           include_all: bool
                                           ) -> List[SentenceEvidence]:
    ret = []
    for ann in annotations:
        ann_id = ann.annotation_id
        docids = set(ev.docid for ev in chain.from_iterable(ann.evidences))
        annotations_for_doc = defaultdict(list)
        for d in docids:
            for index, sent in enumerate(documents[d]):
                annotations_for_doc[d].append(
                    SentenceEvidence(
                        kls=class_interner[ann.classification],
                        query=ann.query,
                        ann_id=ann.annotation_id,
                        docid=d,
                        index=index,
                        sentence=tuple(sent)))
        if include_all:
            ret.extend(chain.from_iterable(annotations_for_doc.values()))
        else:
            contributes = set()
            for ev in chain.from_iterable(ann.evidences):
                for index in range(ev.start_sentence, ev.end_sentence):
                    contributes.add(annotations_for_doc[ev.docid][index])
            ret.extend(contributes)
    assert len(ret) > 0
    return ret
def annotations_to_evidence_classification ( annotations : List [ Annotation ] , documents : Dict [ str , List [ List [ Any ] ] ] , class_interner : Dict [ str , int ] , include_all : bool ) -> List [ SentenceEvidence ] : ret = [ ] for ann in annotations : ann_id = ann . annotation_id docids = set ( ev . docid for ev in chain . from_iterable ( ann . evidences ) ) annotations_for_doc = defaultdict ( list ) for d in docids : for index , sent in enumerate ( documents [ d ] ) : annotations_for_doc [ d ] . append ( SentenceEvidence ( kls = class_interner [ ann . classification ] , query = ann . query , ann_id = ann . annotation_id , docid = d , index = index , sentence = tuple ( sent ) ) ) if include_all : ret . extend ( chain . from_iterable ( annotations_for_doc . values ( ) ) ) else : contributes = set ( ) for ev in chain . from_iterable ( ann . evidences ) : for index in range ( ev . start_sentence , ev . end_sentence ) : contributes . add ( annotations_for_doc [ ev . docid ] [ index ] ) ret . extend ( contributes ) assert len ( ret ) > 0 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]
    """
annotations
List[Annotation]
documents
Dict[str, List[List[Any]]]
class_interner
Dict[str, int]
include_all
bool