tensorflow/models · error · ValueError
`slice_by_treatment` must be False when y_pred is a `tf.Tens
Error message
`slice_by_treatment` must be False when y_pred is a `tf.Tensor` or `np.ndarray`.
What it means
Error "`slice_by_treatment` must be False when y_pred is a `tf.Tensor` or `np.ndarray`." thrown in tensorflow/models.
Source
Thrown at official/recommendation/uplift/metrics/loss_metric.py:150
sample_weight: tf.Tensor | None = None,
):
"""Updates the overall, control and treatment losses.
Args:
y_true: A `tf.Tensor` with the targets.
y_pred: Model outputs. If of type `TwoTowerTrainingOutputs`, the treatment
indicator tensor is used to slice the true logits or true predictions
into control and treatment losses.
sample_weight: Optional sample weight to compute weighted losses. If
given, the sample weight will also be sliced by the treatment indicator
tensor to compute the weighted control and treatment losses.
Raises:
TypeError: if `y_pred` is not of type `TwoTowerTrainingOutputs`.
"""
if isinstance(y_pred, (tf.Tensor, np.ndarray)):
if self._slice_by_treatment:
raise ValueError(
"`slice_by_treatment` must be False when y_pred is a `tf.Tensor` or"
" `np.ndarray`."
)
pred = y_pred
elif isinstance(y_pred, types.TwoTowerTrainingOutputs):
pred = (
y_pred.true_logits if self._from_logits else y_pred.true_predictions
)
else:
raise TypeError(
"y_pred must be of type `TwoTowerTrainingOutputs`, `tf.Tensor` or"
f" `np.ndarray` but got type {type(y_pred)} instead."
)
is_treatment = {}
if self._slice_by_treatment:
is_treatment["is_treatment"] = y_pred.is_treatment
View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/uplift/metrics/loss_metric.py:150 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/73293b2d0cba4b02.
Report an issue: GitHub.