code: def get_batches(qp_pairs, batch_size, need_sort=True):
      '''
      Get batches data and shuffle.
      '''
      if need_sort:
          qp_pairs = sorted(qp_pairs, key=lambda qp: (
              len(qp['passage_tokens']), qp['id']), reverse=True)
      batches = [{'qp_pairs': qp_pairs[i:(i + batch_size)]}
                 for i in range(0, len(qp_pairs), batch_size)]
      shuffle(batches)
      return batchef get_batches(qp_pairs, batch_size, need_sort=True):
      '''
      Get batches data and shuffle.
      '''
      if need_sort:
          qp_pairs = sorted(qp_pairs, key=lambda qp: (
              len(qp['passage_tokens']), qp['id']), reverse=True)
      batches = [{'qp_pairs': qp_pairs[i:(i + batch_size)]}
                 for i in range(0, len(qp_pairs), batch_size)]
      shuffle(batches)
      return batches
docs: Get batches data and shuffle.