If there are enough hypotheses and that none of the hypotheses being generated can become better than the worst one in the heap, then we are done with this sentence.
(self, best_sum_logprobs: float, cur_len: int)
| 374 | self.worst_score = min(score, self.worst_score) |
| 375 | |
| 376 | def is_done(self, best_sum_logprobs: float, cur_len: int) -> bool: |
| 377 | """ |
| 378 | If there are enough hypotheses and that none of the hypotheses being generated can become better than the worst |
| 379 | one in the heap, then we are done with this sentence. |
| 380 | """ |
| 381 | |
| 382 | if len(self) < self.num_beams: |
| 383 | return False |
| 384 | elif self.early_stopping: |
| 385 | return True |
| 386 | else: |
| 387 | cur_score = best_sum_logprobs / cur_len ** self.length_penalty |
| 388 | ret = self.worst_score >= cur_score |
| 389 | return ret |
| 390 | |
| 391 | |
| 392 | class LogitsProcessor(ABC): |