code: def batch_slice(data, batch_size, sort=True):
      batch_num = int(np.ceil(len(data) / float(batch_size)))
      for i in range(batch_num):
          cur_batch_size = (
              batch_size
              if i < batch_num - 1
              else len(data) - batch_size * i
          )
          src_sents = [
              data[i * batch_size + b][0] for b in range(cur_batch_size)
          ]
          tgt_sents = [
              data[i * batch_size + b][1] for b in range(cur_batch_size)
          ]
  
          if sort:
              src_ids = sorted(
                  range(cur_batch_size),
                  key=lambda src_id: len(src_sents[src_id]),
                  reverse=True,
              )
              src_sents = [src_sents[src_id] for src_id in src_ids]
              tgt_sents = [tgt_sents[src_id] for src_id in src_ids]
  
          yield src_sents, tgt_sents
  
imports: from collections import defaultdict
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: batch_slice(data, batch_size, sort) without return types