def _decode_batch_input_fn(num_decode_batches, sorted_inputs, vocabulary,
                           batch_size, max_input_size, task_id=-1):
  """Generator to produce batches of inputs."""
  tf.logging.info(" batch %d" % num_decode_batches)
  # First reverse all the input sentences so that if you're going to get OOMs,
  # you'll see it in the first batch
  sorted_inputs.reverse()
  for b in range(num_decode_batches):
    tf.logging.info("Decoding batch %d" % b)
    batch_length = 0
    batch_target_tags = []
    batch_inputs = []
    for inputs in sorted_inputs[b * batch_size:(b + 1) * batch_size]:
      target_tag = inputs[:translate_multilingual.LANG_TAG_LENGTH]
      target_tag_id = translate_multilingual.get_tag_id(target_tag)
      batch_target_tags.append([target_tag_id])
      # Add +1 to drop the space character right after the tag.
      input_seq = inputs[(translate_multilingual.LANG_TAG_LENGTH + 1):]
      input_ids = vocabulary.encode(input_seq)
      if max_input_size > 0:
        # Subtract 1 for the EOS_ID.
        input_ids = input_ids[:max_input_size - 1]
      final_id = text_encoder.EOS_ID if task_id < 0 else task_id
      input_ids.append(final_id)
      batch_inputs.append(input_ids)
      if len(input_ids) > batch_length:
        batch_length = len(input_ids)
    final_batch_inputs = []
    for input_ids in batch_inputs:
      assert len(input_ids) <= batch_length
      x = input_ids + [0] * (batch_length - len(input_ids))
      final_batch_inputs.append(x)

    yield {
        "inputs": np.array(final_batch_inputs).astype(np.int32),
        "target_tags": np.array(batch_target_tags).astype(np.int32),
    }
Generator to produce batches of inputs.
language/labs/consistent_zero_shot_nmt/utils/t2t_tweaks.py