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

Commit

Permalink
Merge pull request #426 from martinpopel/decode-to-file
Browse files Browse the repository at this point in the history
fix the semantics of decode_to_file
  • Loading branch information
lukaszkaiser authored Nov 23, 2017
2 parents 8ca9709 + 985b637 commit c78abcd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
5 changes: 2 additions & 3 deletions tensor2tensor/bin/t2t-decoder
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ flags = tf.flags
FLAGS = flags.FLAGS

flags.DEFINE_string("output_dir", "", "Training directory to load from.")
flags.DEFINE_string("decode_from_file", None, "Path to decode file")
flags.DEFINE_string("decode_to_file", None,
"Path prefix to inference output file")
flags.DEFINE_string("decode_from_file", None, "Path to the source file for decoding")
flags.DEFINE_string("decode_to_file", None, "Path to the decoded (output) file")
flags.DEFINE_bool("decode_interactive", False,
"Interactive local inference mode.")
flags.DEFINE_integer("decode_shards", 1, "Number of decoding replicas.")
Expand Down
17 changes: 7 additions & 10 deletions tensor2tensor/utils/decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,14 @@ def input_fn():
# _decode_batch_input_fn
sorted_inputs.reverse()
decodes.reverse()
# Dumping inputs and outputs to file filename.decodes in
# format result\tinput in the same order as original inputs
if decode_to_file:
output_filename = decode_to_file
else:
output_filename = filename
# If decode_to_file was provided use it as the output filename without any change
# (except for adding shard_id if using more shards for decoding).
# Otherwise, use the input filename plus model, hp, problem, beam, alpha.
decode_filename = decode_to_file if decode_to_file else filename
if decode_hp.shards > 1:
base_filename = output_filename + ("%.2d" % decode_hp.shard_id)
else:
base_filename = output_filename
decode_filename = _decode_filename(base_filename, problem_name, decode_hp)
decode_filename = decode_filename + ("%.2d" % decode_hp.shard_id)
if not decode_to_file:
decode_filename = _decode_filename(decode_filename, problem_name, decode_hp)
tf.logging.info("Writing decodes into %s" % decode_filename)
outfile = tf.gfile.Open(decode_filename, "w")
for index in range(len(sorted_inputs)):
Expand Down

0 comments on commit c78abcd

Please sign in to comment.