()
| 378 | return translation_result_list |
| 379 | |
| 380 | def main(): |
| 381 | parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 382 | parser.add_argument('-batch', '--batch_size', type=int, default=1, metavar='NUMBER', |
| 383 | help='batch size (default: 1)') |
| 384 | parser.add_argument('-beam', '--beam_width', type=int, default=4, metavar='NUMBER', |
| 385 | help='beam width (default: 4)') |
| 386 | parser.add_argument('-s', '--max_seq_len', type=int, default=200, metavar='NUMBER', |
| 387 | help='max sequence length (default: 200)') |
| 388 | parser.add_argument("--source", default="../examples/tensorflow/decoding/utils/translation/test.en", |
| 389 | help="Path to the source file.") |
| 390 | parser.add_argument("--target", default="../examples/tensorflow/decoding/utils/translation/test.de", |
| 391 | help="Path to the target file.") |
| 392 | parser.add_argument("--source_vocabulary", default="../examples/tensorflow/decoding/utils/translation/wmtende.vocab", |
| 393 | help="Path to the source vocabulary.") |
| 394 | parser.add_argument("--target_vocabulary", default="../examples/tensorflow/decoding/utils/translation/wmtende.vocab", |
| 395 | help="Path to the target vocabulary.") |
| 396 | parser.add_argument("--model_dir", default="../translation/ckpt", |
| 397 | help="Directory where checkpoint are written.") |
| 398 | parser.add_argument('-time', '--test_time', type=str, default='', metavar='STRING', |
| 399 | help=''' |
| 400 | Test the time of which one (default: '' (not test anyone) ); |
| 401 | '': not test anyone |
| 402 | '0': test tf_decoding_beamsearch |
| 403 | '1': test op_decoder_beamsearch |
| 404 | '2': test op_decoding_beamsearch |
| 405 | '3': test tf_decoding_sampling |
| 406 | '4': test op_decoder_sampling |
| 407 | '5': test op_decoding_sampling |
| 408 | 'e.g., if you want to test op_decoder_beamsearch and op_decoding_sampling, |
| 409 | then you need to use -time '15' ''') |
| 410 | parser.add_argument('-diversity_rate', '--beam_search_diversity_rate', type=float, default=0.0, metavar='NUMBER', |
| 411 | help='deviersity rate of beam search. default is 0. When diversity rate = 0, it is equivalent to the naive beam search.') |
| 412 | parser.add_argument('-topk', '--sampling_topk', type=int, default=1, metavar='NUMBER', |
| 413 | help='Candidate (k) value of top k sampling in decoding. Default is 1.') |
| 414 | parser.add_argument('-topp', '--sampling_topp', type=float, default=0.0, metavar='NUMBER', |
| 415 | help='Probability (p) value of top p sampling in decoding. Default is 0.0. ') |
| 416 | parser.add_argument('-d', '--data_type', type=str, default="fp32", metavar='STRING', |
| 417 | help='data type (default: fp32)', choices=['fp32', 'fp16', 'bf16']) |
| 418 | parser.add_argument('-max_ite', '--max_iteration', type=int, default=100000, metavar='NUMBER', |
| 419 | help='Maximum iteraiton for translation, default is 100000 (as large as possible to run all test set).') |
| 420 | args = parser.parse_args() |
| 421 | translate(vars(args)) |
| 422 | |
| 423 | # example script |
| 424 | # python ../examples/tensorflow/decoding/translate_example.py --source ../examples/tensorflow/decoding/utils/translation/test.en --target ../examples/tensorflow/decoding/utils/translation/test.de --source_vocabulary ../examples/tensorflow/decoding/utils/translation/wmtende.vocab --target_vocabulary ../examples/tensorflow/decoding/utils/translation/wmtende.vocab --model_dir ../translation/ckpt/ -time 02 |
no test coverage detected