Add a new hypothesis to the list.
(self, hyp, sum_logprobs)
| 964 | return len(self.beams) |
| 965 | |
| 966 | def add(self, hyp, sum_logprobs): |
| 967 | """ |
| 968 | Add a new hypothesis to the list. |
| 969 | """ |
| 970 | score = sum_logprobs / len(hyp) ** self.length_penalty |
| 971 | if len(self) < self.num_beams or score > self.worst_score: |
| 972 | self.beams.append((score, hyp)) |
| 973 | if len(self) > self.num_beams: |
| 974 | sorted_scores = sorted([(s, idx) for idx, (s, _) in enumerate(self.beams)]) |
| 975 | del self.beams[sorted_scores[0][1]] |
| 976 | self.worst_score = sorted_scores[1][0] |
| 977 | else: |
| 978 | self.worst_score = min(score, self.worst_score) |
| 979 | |
| 980 | def is_done(self, best_sum_logprobs, cur_len): |
| 981 | """ |
no outgoing calls
no test coverage detected