Abstract base class for all beam scorers that are used for :meth:`~transformers.PretrainedModel.beam_search` and :meth:`~transformers.PretrainedModel.beam_sample`.
| 110 | |
| 111 | |
| 112 | class BeamScorer(ABC): |
| 113 | """ |
| 114 | Abstract base class for all beam scorers that are used for :meth:`~transformers.PretrainedModel.beam_search` and |
| 115 | :meth:`~transformers.PretrainedModel.beam_sample`. |
| 116 | """ |
| 117 | |
| 118 | @abstractmethod |
| 119 | def process( |
| 120 | self, |
| 121 | input_ids: torch.LongTensor, |
| 122 | next_scores: torch.FloatTensor, |
| 123 | next_tokens: torch.LongTensor, |
| 124 | next_indices: torch.LongTensor, |
| 125 | **kwargs |
| 126 | ) -> Tuple[torch.Tensor]: |
| 127 | raise NotImplementedError("This is an abstract method.") |
| 128 | |
| 129 | @abstractmethod |
| 130 | def finalize( |
| 131 | self, |
| 132 | input_ids: torch.LongTensor, |
| 133 | next_scores: torch.FloatTensor, |
| 134 | next_tokens: torch.LongTensor, |
| 135 | next_indices: torch.LongTensor, |
| 136 | **kwargs |
| 137 | ) -> torch.LongTensor: |
| 138 | raise NotImplementedError("This is an abstract method.") |
| 139 | |
| 140 | |
| 141 | class BeamSearchScorer(BeamScorer): |
nothing calls this directly
no outgoing calls
no test coverage detected