code: def sort_by_padding(
      instances,
      sorting_keys,  # pylint: disable=invalid-sequence-index
      vocab,
      padding_noise=0.0,
  ):
      """
      Sorts the instances by their padding lengths, using the keys in
      ``sorting_keys`` (in the order in which they are provided).  ``sorting_keys`` is a list of
      ``(field_name, padding_key)`` tuples.
      """
      instances_with_lengths = []
      for instance in instances:
          # Make sure instance is indexed before calling .get_padding
          instance.index_fields(vocab)
          padding_lengths = cast(
              Dict[unicode, Dict[unicode, float]],
              instance.get_padding_lengths(),
          )
          if padding_noise > 0.0:
              noisy_lengths = {}
              for field_name, field_lengths in list(
                  padding_lengths.items()
              ):
                  noisy_lengths[field_name] = add_noise_to_dict_values(
                      field_lengths, padding_noise
                  )
              padding_lengths = noisy_lengths
          instance_with_lengths = (
              [
                  padding_lengths[field_name][padding_key]
                  for (field_name, padding_key) in sorting_keys
              ],
              instance,
          )
          instances_with_lengths.append(instance_with_lengths)
      instances_with_lengths.sort(key=lambda x: x[0])
      return [
          instance_with_lengths[-1]
          for instance_with_lengths in instances_with_lengths
      ]
  
file_path: magnitude/pymagnitude/third_party/allennlp/data/iterators/bucket_iterator.py
imports: from __future__ import absolute_import
  import logging
  import random
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.util import lazy_groups_of, add_noise_to_dict_values
  from allennlp.data.dataset import Batch
  from allennlp.data.instance import Instance
  from allennlp.data.iterators.data_iterator import DataIterator
  from allennlp.data.vocabulary import Vocabulary
label_desc: Use image node_id 1 for calling a global function with example usage: sort_by_padding(instances, sorting_keys, vocab, padding_noise) and returns: unknown