code: def data_iter(data, batch_size, shuffle=True):
      """
      randomly permute data, then sort by source length, and partition into batches
      ensure that the length of source sentences in each batch is decreasing
      """
  
      buckets = defaultdict(list)
      for pair in data:
          src_sent = pair[0]
          buckets[len(src_sent)].append(pair)
  
      batched_data = []
      for src_len in buckets:
          tuples = buckets[src_len]
          if shuffle:
              np.random.shuffle(tuples)
          batched_data.extend(list(batch_slice(tuples, batch_size)))
  
      if shuffle:
          np.random.shuffle(batched_data)
      for batch in batched_data:
          yield batch
  
imports: from collections import defaultdict
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: data_iter(data, batch_size, shuffle) without return types