tensorflow/models · error · ValueError
The `slicing_feature` and slicing values in `slicing_spec` m
Error message
The `slicing_feature` and slicing values in `slicing_spec` must have the same type. Got types: {(slicing_feature.dtype, self._slicing_feature_dtype)}. What it means
Error "The `slicing_feature` and slicing values in `slicing_spec` must have the same type. Got types: {(slicing_feature.dtype, self._slicing_feature_dtype)}." thrown in tensorflow/models.
Source
Thrown at official/recommendation/uplift/metrics/sliced_metric.py:144
sample_weight: tf.Tensor | None = None,
slicing_feature: tf.Tensor,
**kwargs,
):
"""Updates the state of the metrics for each slice.
Args:
*args: A variable amount of `tf.Tensor` instances that will be passed to
the `update_state` method of each metric.
sample_weight: An optional `tf.Tensor` used to weight the sample. Its
dimensions must be broadcastable to the shape(s) of *args.
slicing_feature: A `tf.Tensor` consisting of the feature to be sliced on.
Its dimensions must be broadcastable to the shape(s) of *args.
**kwargs: Keyword arguments that will be passed to the `update_state`
method of each metric.
"""
if slicing_feature.dtype != self._slicing_feature_dtype:
raise ValueError(
"The `slicing_feature` and slicing values in `slicing_spec` must "
"have the same type. Got types: "
f"{(slicing_feature.dtype, self._slicing_feature_dtype)}."
)
if sample_weight is not None:
for _ in range(len(slicing_feature.shape) - len(sample_weight.shape)):
sample_weight = tf.expand_dims(sample_weight, axis=-1)
for _ in range(len(sample_weight.shape) - len(slicing_feature.shape)):
slicing_feature = tf.expand_dims(slicing_feature, axis=-1)
self._metric.update_state(*args, sample_weight=sample_weight, **kwargs)
for slicing_val, metric in zip(
self._slicing_values_tensors, self._sliced_metrics
):
slice_mask = tf.cast(slicing_feature == slicing_val, dtype=tf.float32)
if sample_weight is not None:View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/uplift/metrics/sliced_metric.py:144 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/dae65bf3534fd69d.
Report an issue: GitHub.