code: def generate_examples(file_path: str):
      """Provides a common generate_examples method for D4RL datasets."""
      d4rl_dict = read_d4rl_dataset(file_path)
      if "timeouts" not in d4rl_dict:
          raise ValueError(
              "Only datasets with explicit timeouts are supported."
          )
  
      done = [
          terminal or timeout
          for (terminal, timeout) in zip(
              d4rl_dict["terminals"], d4rl_dict["timeouts"]
          )
      ]
      # is_first corresponds to the done flag delayed by one step.
      d4rl_dict["is_first"] = [True] + done[:-1]
      # is_last is not used but this is needed to build a valid dictionary.
      d4rl_dict["is_last"] = done
  
      # Get step metadata
      infos_dict = _get_nested_metadata(d4rl_dict, "infos")
  
      # Flatten reward
      d4rl_dict["rewards"] = np.squeeze(d4rl_dict["rewards"])
  
      episode_metadata = _get_nested_metadata(d4rl_dict, "metadata")
      dataset_dict = {
          "observation": d4rl_dict["observations"],
          "action": d4rl_dict["actions"],
          "reward": d4rl_dict["rewards"],
          "discount": np.ones_like(d4rl_dict["rewards"]),
          "is_terminal": d4rl_dict["terminals"],
          "is_first": d4rl_dict["is_first"],
          "is_last": d4rl_dict["is_last"],
      }
      if "next_observations" in d4rl_dict:
          dataset_dict["next_observation"] = d4rl_dict[
              "next_observations"
          ]
  
      if infos_dict:
          dataset_dict["infos"] = infos_dict
      num_steps = len(dataset_dict["is_first"])
      prev = 0
      counter = 0
      for pos in range(num_steps):
          if dataset_dict["is_first"][pos] and pos > prev:
              yield counter, _get_episode(
                  dataset_dict, episode_metadata, prev, pos
              )
              prev = pos
              counter += 1
      if prev < num_steps:
          yield counter, _get_episode(
              dataset_dict, episode_metadata, prev, num_steps
          )
  
file_path: datasets/tensorflow_datasets/d4rl/dataset_utils.py
imports: from typing import Any, Dict
  import h5py
  import numpy
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
label_desc: Use image node_id 4 for calling a global function with example usage: generate_examples(file_path) without return types