code: def decode_interactively(
      estimator, hparams, decode_hp, checkpoint_path=None
  ):
      """Interactive decoding."""
  
      is_image = "image" in hparams.problem.name
      is_text2class = isinstance(
          hparams.problem, text_problems.Text2ClassProblem
      )
      skip_eos_postprocess = (
          is_image or is_text2class or decode_hp.skip_eos_postprocess
      )
  
      def input_fn():
          gen_fn = make_input_fn_from_generator(
              _interactive_input_fn(hparams, decode_hp)
          )
          example = gen_fn()
          example = _interactive_input_tensor_to_features_dict(
              example, hparams
          )
          return example
  
      result_iter = estimator.predict(
          input_fn, checkpoint_path=checkpoint_path
      )
      for result in result_iter:
          targets_vocab = hparams.problem_hparams.vocabulary["targets"]
  
          if decode_hp.return_beams:
              beams = np.split(
                  result["outputs"], decode_hp.beam_size, axis=0
              )
              scores = None
              if "scores" in result:
                  if np.isscalar(result["scores"]):
                      result["scores"] = result["scores"].reshape(1)
                  scores = np.split(
                      result["scores"], decode_hp.beam_size, axis=0
                  )
              for k, beam in enumerate(beams):
                  tf.logging.info("BEAM %d:" % k)
                  beam_string = targets_vocab.decode(
                      _save_until_eos(beam, skip_eos_postprocess)
                  )
                  if scores is not None:
                      tf.logging.info(
                          '"%s"\tScore:%f' % (beam_string, scores[k])
                      )
                  else:
                      tf.logging.info('"%s"' % beam_string)
          else:
              if decode_hp.identity_output:
                  tf.logging.info(
                      " ".join(map(str, result["outputs"].flatten()))
                  )
              else:
                  tf.logging.info(
                      targets_vocab.decode(
                          _save_until_eos(
                              result["outputs"], skip_eos_postprocess
                          )
                      )
                  )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import operator
  import os
  import re
  import string
  import time
  import numpy
  import six
  from six.moves import input
  from tensor2tensor.data_generators import problem
  from tensor2tensor.data_generators import text_encoder
  from tensor2tensor.data_generators import text_problems
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import hparam
  from tensor2tensor.utils import mlperf_log
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 9 for calling a global function with example usage: decode_interactively(estimator, hparams, decode_hp, checkpoint_path) and returns: example