code: def to_example_dict(encoder, inputs, mask, outputs):
      """Convert single h5 record to an example dict."""
      # Inputs
      bases = []
      input_ids = []
      last_idx = -1
      for row in np.argwhere(inputs):
          idx, base_id = row
          idx, base_id = int(idx), int(base_id)
          assert idx > last_idx  # if not, means 2 True values in 1 row
          # Some rows are all False. Those rows are mapped to UNK_ID.
          while idx != last_idx + 1:
              bases.append(encoder.UNK)
              last_idx += 1
          bases.append(encoder.BASES[base_id])
          last_idx = idx
      assert len(inputs) == len(bases)
  
      input_ids = encoder.encode(bases)
      input_ids.append(text_encoder.EOS_ID)
  
      # Targets: mask and output
      targets_mask = [float(v) for v in mask]
      # The output is (n, m); store targets_shape so that it can be reshaped
      # properly on the other end.
      targets = [float(v) for v in outputs.flatten()]
      targets_shape = [int(dim) for dim in outputs.shape]
      assert mask.shape[0] == outputs.shape[0]
  
      example_keys = [
          "inputs",
          "targets_mask",
          "targets",
          "targets_shape",
      ]
      ex_dict = dict(
          zip(
              example_keys,
              [input_ids, targets_mask, targets, targets_shape],
          )
      )
      return ex_dict
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import multiprocessing
  import os
  import h5py
  import numpy
  from six.moves import range
  from tensor2tensor.data_generators import dna_encoder
  from tensor2tensor.data_generators import generator_utils
  from tensor2tensor.data_generators import problem
  from tensor2tensor.data_generators import text_encoder
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import metrics
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling a global function with example usage: to_example_dict(encoder, inputs, mask, outputs) and returns: ex_dict