tensorflow/models · error · ValueError
`from_logits` must be set to `True` when `y_pred` is of type
Error message
`from_logits` must be set to `True` when `y_pred` is of type TwoTowerTrainingOutputs. Note that the true logits and true predictions are assumed to be linked to each other through the log link function: `true_logits = tf.math.log(true_predictions).
What it means
Error "`from_logits` must be set to `True` when `y_pred` is of type TwoTowerTrainingOutputs. Note that the true logits and true predictions are assumed to be linked to each other through the log link function: `true_logits = tf.math.log(true_predictions)." thrown in tensorflow/models.
Source
Thrown at official/recommendation/uplift/metrics/poisson_metrics.py:107
"""
super().__init__(
loss_fn=tf.nn.log_poisson_loss,
from_logits=from_logits,
compute_full_loss=compute_full_loss,
slice_by_treatment=slice_by_treatment,
name=name,
dtype=dtype,
)
def update_state(
self,
y_true: tf.Tensor,
y_pred: types.TwoTowerTrainingOutputs | tf.Tensor,
sample_weight: tf.Tensor | None = None,
):
if not self._from_logits:
if isinstance(y_pred, types.TwoTowerTrainingOutputs):
raise ValueError(
"`from_logits` must be set to `True` when `y_pred` is of type"
" TwoTowerTrainingOutputs. Note that the true logits and true"
" predictions are assumed to be linked to each other through the"
" log link function: `true_logits = tf.math.log(true_predictions)."
)
y_pred = tf.math.log(y_pred)
super().update_state(y_true, y_pred, sample_weight)
def get_config(self) -> dict[str, Any]:
config = super().get_config()
del config["loss_fn"]
return config
@classmethod
def from_config(cls, config: dict[str, Any]) -> LogLoss:
return cls(**config)
View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/uplift/metrics/poisson_metrics.py:107 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/eb7406db2aeeec87.
Report an issue: GitHub.