code: def dataset_generator(filepath,
                        dataset,
                        chunk_size=1,
                        start_idx=None,
                        end_idx=None):
    
    encoder = dna_encoder.DNAEncoder(chunk_size=chunk_size)
    with h5py.File(filepath, "r") as h5_file:
      # Get input keys from h5_file
      src_keys = [s % dataset for s in ["%s_in", "%s_na", "%s_out"]]
      src_values = [h5_file[k] for k in src_keys]
      inp_data, mask_data, out_data = src_values
      assert len(set([v.len() for v in src_values])) == 1
  
      if start_idx is None:
        start_idx = 0
      if end_idx is None:
        end_idx = inp_data.len()
  
      for i in range(start_idx, end_idx):
        if i % 100 == 0:
          print("Generating example %d for %s" % (i, dataset))
        inputs, mask, outputs = inp_data[i], mask_data[i], out_data[i]
        ex_dict = to_example_dict(encoder, inputs, mask, outputs)
        # Original data has one output for every 128 input bases. Ensure that the
        # ratio has been maintained given the chunk size and removing EOS.
        assert (len(ex_dict["inputs"]) - 1) == ((
            128 // chunk_size) * ex_dict["targets_shape"][0])
        yield ex_dict
docs: Generate example dicts.