def build_feature_dict_mapper(feature_names):
  """Build a function for tf.data.Dataset.map.

  Args:
    feature_names: List of feature names.

  Returns:
    A function converting tuples into (dictionary of features, label).
  """

  def mapper(*tuple_args):
    d = {}
    for i in range(len(feature_names)):
      d[feature_names[i]] = tuple_args[i]
    return d, tuple_args[-1]

  return mapper