prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Logger is not passed to translator
  When building the translator, there is a logger created but not passed to the translator:
  https://github.com/OpenNMT/OpenNMT-py/blob/35cf4f0ae774a4aa500318879a1a4d53408ac129/onmt/bin/translate.py#L18
  This results in a log file that only contains a single entry:
  https://github.com/OpenNMT/OpenNMT-py/blob/35cf4f0ae774a4aa500318879a1a4d53408ac129/onmt/bin/translate.py#L24
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `onmt/bin/translate.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 
  4 from __future__ import unicode_literals
  5 
  6 from onmt.utils.logging import init_logger
  7 from onmt.utils.misc import split_corpus
  8 from onmt.translate.translator import build_translator
  9 
  10 import onmt.opts as opts
  11 from onmt.utils.parse import ArgumentParser
  12 
  13 
  14 def translate(opt):
  15     ArgumentParser.validate_translate_opts(opt)
  16     logger = init_logger(opt.log_file)
  17 
  18     translator = build_translator(opt, report_score=True)
  19     src_shards = split_corpus(opt.src, opt.shard_size)
  20     tgt_shards = split_corpus(opt.tgt, opt.shard_size)
  21     shard_pairs = zip(src_shards, tgt_shards)
  22 
  23     for i, (src_shard, tgt_shard) in enumerate(shard_pairs):
  24         logger.info("Translating shard %d." % i)
  25         translator.translate(
  26             src=src_shard,
  27             tgt=tgt_shard,
  28             src_dir=opt.src_dir,
  29             batch_size=opt.batch_size,
  30             batch_type=opt.batch_type,
  31             attn_debug=opt.attn_debug,
  32             align_debug=opt.align_debug
  33             )
  34 
  35 
  36 def _get_parser():
  37     parser = ArgumentParser(description='translate.py')
  38 
  39     opts.config_opts(parser)
  40     opts.translate_opts(parser)
  41     return parser
  42 
  43 
  44 def main():
  45     parser = _get_parser()
  46 
  47     opt = parser.parse_args()
  48     translate(opt)
  49 
  50 
  51 if __name__ == "__main__":
  52     main()
  53
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/onmt/bin/translate.py b/onmt/bin/translate.py
  --- a/onmt/bin/translate.py
  +++ b/onmt/bin/translate.py
  @@ -15,7 +15,7 @@
       ArgumentParser.validate_translate_opts(opt)
       logger = init_logger(opt.log_file)
   
  -    translator = build_translator(opt, report_score=True)
  +    translator = build_translator(opt, logger=logger, report_score=True)
       src_shards = split_corpus(opt.src, opt.shard_size)
       tgt_shards = split_corpus(opt.tgt, opt.shard_size)
       shard_pairs = zip(src_shards, tgt_shards)
  
verification_info: {"golden_diff": "diff --git a/onmt/bin/translate.py b/onmt/bin/translate.py\n--- a/onmt/bin/translate.py\n+++ b/onmt/bin/translate.py\n@@ -15,7 +15,7 @@\n     ArgumentParser.validate_translate_opts(opt)\n     logger = init_logger(opt.log_file)\n \n-    translator = build_translator(opt, report_score=True)\n+    translator = build_translator(opt, logger=logger, report_score=True)\n     src_shards = split_corpus(opt.src, opt.shard_size)\n     tgt_shards = split_corpus(opt.tgt, opt.shard_size)\n     shard_pairs = zip(src_shards, tgt_shards)\n", "issue": "Logger is not passed to translator\nWhen building the translator, there is a logger created but not passed to the translator:\r\nhttps://github.com/OpenNMT/OpenNMT-py/blob/35cf4f0ae774a4aa500318879a1a4d53408ac129/onmt/bin/translate.py#L18\r\nThis results in a log file that only contains a single entry:\r\nhttps://github.com/OpenNMT/OpenNMT-py/blob/35cf4f0ae774a4aa500318879a1a4d53408ac129/onmt/bin/translate.py#L24\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nfrom __future__ import unicode_literals\n\nfrom onmt.utils.logging import init_logger\nfrom onmt.utils.misc import split_corpus\nfrom onmt.translate.translator import build_translator\n\nimport onmt.opts as opts\nfrom onmt.utils.parse import ArgumentParser\n\n\ndef translate(opt):\n    ArgumentParser.validate_translate_opts(opt)\n    logger = init_logger(opt.log_file)\n\n    translator = build_translator(opt, report_score=True)\n    src_shards = split_corpus(opt.src, opt.shard_size)\n    tgt_shards = split_corpus(opt.tgt, opt.shard_size)\n    shard_pairs = zip(src_shards, tgt_shards)\n\n    for i, (src_shard, tgt_shard) in enumerate(shard_pairs):\n        logger.info(\"Translating shard %d.\" % i)\n        translator.translate(\n            src=src_shard,\n            tgt=tgt_shard,\n            src_dir=opt.src_dir,\n            batch_size=opt.batch_size,\n            batch_type=opt.batch_type,\n            attn_debug=opt.attn_debug,\n            align_debug=opt.align_debug\n            )\n\n\ndef _get_parser():\n    parser = ArgumentParser(description='translate.py')\n\n    opts.config_opts(parser)\n    opts.translate_opts(parser)\n    return parser\n\n\ndef main():\n    parser = _get_parser()\n\n    opt = parser.parse_args()\n    translate(opt)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "onmt/bin/translate.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nfrom __future__ import unicode_literals\n\nfrom onmt.utils.logging import init_logger\nfrom onmt.utils.misc import split_corpus\nfrom onmt.translate.translator import build_translator\n\nimport onmt.opts as opts\nfrom onmt.utils.parse import ArgumentParser\n\n\ndef translate(opt):\n    ArgumentParser.validate_translate_opts(opt)\n    logger = init_logger(opt.log_file)\n\n    translator = build_translator(opt, logger=logger, report_score=True)\n    src_shards = split_corpus(opt.src, opt.shard_size)\n    tgt_shards = split_corpus(opt.tgt, opt.shard_size)\n    shard_pairs = zip(src_shards, tgt_shards)\n\n    for i, (src_shard, tgt_shard) in enumerate(shard_pairs):\n        logger.info(\"Translating shard %d.\" % i)\n        translator.translate(\n            src=src_shard,\n            tgt=tgt_shard,\n            src_dir=opt.src_dir,\n            batch_size=opt.batch_size,\n            batch_type=opt.batch_type,\n            attn_debug=opt.attn_debug,\n            align_debug=opt.align_debug\n            )\n\n\ndef _get_parser():\n    parser = ArgumentParser(description='translate.py')\n\n    opts.config_opts(parser)\n    opts.translate_opts(parser)\n    return parser\n\n\ndef main():\n    parser = _get_parser()\n\n    opt = parser.parse_args()\n    translate(opt)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "onmt/bin/translate.py"}]}