tensorflow/models · error · ValueError
is_treatment tensor must be a tensor of shape (D0,) (D0, 1)
Error message
is_treatment tensor must be a tensor of shape (D0,) (D0, 1) but got a tensor of shape {is_treatment.shape} instead. What it means
Error "is_treatment tensor must be a tensor of shape (D0,) (D0, 1) but got a tensor of shape {is_treatment.shape} instead." thrown in tensorflow/models.
Source
Thrown at official/recommendation/uplift/utils.py:55
def split_by_treatment(
values: tf.Tensor, is_treatment: tf.Tensor
) -> Tuple[tf.Tensor, tf.Tensor]:
"""Splits a tensor into control and treatment tensors.
Args:
values: a `tf.Tensor` of shape (D0, D1, ..., DN).
is_treatment: a `tf.Tensor` of shape (D0,) or (D0, 1) castable to boolean
indicating if the example belongs to the treatment group (True) or control
group (False).
Returns:
A tuple with control and treatment values sliced by the is_treatment tensor.
"""
if is_treatment.shape.rank > 2 or (
is_treatment.shape == 2 and is_treatment.shape[1] != 1 # pyrefly: ignore[unsupported-operation]
):
raise ValueError(
"is_treatment tensor must be a tensor of shape (D0,) (D0, 1) but got a"
f" tensor of shape {is_treatment.shape} instead."
)
if values.shape[0] != is_treatment.shape[0]:
raise ValueError(
"values and is_treatment must be tensors of shapes (D0, D1, ..., DN)"
f" and (D0, 1) (or (D0,)), but got tensors of shapes {values.shape} and"
f" {is_treatment.shape} respectively."
)
if is_treatment.dtype == tf.string:
raise ValueError(
"is_treatment must be a tensor castable to boolean but got tensor"
f" {is_treatment} of dtype {is_treatment.dtype} instead."
)
# Assert is_treatment tensor containss only 0 or 1 values.View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/uplift/utils.py:55 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/1b26d923858dabb3.
Report an issue: GitHub.