class_docstr: An iterator which by default, pads batches with respect to the maximum input lengths `per
  batch`. Additionally, you can provide a list of field names and padding keys which the dataset
  will be sorted by before doing this batching, causing inputs with similar length to be batched
  together, making computation more efficient (as less time is wasted on padded elements of the
  batch).
  
  Parameters
  ----------
  sorting_keys : List[Tuple[str, str]]
      To bucket inputs into batches, we want to group the instances by padding length, so that we
      minimize the amount of padding necessary per batch. In order to do this, we need to know
      which fields need what type of padding, and in what order.
  
      For example, ``[("sentence1", "num_tokens"), ("sentence2", "num_tokens"), ("sentence1",
      "num_token_characters")]`` would sort a dataset first by the "num_tokens" of the
      "sentence1" field, then by the "num_tokens" of the "sentence2" field, and finally by the
      "num_token_characters" of the "sentence1" field.  TODO(mattg): we should have some
      documentation somewhere that gives the standard padding keys used by different fields.
  padding_noise : float, optional (default=.1)
      When sorting by padding length, we add a bit of noise to the lengths, so that the sorting
      isn't deterministic.  This parameter determines how much noise we add, as a percentage of
      the actual padding value for each instance.
  biggest_batch_first : bool, optional (default=False)
      This is largely for testing, to see how large of a batch you can safely use with your GPU.
      This will let you try out the largest batch that you have in the data `first`, so that if
      you're going to run out of memory, you know it early, instead of waiting through the whole
      epoch to find out at the end that you're going to crash.
  
      Note that if you specify ``max_instances_in_memory``, the first batch will only be the
      biggest from among the first "max instances in memory" instances.
  batch_size : int, optional, (default = 32)
      The size of each batch of instances yielded when calling the iterator.
  instances_per_epoch : int, optional, (default = None)
      See :class:`BasicIterator`.
  max_instances_in_memory : int, optional, (default = None)
      See :class:`BasicIterator`.
  maximum_samples_per_batch : ``Tuple[str, int]``, (default = None)
      See :class:`BasicIterator`.
code: def __init__(
      self,
      sorting_keys,
      padding_noise=0.1,
      biggest_batch_first=False,
      batch_size=32,
      instances_per_epoch=None,
      max_instances_in_memory=None,
      cache_instances=False,
      track_epoch=False,
      maximum_samples_per_batch=None,
  ):
      if not sorting_keys:
          raise ConfigurationError(
              "BucketIterator requires sorting_keys to be specified"
          )
  
      super(BucketIterator, self).__init__(
          cache_instances=cache_instances,
          track_epoch=track_epoch,
          batch_size=batch_size,
          instances_per_epoch=instances_per_epoch,
          max_instances_in_memory=max_instances_in_memory,
          maximum_samples_per_batch=maximum_samples_per_batch,
      )
      self._sorting_keys = sorting_keys
      self._padding_noise = padding_noise
      self._biggest_batch_first = biggest_batch_first
  
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 to create a new BucketIterator object from inherited base classes: DataIterator with example: obj = BucketIterator(sorting_keys, padding_noise, biggest_batch_first, batch_size, instances_per_epoch, max_instances_in_memory, cache_instances, track_epoch, maximum_samples_per_batch)