keras-team/keras · error · ValueError

q must be in the interval (0, 1)

Error message

q must be in the interval (0, 1)

What it means

Error "q must be in the interval (0, 1)" thrown in keras-team/keras.

Source

Thrown at keras/src/losses/losses.py:1593

    y_pred = np.array([[0.7, 0.3], [0.2, 0.8], [0.6, 0.4], [0.4, 0.6]])
    keras.losses.CategoricalGeneralizedCrossEntropy()(y_true, y_pred)
    ```

    References:
        - [Zhang, Sabuncu, 2018](https://arxiv.org/abs/1805.07836)
          ("Generalized Cross Entropy Loss for Training
            Deep Neural Networks with Noisy Labels")
    """

    def __init__(
        self,
        q=0.5,
        reduction="sum_over_batch_size",
        name="categorical_generalized_cross_entropy",
        dtype=None,
    ):
        if not 0 < q < 1:
            raise ValueError("q must be in the interval (0, 1)")
        super().__init__(
            categorical_generalized_cross_entropy,
            name=name,
            reduction=reduction,
            dtype=dtype,
            q=q,
        )
        self.q = q

    def get_config(self):
        config = Loss.get_config(self)
        config.update(
            {
                "q": self.q,
            }
        )
        return config

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/losses/losses.py:1593 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/e40ad77c39742f51. Report an issue: GitHub.