docstr: Takes two lists of source and target sentences, sorts them, and packs
  into batches to minimize the use of padding tokens. Returns a list of
  batches where each batch contains indices of sentences included into it
docstr_tok: ["Takes","two","lists","of","source","and","target","sentences",",","sorts","them",",","and","packs","into","batches","to","minimize","the","use","of","padding","tokens",".","Returns","a","list","of","batches","where","each","batch","contains","indices","of","sentences","included","into","it"]
code: def pack_data_into_batches(self, ids):
      """
      Takes two lists of source and target sentences, sorts them, and packs
      into batches to minimize the use of padding tokens. Returns a list of
      batches where each batch contains indices of sentences included into it
      """
  
      # create buckets sorted by the number of src tokens
      # each bucket is also sorted by the number of tgt tokens
      buckets = {}
      for i, line_ids in enumerate(ids):
          len_ = len(line_ids)
          if len_ not in buckets:
              buckets[len_] = [i]
          else:
              buckets[len_].append(i)
  
      for b_idx in buckets:
          buckets[b_idx] = sorted(buckets[b_idx])
  
      buckets = OrderedDict(sorted(buckets.items()))
  
      batches = []
      batch_elem_lengths = []
      curr_batch = []
      len_of_longest_sent = 0
      for sent_len, bucket in buckets.items():
          for sent_i in bucket:
              if (
                  sent_len * (len(curr_batch) + 1)
                  > self.tokens_in_batch
              ):
                  if not curr_batch:
                      raise ValueError(
                          f"The limitation on number of tokens in batch {self.tokens_in_batch} is too strong."
                          f"Several sentences contain {sent_len} tokens."
                      )
                  batches.append(curr_batch)
                  batch_elem_lengths.append(sent_len)
                  curr_batch = []
              curr_batch.append(sent_i)
          len_of_longest_sent = sent_len
      if curr_batch:
          batches.append(curr_batch)
          batch_elem_lengths.append(len_of_longest_sent)
      return batches, batch_elem_lengths
  
imports: import io
  import json
  import logging
  import pickle
  from collections import OrderedDict
  from typing import Any
  import braceexpand
  import numpy
  import webdataset
  from torch.utils.data import IterableDataset
  from nemo.collections.nlp.data.data_utils.data_preprocessing import dataset_to_ids
  from nemo.core import Dataset
label_desc: Use image node_id 5 for calling the SentenceDataset obj's underlying member method code with example usage: obj.pack_data_into_batches(ids) and returns: batches,  batch_elem_lengths