class_docstr: Pytorch Dataset class for ESPNet.
  
  Examples:
      >>> dataset = IterableESPnetDataset([('wav.scp', 'input', 'sound'),
      ...                                  ('token_int', 'output', 'text_int')],
      ...                                )
      >>> for uid, data in dataset:
      ...     data
      {'input': per_utt_array, 'output': per_utt_array}
class_docstr_tok: ["Pytorch","Dataset","class","for","ESPNet",".","Examples",":",">",">",">","dataset","=","IterableESPnetDataset","(","[","(","'wav.scp","'",",","'input","'",",","'sound","'",")",",","...","(","'token_int","'",",","'output","'",",","'text_int","'",")","]",",","...",")",">",">",">","for","uid",",","data","in","dataset",":","...","data","{","'input","'",":","per_utt_array",",","'output","'",":","per_utt_array","}"]
code: def __iter__(
      self,
  ) -> Iterator[Tuple[Union[str, int], Dict[str, np.ndarray]]]:
      if self.key_file is not None:
          uid_iter = (
              line.rstrip().split(maxsplit=1)[0]
              for line in open(self.key_file, encoding="utf-8")
          )
      elif len(self.path_name_type_list) != 0:
          uid_iter = (
              line.rstrip().split(maxsplit=1)[0]
              for line in open(
                  self.path_name_type_list[0][0], encoding="utf-8"
              )
          )
      else:
          uid_iter = iter(self.non_iterable_dataset)
  
      files = [
          open(lis[0], encoding="utf-8")
          for lis in self.path_name_type_list
      ]
  
      worker_info = torch.utils.data.get_worker_info()
  
      linenum = 0
      count = 0
      for count, uid in enumerate(uid_iter, 1):
          # If num_workers>=1, split keys
          if worker_info is not None:
              if (
                  count - 1
              ) % worker_info.num_workers != worker_info.id:
                  continue
  
          # 1. Read a line from each file
          while True:
              keys = []
              values = []
              for f in files:
                  linenum += 1
                  try:
                      line = next(f)
                  except StopIteration:
                      raise RuntimeError(
                          f"{uid} is not found in the files"
                      )
                  sps = line.rstrip().split(maxsplit=1)
                  if len(sps) != 2:
                      raise RuntimeError(
                          f"This line doesn't include a space:"
                          f" {f}:L{linenum}: {line})"
                      )
                  key, value = sps
                  keys.append(key)
                  values.append(value)
  
              for k_idx, k in enumerate(keys):
                  if k != keys[0]:
                      raise RuntimeError(
                          f"Keys are mismatched. Text files (idx={k_idx}) is "
                          f"not sorted or not having same keys at L{linenum}"
                      )
  
              # If the key is matched, break the loop
              if len(keys) == 0 or keys[0] == uid:
                  break
  
          # 2. Load the entry from each line and create a dict
          data = {}
          # 2.a. Load data streamingly
          for value, (path, name, _type) in zip(
              values, self.path_name_type_list
          ):
              func = DATA_TYPES[_type]
              # Load entry
              array = func(value)
              data[name] = array
          if self.non_iterable_dataset is not None:
              # 2.b. Load data from non-iterable dataset
              _, from_non_iterable = self.non_iterable_dataset[uid]
              data.update(from_non_iterable)
  
          # 3. [Option] Apply preprocessing
          #   e.g. espnet2.train.preprocessor:CommonPreprocessor
          if self.preprocess is not None:
              data = self.preprocess(uid, data)
  
          # 4. Force data-precision
          for name in data:
              value = data[name]
              if not isinstance(value, np.ndarray):
                  raise RuntimeError(
                      f"All values must be converted to np.ndarray object "
                      f'by preprocessing, but "{name}" is still {type(value)}.'
                  )
  
              # Cast to desired type
              if value.dtype.kind == "f":
                  value = value.astype(self.float_dtype)
              elif value.dtype.kind == "i":
                  value = value.astype(self.int_dtype)
              else:
                  raise NotImplementedError(
                      f"Not supported dtype: {value.dtype}"
                  )
              data[name] = value
  
          yield uid, data
  
      if count == 0:
          raise RuntimeError("No iteration")
  
file_path: espnet/espnet2/train/iterable_dataset.py
imports: import copy
  from io import StringIO
  from pathlib import Path
  from typing import Callable, Collection, Dict, Iterator, Tuple, Union
  import kaldiio
  import numpy
  import soundfile
  import torch
  from torch.utils.data.dataset import IterableDataset
  from typeguard import check_argument_types
  from espnet2.train.dataset import ESPnetDataset
label_desc: Use image node_id 5 for calling the IterableESPnetDataset obj's underlying member method code with example usage: obj.__iter__() without return types