code: def create_batches(x, y, batch_size, map2id, perm=None, sort=False):
      lst = perm or range(len(x))
  
      # sort sequences based on their length; necessary for SST
      if sort:
          lst = sorted(lst, key=lambda i: len(x[i]))
  
      x = [x[i] for i in lst]
      y = [y[i] for i in lst]
  
      sum_len = 0.0
      batches_x = []
      batches_y = []
      size = batch_size
      nbatch = (len(x) - 1) // size + 1
      for i in range(nbatch):
          bx, by = create_one_batch(
              x[i * size : (i + 1) * size],
              y[i * size : (i + 1) * size],
              map2id,
          )
          sum_len += len(bx)
          batches_x.append(bx)
          batches_y.append(by)
  
      if sort:
          perm = list(range(nbatch))
          random.shuffle(perm)
          batches_x = [batches_x[i] for i in perm]
          batches_y = [batches_y[i] for i in perm]
  
      sys.stdout.write(
          "{} batches, avg len: {:.1f}\n".format(
              nbatch, sum_len / nbatch
          )
      )
  
      return batches_x, batches_y
  
imports: import gzip
  import os
  import sys
  import re
  import random
  import numpy
  import torch
label_desc: Use image node_id 13 for calling a global function with example usage: create_batches(x, y, batch_size, map2id, perm, sort) and returns: batches_x,  batches_y