code: def _decode_inference_indices(
      model,
      sess,
      output_infer,
      output_infer_summary_prefix,
      inference_indices,
      tgt_eos,
      subword_option,
  ):
      """Decoding only a specific set of sentences."""
      utils.print_out(
          "  decoding to output %s , num sents %d."
          % (output_infer, len(inference_indices))
      )
      start_time = time.time()
      with codecs.getwriter("utf-8")(
          tf.gfile.GFile(output_infer, mode="wb")
      ) as trans_f:
          trans_f.write(
              ""
          )  # Write empty string to ensure file is created.
          for decode_id in inference_indices:
              nmt_outputs, infer_summary = model.decode(sess)
  
              # get text translation
              assert nmt_outputs.shape[0] == 1
              translation = nmt_utils.get_translation(
                  nmt_outputs,
                  sent_id=0,
                  tgt_eos=tgt_eos,
                  subword_option=subword_option,
              )
  
              if infer_summary is not None:  # Attention models
                  image_file = (
                      output_infer_summary_prefix
                      + str(decode_id)
                      + ".png"
                  )
                  utils.print_out(
                      "  save attention image to %s*" % image_file
                  )
                  image_summ = tf.Summary()
                  image_summ.ParseFromString(infer_summary)
                  with tf.gfile.GFile(image_file, mode="w") as img_f:
                      # pylint: disable=no-member
                      img_f.write(
                          image_summ.value[0].image.encoded_image_string
                      )
  
              trans_f.write("%s\n" % translation)
              utils.print_out(translation + b"\n")
      utils.print_time("  done", start_time)
  
file_path: nlp-architect/examples/sparse_gnmt/inference.py
imports: from __future__ import print_function
  import codecs
  import os
  import time
  import tensorflow
  from .None import gnmt_model
  from .gnmt import attention_model, model
  from .gnmt import model_helper
  from .gnmt.utils import nmt_utils, misc_utils
label_desc: Use image node_id 1 for calling a global function with example usage: _decode_inference_indices(model, sess, output_infer, output_infer_summary_prefix, inference_indices, tgt_eos, subword_option) without return types