class_docstr: Dataset iterator to create a batch of sentences.
  
  This iterator returns a pair of sentences, where one token is shifted
  between the sentences like '<sos> w1 w2 w3' and 'w1 w2 w3 <eos>'
  Sentence batches are made in order of longer sentences, and then
  randomly shuffled.
class_docstr_tok: ["Dataset","iterator","to","create","a","batch","of","sentences",".","This","iterator","returns","a","pair","of","sentences",",","where","one","token","is","shifted","between","the","sentences","like","'","<","sos",">","w1","w2","w3","'","and","'w1","w2","w3","<","eos",">","'","Sentence","batches","are","made","in","order","of","longer","sentences",",","and","then","randomly","shuffled","."]
code: def __init__(
      self,
      dataset,
      batch_size,
      max_length=0,
      sos=0,
      eos=0,
      repeat=True,
      shuffle=True,
  ):
      self.dataset = dataset
      self.batch_size = batch_size  # batch size
      # Number of completed sweeps over the dataset. In this case, it is
      # incremented if every word is visited at least once after the last
      # increment.
      self.epoch = 0
      # True if the epoch is incremented at the last iteration.
      self.is_new_epoch = False
      self.repeat = repeat
      length = len(dataset)
      self.batch_indices = []
      # make mini-batches
      if batch_size > 1:
          indices = sorted(
              range(len(dataset)), key=lambda i: -len(dataset[i])
          )
          bs = 0
          while bs < length:
              be = min(bs + batch_size, length)
              # batch size is automatically reduced if the sentence length
              # is larger than max_length
              if max_length > 0:
                  sent_length = len(dataset[indices[bs]])
                  be = min(
                      be,
                      bs
                      + max(
                          batch_size // (sent_length // max_length + 1),
                          1,
                      ),
                  )
              self.batch_indices.append(np.array(indices[bs:be]))
              bs = be
          if shuffle:
              # shuffle batches
              random.shuffle(self.batch_indices)
      else:
          self.batch_indices = [np.array([i]) for i in range(length)]
  
      # NOTE: this is not a count of parameter updates. It is just a count of
      # calls of ``__next__``.
      self.iteration = 0
      self.sos = sos
      self.eos = eos
      # use -1 instead of None internally
      self._previous_epoch_detail = -1.0
  
imports: import logging
  import os
  import random
  import chainer
  import h5py
  import numpy
  from chainer.training import extension
  from tqdm import tqdm
label_desc: Use image node_id 1 to create a new ParallelSentenceIterator object from inherited base classes: chainer.dataset with example: obj = ParallelSentenceIterator(dataset, batch_size, max_length, sos, eos, repeat, shuffle)