code: def main(_):
      tf.logging.set_verbosity(tf.logging.INFO)
      if FLAGS.translation:
          if FLAGS.translations_dir:
              raise ValueError(
                  "Cannot specify both --translation and --translations_dir."
              )
          if FLAGS.bleu_variant in ("uncased", "both"):
              bleu = 100 * bleu_hook.bleu_wrapper(
                  FLAGS.reference,
                  FLAGS.translation,
                  case_sensitive=False,
              )
              print("BLEU_uncased = %6.2f" % bleu)
          if FLAGS.bleu_variant in ("cased", "both"):
              bleu = 100 * bleu_hook.bleu_wrapper(
                  FLAGS.reference,
                  FLAGS.translation,
                  case_sensitive=True,
              )
              print("BLEU_cased = %6.2f" % bleu)
          return
  
      if not FLAGS.translations_dir:
          raise ValueError(
              "Either --translation or --translations_dir must be specified."
          )
      transl_dir = os.path.expanduser(FLAGS.translations_dir)
      if not os.path.exists(transl_dir):
          exit_time = time.time() + FLAGS.wait_minutes * 60
          tf.logging.info(
              "Translation dir %s does not exist, waiting till %s.",
              transl_dir,
              time.asctime(time.localtime(exit_time)),
          )
          while not os.path.exists(transl_dir):
              time.sleep(10)
              if time.time() > exit_time:
                  raise ValueError(
                      "Translation dir %s does not exist" % transl_dir
                  )
  
      last_step_file = os.path.join(
          FLAGS.event_dir, "last_evaluated_step.txt"
      )
      if FLAGS.min_steps == -1:
          if tf.gfile.Exists(last_step_file):
              with open(last_step_file) as ls_file:
                  FLAGS.min_steps = int(ls_file.read())
          else:
              FLAGS.min_steps = 0
      if FLAGS.report_zero is None:
          FLAGS.report_zero = FLAGS.min_steps == 0
  
      writer = tf.summary.FileWriter(FLAGS.event_dir)
      for transl_file in bleu_hook.stepfiles_iterator(
          transl_dir,
          FLAGS.wait_minutes,
          FLAGS.min_steps,
          path_suffix="",
      ):
          # report_zero handling must be inside the for-loop,
          # so we are sure the transl_dir is already created.
          if FLAGS.report_zero:
              all_files = (
                  os.path.join(transl_dir, f)
                  for f in os.listdir(transl_dir)
              )
              start_time = min(
                  os.path.getmtime(f)
                  for f in all_files
                  if os.path.isfile(f)
              )
              values = []
              if FLAGS.bleu_variant in ("uncased", "both"):
                  values.append(
                      tf.Summary.Value(
                          tag="BLEU_uncased" + FLAGS.tag_suffix,
                          simple_value=0,
                      )
                  )
              if FLAGS.bleu_variant in ("cased", "both"):
                  values.append(
                      tf.Summary.Value(
                          tag="BLEU_cased" + FLAGS.tag_suffix,
                          simple_value=0,
                      )
                  )
              writer.add_event(
                  tf.summary.Event(
                      summary=tf.Summary(value=values),
                      wall_time=start_time,
                      step=0,
                  )
              )
              FLAGS.report_zero = False
  
          filename = transl_file.filename
          tf.logging.info("Evaluating " + filename)
          values = []
          if FLAGS.bleu_variant in ("uncased", "both"):
              bleu = 100 * bleu_hook.bleu_wrapper(
                  FLAGS.reference, filename, case_sensitive=False
              )
              values.append(
                  tf.Summary.Value(
                      tag="BLEU_uncased" + FLAGS.tag_suffix,
                      simple_value=bleu,
                  )
              )
              tf.logging.info(
                  "%s: BLEU_uncased = %6.2f" % (filename, bleu)
              )
          if FLAGS.bleu_variant in ("cased", "both"):
              bleu = 100 * bleu_hook.bleu_wrapper(
                  FLAGS.reference, filename, case_sensitive=True
              )
              values.append(
                  tf.Summary.Value(
                      tag="BLEU_cased" + FLAGS.tag_suffix,
                      simple_value=bleu,
                  )
              )
              tf.logging.info(
                  "%s: BLEU_cased = %6.2f"
                  % (transl_file.filename, bleu)
              )
          writer.add_event(
              tf.summary.Event(
                  summary=tf.Summary(value=values),
                  wall_time=transl_file.mtime,
                  step=transl_file.steps,
              )
          )
          writer.flush()
          with open(last_step_file, "w") as ls_file:
              ls_file.write(str(transl_file.steps) + "\n")
  
file_path: tensor2tensor/tensor2tensor/bin/t2t_bleu.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import time
  from tensor2tensor.utils import bleu_hook
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: main(_) without return types