MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / test_callback_hypothesis_id

Function test_callback_hypothesis_id

python/tests/test_translator.py:214–231  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

212
213
214def test_callback_hypothesis_id():
215 hypotheses = collections.defaultdict(list)
216
217 def _callback(step_result):
218 assert step_result.batch_id == 0
219 hypotheses[step_result.hypothesis_id].append(step_result.token)
220
221 source = ["آ", "ت", "ز", "م", "و", "ن"]
222 translator = _get_transliterator()
223 translator.translate_batch(
224 [source],
225 beam_size=1,
226 sampling_topk=20,
227 num_hypotheses=3,
228 callback=_callback,
229 )
230
231 assert len(hypotheses) == 3
232
233
234def test_callback_batch_id():

Callers

nothing calls this directly

Calls 2

_get_transliteratorFunction · 0.85
translate_batchMethod · 0.45

Tested by

no test coverage detected