code: def sort_dataset_by_len(dataset, keep_index=False):
      """
      returns a dict mapping length -> list of items of that length
  
      an OrderedDict is used so that the mapping is sorted from smallest to largest
      """
      sorted_dataset = collections.OrderedDict()
      lengths = sorted(list(set(len(x.text) for x in dataset)))
      for l in lengths:
          sorted_dataset[l] = []
      for item_idx, item in enumerate(dataset):
          if keep_index:
              sorted_dataset[len(item.text)].append((item, item_idx))
          else:
              sorted_dataset[len(item.text)].append(item)
      return sorted_dataset
  
imports: import collections
  from collections import namedtuple
  import logging
  import json
  import random
  import re
  from typing import List
  from stanza.models.classifiers.utils import WVType
  from stanza.models.common.vocab import PAD, PAD_ID, UNK, UNK_ID
  import stanza.models.constituency.tree_reader
label_desc: Use image node_id 5 for calling a global function with example usage: sort_dataset_by_len(dataset, keep_index) and returns: sorted_dataset