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

Function test_callback_batch_id

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

Source from the content-addressed store, hash-verified

232
233
234def test_callback_batch_id():
235 # The method will internally sort the input from longest to shortest,
236 # but we check that the returned batch ids match the user input.
237
238 source = [
239 ["ن"] * 1,
240 ["ن"] * 2,
241 ["ن"] * 3,
242 ]
243
244 target_prefix = [
245 ["a"],
246 ["b"],
247 ["c"],
248 ]
249
250 def _callback(step_result):
251 assert step_result.token == target_prefix[step_result.batch_id][0]
252 return True
253
254 translator = _get_transliterator()
255 translator.translate_batch(
256 source,
257 target_prefix,
258 max_batch_size=2,
259 beam_size=1,
260 callback=_callback,
261 )
262
263
264def test_file_translation(tmp_dir):

Callers

nothing calls this directly

Calls 2

_get_transliteratorFunction · 0.85
translate_batchMethod · 0.45

Tested by

no test coverage detected