def supervised_to_dict(dataset, text2self):
  """Turns a supervised dataset into a dataset with a feature dictionary.

  if text2self, then the features dictionary contains a "targets" key.
  else, the features dictionary contains "inputs" and "targets" keys.

  Args:
    dataset: a tf.data.Dataset
    text2self: a boolean
  Returns:
    a tf.data.Dataset
  """
  def my_fn(inputs, targets):
    if text2self:
      return {"targets": targets}
    else:
      return {"inputs": inputs, "targets": targets}
  return dataset.map(my_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE)
Turns a supervised dataset into a dataset with a feature dictionary.

  if text2self, then the features dictionary contains a "targets" key.
  else, the features dictionary contains "inputs" and "targets" keys.

  Args:
    dataset: a tf.data.Dataset
    text2self: a boolean
  Returns:
    a tf.data.Dataset