code: def get_infer_iterator(
      src_dataset,
      src_vocab_table,
      batch_size,
      eos,
      src_max_len=None,
      use_char_encode=False,
  ):
      if use_char_encode:
          src_eos_id = vocab_utils.EOS_CHAR_ID
      else:
          src_eos_id = tf.cast(
              src_vocab_table.lookup(tf.constant(eos)), tf.int32
          )
      src_dataset = src_dataset.map(
          lambda src: tf.string_split([src]).values
      )
  
      if src_max_len:
          src_dataset = src_dataset.map(lambda src: src[:src_max_len])
  
      if use_char_encode:
          # Convert the word strings to character ids
          src_dataset = src_dataset.map(
              lambda src: tf.reshape(
                  vocab_utils.tokens_to_bytes(src), [-1]
              )
          )
      else:
          # Convert the word strings to ids
          src_dataset = src_dataset.map(
              lambda src: tf.cast(src_vocab_table.lookup(src), tf.int32)
          )
  
      # Add in the word counts.
      if use_char_encode:
          src_dataset = src_dataset.map(
              lambda src: (
                  src,
                  tf.to_int32(
                      tf.size(src) / vocab_utils.DEFAULT_CHAR_MAXLEN
                  ),
              )
          )
      else:
          src_dataset = src_dataset.map(lambda src: (src, tf.size(src)))
  
      def batching_func(x):
          return x.padded_batch(
              batch_size,
              # The entry is the source line rows;
              # this has unknown-length vectors.  The last entry is
              # the source row size; this is a scalar.
              padded_shapes=(
                  tf.TensorShape([None]),
                  tf.TensorShape([]),
              ),  # src  # src_len
              # Pad the source sequences with eos tokens.
              # (Though notice we don't generally need to do this since
              # later on we will be masking out calculations past the true sequence.
              padding_values=(src_eos_id, 0),  # src
          )  # src_len -- unused
  
      batched_dataset = batching_func(src_dataset)
      batched_iter = batched_dataset.make_initializable_iterator()
      (src_ids, src_seq_len) = batched_iter.get_next()
      return BatchedInput(
          initializer=batched_iter.initializer,
          source=src_ids,
          target_input=None,
          target_output=None,
          source_sequence_length=src_seq_len,
          target_sequence_length=None,
      )
  
file_path: nlp-architect/examples/sparse_gnmt/gnmt/utils/iterator_utils.py
imports: from __future__ import print_function
  import collections
  import tensorflow
  from .None import vocab_utils
label_desc: Use image node_id 1 for calling a global function with example usage: get_infer_iterator(src_dataset, src_vocab_table, batch_size, eos, src_max_len, use_char_encode) and returns: BatchedInput, x