argmax with deterministic pseudorandom tie breaking.
(array)
| 180 | |
| 181 | |
| 182 | def _argmax(array): |
| 183 | """argmax with deterministic pseudorandom tie breaking.""" |
| 184 | max_indices = np.arange(len(array))[array == np.max(array)] |
| 185 | idx = int(hashlib.sha256(np.asarray(array).tobytes()).hexdigest(), 16) % len( |
| 186 | max_indices |
| 187 | ) |
| 188 | return max_indices[idx] |
| 189 | |
| 190 | |
| 191 | def _postprocess_output(text, max_length, stop_string, output_regex): |