class_docstr: An abstract ``DataIterator`` class. ``DataIterators`` must override ``_create_batches()``.
  
  Parameters
  ----------
  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)
      If specified, each epoch will consist of precisely this many instances.
      If not specified, each epoch will consist of a single pass through the dataset.
  max_instances_in_memory : ``int``, optional, (default = None)
      If specified, the iterator will load this many instances at a time into an
      in-memory list and then produce batches from one such list at a time. This
      could be useful if your instances are read lazily from disk.
  cache_instances : ``bool``, optional, (default = False)
      If true, the iterator will cache the tensorized instances in memory.
      If false, it will do the tensorization anew each iteration.
  track_epoch : ``bool``, optional, (default = False)
      If true, each instance will get a ``MetadataField`` containing the epoch number.
  maximum_samples_per_batch : ``Tuple[str, int]``, (default = None)
      If specified, then is a tuple (padding_key, limit) and we will
      shrink the batch size for very long sequences such that
      batch_size * sequence_length <= limit where sequence_length is given
      by the padding_key.
docstr: Take the next `max_instances` instances from the given dataset.
  If `max_instances` is `None`, then just take all instances from the dataset.
  If `max_instances` is not `None`, each call resumes where the previous one
  left off, and when you get to the end of the dataset you start again from the beginning.
docstr_tok: ["Take","the","next","`","max_instances","`","instances","from","the","given","dataset",".","If","`","max_instances","`","is","`","None","`",",","then","just","take","all","instances","from","the","dataset",".","If","`","max_instances","`","is","not","`","None","`",",","each","call","resumes","where","the","previous","one","left","off",",","and","when","you","get","to","the","end","of","the","dataset","you","start","again","from","the","beginning","."]
code: def _take_instances(self, instances, max_instances=None):
      """
      Take the next `max_instances` instances from the given dataset.
      If `max_instances` is `None`, then just take all instances from the dataset.
      If `max_instances` is not `None`, each call resumes where the previous one
      left off, and when you get to the end of the dataset you start again from the beginning.
      """
      # If max_instances isn't specified, just iterate once over the whole dataset
      if max_instances is None:
          _i = iter(instances)
          while True:
              yield _i.next()
      else:
          # If we don't have a cursor for this dataset, create one. We use ``id()``
          # for the key because ``instances`` could be a list, which can't be used as a key.
          key = id(instances)
          iterator = self._cursors.get(key, iter(instances))
  
          while max_instances > 0:
              try:
                  # If there are instances left on this iterator,
                  # yield one and decrement max_instances.
                  yield next(iterator)
                  max_instances -= 1
              except StopIteration:
                  # None left, so start over again at the beginning of the dataset.
                  iterator = iter(instances)
  
          # We may have a new iterator, so update the cursor.
          self._cursors[key] = iterator
  
imports: from __future__ import division
  from __future__ import absolute_import
  import logging
  from collections import defaultdict
  import itertools
  import math
  import random
  import torch
  from allennlp.common.registrable import Registrable
  from allennlp.common.util import is_lazy, lazy_groups_of, ensure_list
  from allennlp.data.dataset import Batch
  from allennlp.data.fields import MetadataField
  from allennlp.data.instance import Instance
  from allennlp.data.vocabulary import Vocabulary
label_desc: Use image node_id 3 for calling the DataIterator obj's underlying member method code with example usage: obj._take_instances(instances, max_instances) without return types