keras-team/keras · error · ValueError

`num_bins` must be greater than or equal to 0. Received: `nu

Error message

`num_bins` must be greater than or equal to 0. Received: `num_bins={num_bins}`

What it means

Error "`num_bins` must be greater than or equal to 0. Received: `num_bins={num_bins}`" thrown in keras-team/keras.

Source

Thrown at keras/src/layers/preprocessing/discretization.py:126

                "`'one_hot'`, `'multi_hot'`, or `'count'`. "
                f"Received: sparse={sparse} and "
                f"output_mode={output_mode}"
            )

        argument_validation.validate_string_arg(
            output_mode,
            allowable_strings=(
                "int",
                "one_hot",
                "multi_hot",
                "count",
            ),
            caller_name=self.__class__.__name__,
            arg_name="output_mode",
        )

        if num_bins is not None and num_bins < 0:
            raise ValueError(
                "`num_bins` must be greater than or equal to 0. "
                f"Received: `num_bins={num_bins}`"
            )
        if num_bins is not None and bin_boundaries is not None:
            raise ValueError(
                "Both `num_bins` and `bin_boundaries` should not be set. "
                f"Received: `num_bins={num_bins}` and "
                f"`bin_boundaries={bin_boundaries}`"
            )
        if num_bins is None and bin_boundaries is None:
            raise ValueError(
                "You need to set either `num_bins` or `bin_boundaries`."
            )

        self.bin_boundaries = bin_boundaries
        self.num_bins = num_bins
        self.epsilon = epsilon
        self.output_mode = output_mode

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/preprocessing/discretization.py:126 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/cfb4d04d79acdcc8. Report an issue: GitHub.