code: def batchfy_shuffle(
      data, batch_size, min_batch_size, num_batches, shortest_first
  ):
      import random
  
      logging.info("use shuffled batch.")
      sorted_data = random.sample(data.items(), len(data.items()))
      logging.info("# utts: " + str(len(sorted_data)))
      # make list of minibatches
      minibatches = []
      start = 0
      while True:
          end = min(len(sorted_data), start + batch_size)
          # check each batch is more than minimum batchsize
          minibatch = sorted_data[start:end]
          if shortest_first:
              minibatch.reverse()
          if len(minibatch) < min_batch_size:
              mod = min_batch_size - len(minibatch) % min_batch_size
              additional_minibatch = [
                  sorted_data[i]
                  for i in np.random.randint(0, start, mod)
              ]
              if shortest_first:
                  additional_minibatch.reverse()
              minibatch.extend(additional_minibatch)
          minibatches.append(minibatch)
          if end == len(sorted_data):
              break
          start = end
  
      # for debugging
      if num_batches > 0:
          minibatches = minibatches[:num_batches]
          logging.info("# minibatches: " + str(len(minibatches)))
      return minibatches
  
imports: import itertools
  import logging
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: batchfy_shuffle(data, batch_size, min_batch_size, num_batches, shortest_first) and returns: minibatches