tensorflow/models · error · ValueError
The slicing spec must be a non-empty dictionary.
Error message
The slicing spec must be a non-empty dictionary.
What it means
Error "The slicing spec must be a non-empty dictionary." thrown in tensorflow/models.
Source
Thrown at official/recommendation/uplift/metrics/sliced_metric.py:92
Args:
metric: A `tf_keras.metrics.Metric` instance.
slicing_spec: A dictionary that maps from string slice names, to one of
integer, boolean, or string slicing values.
slicing_feature_dtype: The expected dtype of the slicing feature. The
values in the slicing spec are casted to this type if passed. If None,
the dtype of the slicing feature is inferred based on the values in the
slicing spec.
name: The name of the wrapper metric. Defaults to `sliced_{metric.name}`.
Raises:
A ValueError if `slicing_spec` is empty, contains duplicate slicing
values, or has slicing values of different types.
"""
super().__init__(name=name or f"sliced_{metric.name}", dtype=metric.dtype)
if not slicing_spec:
raise ValueError("The slicing spec must be a non-empty dictionary.")
slice_names, slicing_values = zip(*slicing_spec.items())
if not isinstance(slicing_values[0], (int, bool, str)) or not all(
isinstance(k, type(slicing_values[0])) for k in slicing_values
):
raise ValueError(
"All slicing values in the slicing spec must be one of `int`, "
"`bool`, or `str`, and all values must have the same type. "
f"Got types: {list(map(type, slicing_values))}."
)
if len(slicing_values) > len(set(slicing_values)):
raise ValueError(
"The slicing values passed to the slicing spec must be unique. Got "
f"{slicing_values}."
)
# TODO(b/276811843): Look into validating whether `metric` acceptsView on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/uplift/metrics/sliced_metric.py:92 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/3724b4ec5324746b.
Report an issue: GitHub.