Scores multiple annotations at once, useful for batching model calls. Note this method does not handle batching, and the length of the list will be used as the batch size. Args: paired_annos: A single batch of annotations to score. Yields: ScoredPair objects consisting
(
self, paired_annos: List[annotation.PairedAnnotation]
)
| 170 | self.qsim_model = qsim_model |
| 171 | |
| 172 | def score_batch( |
| 173 | self, paired_annos: List[annotation.PairedAnnotation] |
| 174 | ) -> Iterable[ScoredPair]: |
| 175 | """Scores multiple annotations at once, useful for batching model calls. |
| 176 | |
| 177 | Note this method does not handle batching, and the length of the list will |
| 178 | be used as the batch size. |
| 179 | |
| 180 | Args: |
| 181 | paired_annos: A single batch of annotations to score. |
| 182 | |
| 183 | Yields: |
| 184 | ScoredPair objects consisting of the annotation with metrics populated. |
| 185 | Note that bleurt and qsim might be None if the models were not loaded. |
| 186 | """ |
| 187 | labels = [_normalize_and_get_label(anno) for anno in paired_annos] |
| 188 | nones = [None] * len(paired_annos) |
| 189 | bleurts = ( |
| 190 | self.batch_bleurt(paired_annos) |
| 191 | if self.bleurt_scorer is not None |
| 192 | else nones |
| 193 | ) |
| 194 | qsims = ( |
| 195 | self.qsim_model.are_paired_annos_duplicate(paired_annos) |
| 196 | if self.qsim_model is not None |
| 197 | else nones |
| 198 | ) |
| 199 | for i, paired_anno in enumerate(paired_annos): |
| 200 | rouge = self.get_rouge_L(paired_anno) |
| 201 | f1 = self.get_f1(paired_anno) |
| 202 | score = Score(rouge, f1, labels[i], bleurts[i], qsims[i]) |
| 203 | yield ScoredPair(score, paired_anno) |
| 204 | |
| 205 | def score_pair(self, paired_anno: annotation.PairedAnnotation) -> ScoredPair: |
| 206 | """Scores paired annotation for standard metrics. |
no test coverage detected