Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit 518eaba

Browse files
martinpopelrsepassi
authored andcommitted
Better t2t-translate-all functionality (#676)
* wait until the directory is created (e.g. with t2t-translate-all) * t2t-translate relies on the translated files to have correct mtime "correct" here means the time of the checkpoint creation, not time when the evaluation was done. (In my original PR, --keep_timestamp was True by default, but I agree this is a bit non-standard.)
1 parent 9094fc1 commit 518eaba

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tensor2tensor/bin/t2t_bleu.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from __future__ import print_function
5858

5959
import os
60+
import time
6061

6162
# Dependency imports
6263

@@ -110,6 +111,14 @@ def main(_):
110111
raise ValueError(
111112
"Either --translation or --translations_dir must be specified.")
112113
transl_dir = os.path.expanduser(FLAGS.translations_dir)
114+
if not os.path.exists(transl_dir):
115+
exit_time = time.time() + FLAGS.wait_minutes * 60
116+
tf.logging.info("Translation dir %s does not exist, waiting till %s."
117+
% (transl_dir, time.asctime(time.localtime(exit_time))))
118+
while not os.path.exists(transl_dir):
119+
time.sleep(10)
120+
if time.time() > exit_time:
121+
raise ValueError("Translation dir %s does not exist" % transl_dir)
113122

114123
last_step_file = os.path.join(FLAGS.event_dir, "last_evaluated_step.txt")
115124
if FLAGS.min_steps == -1:

tensor2tensor/bin/t2t_translate_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def main(_):
9797
"--decode_hparams=beam_size={FLAGS.beam_size},alpha={FLAGS.alpha} "
9898
"--model={FLAGS.model} --hparams_set={FLAGS.hparams_set} "
9999
"--checkpoint_path={model.filename} --decode_from_file={source} "
100-
"--decode_to_file={out_file}"
100+
"--decode_to_file={out_file} --keep_timestamp"
101101
).format(**locals_and_flags)
102102
command = FLAGS.decoder_command.format(**locals())
103103
tf.logging.info("Running:\n" + command)

0 commit comments

Comments
 (0)