class_docstr: Creates chunks from a sequence
  
  Examples:
      >>> batches = [["id1"], ["id2"], ...]
      >>> batch_size = 128
      >>> chunk_length = 1000
      >>> iter_factory = ChunkIterFactory(dataset, batches, batch_size, chunk_length)
      >>> it = iter_factory.build_iter(epoch)
      >>> for ids, batch in it:
      ...     ...
  
  - The number of mini-batches are varied in each epochs and
    we can't get the number in advance
    because IterFactory doesn't be given to the length information.
  - Since the first reason, "num_iters_per_epoch" can't be implemented
    for this iterator. Instead of it, "num_samples_per_epoch" is implemented.
class_docstr_tok: ["Creates","chunks","from","a","sequence","Examples",":",">",">",">","batches","=","[","[","``","id1","''","]",",","[","``","id2","''","]",",","...","]",">",">",">","batch_size","=","128",">",">",">","chunk_length","=","1000",">",">",">","iter_factory","=","ChunkIterFactory","(","dataset",",","batches",",","batch_size",",","chunk_length",")",">",">",">","it","=","iter_factory.build_iter","(","epoch",")",">",">",">","for","ids",",","batch","in","it",":","...","...","-","The","number","of","mini-batches","are","varied","in","each","epochs","and","we","ca","n't","get","the","number","in","advance","because","IterFactory","does","n't","be","given","to","the","length","information",".","-","Since","the","first","reason",",","``","num_iters_per_epoch","''","ca","n't","be","implemented","for","this","iterator",".","Instead","of","it",",","``","num_samples_per_epoch","''","is","implemented","."]
code: def _generate_mini_batches(
      self,
      id_list: List[str],
      batches: Dict[str, List[torch.Tensor]],
      shuffle: bool,
      state: np.random.RandomState,
  ):
      if shuffle:
          indices = np.arange(0, len(id_list))
          state.shuffle(indices)
          batches = {
              k: [v[i] for i in indices] for k, v in batches.items()
          }
          id_list = [id_list[i] for i in indices]
  
      bs = self.batch_size
      while len(id_list) >= bs:
          # Make mini-batch and yield
          yield (
              id_list[:bs],
              {k: torch.stack(v[:bs], 0) for k, v in batches.items()},
          )
          id_list = id_list[bs:]
          batches = {k: v[bs:] for k, v in batches.items()}
  
      return id_list, batches
  
file_path: espnet/espnet2/iterators/chunk_iter_factory.py
imports: import logging
  import re
  from collections import defaultdict
  from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  from typeguard import check_argument_types
  from espnet2.iterators.abs_iter_factory import AbsIterFactory
  from espnet2.iterators.sequence_iter_factory import SequenceIterFactory
  from espnet2.samplers.abs_sampler import AbsSampler
label_desc: Use image node_id 3 for calling the ChunkIterFactory obj's underlying member method code with example usage: obj._generate_mini_batches(id_list, batches, shuffle, state) and returns: id_list,  batches