docstr: Sort instances based on text length in ascending order
docstr_tok: ["Sort","instances","based","on","text","length","in","ascending","order"]
code: def sort_items(self):
      r"""Sort instances based on text length in ascending order"""
      lengths = np.array([len(ins[0]) for ins in self.items])
  
      idxs = np.argsort(lengths)
      new_items = []
      ignored = []
      for i, idx in enumerate(idxs):
          length = lengths[idx]
          if length < self.min_seq_len or length > self.max_seq_len:
              ignored.append(idx)
          else:
              new_items.append(self.items[idx])
      # shuffle batch groups
      if self.batch_group_size > 0:
          for i in range(len(new_items) // self.batch_group_size):
              offset = i * self.batch_group_size
              end_offset = offset + self.batch_group_size
              temp_items = new_items[offset:end_offset]
              random.shuffle(temp_items)
              new_items[offset:end_offset] = temp_items
      self.items = new_items
  
      if self.verbose:
          print(" | > Max length sequence: {}".format(np.max(lengths)))
          print(" | > Min length sequence: {}".format(np.min(lengths)))
          print(" | > Avg length sequence: {}".format(np.mean(lengths)))
          print(
              " | > Num. instances discarded by max-min (max={}, min={}) seq limits: {}".format(
                  self.max_seq_len, self.min_seq_len, len(ignored)
              )
          )
          print(
              " | > Batch group size: {}.".format(self.batch_group_size)
          )
  
imports: import collections
  import os
  import random
  from multiprocessing import Manager, Pool
  import numpy
  import torch
  import tqdm
  from torch.utils.data import Dataset
  from TTS.tts.utils.data import prepare_data, prepare_stop_target, prepare_tensor
  from TTS.tts.utils.text import pad_with_eos_bos, phoneme_to_sequence, text_to_sequence
label_desc: Use image node_id 9 for calling the MyDataset obj's underlying member method code with example usage: obj.sort_items() without return types