keras-team/keras · error · ValueError

Invalid value received for argument `rate`. Expected a…

Error message

Invalid value received for argument `rate`. Expected a float value between 0 and 1. Received: rate={rate}

What it means

Raised by Dropout.__init__ when the `rate` argument falls outside the [0, 1] interval. `rate` is the fraction of input units to drop, so any value below 0 or above 1 is physically meaningless and the constructor rejects it before building the layer.

Solutions

  1. Set `rate` to a float between 0 and 1, e.g. Dropout(rate=0.5)
  2. If the value comes from a hyperparameter sweep or config, clamp/validate it before passing it to the layer
  3. Check for accidental integer division or string values converted incorrectly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/layers/regularization/dropout.py:44 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/6d64d04aec450dec. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/layers/regularization/dropout.py:44

        rate: Float between 0 and 1. Fraction of the input units to drop.
        noise_shape: 1D integer tensor representing the shape of the
            binary dropout mask that will be multiplied with the input.
            For instance, if your inputs have shape
            `(batch_size, timesteps, features)` and
            you want the dropout mask to be the same for all timesteps,
            you can use `noise_shape=(batch_size, 1, features)`.
        seed: A Python integer to use as random seed.

    Call arguments:
        inputs: Input tensor (of any rank).
        training: Python boolean indicating whether the layer should behave in
            training mode (adding dropout) or in inference mode (doing nothing).
    """

    def __init__(self, rate, noise_shape=None, seed=None, **kwargs):
        super().__init__(**kwargs)
        if not 0 <= rate <= 1:
            raise ValueError(
                f"Invalid value received for argument "
                "`rate`. Expected a float value between 0 and 1. "
                f"Received: rate={rate}"
            )
        self.rate = rate
        self.seed = seed
        self.noise_shape = self._validate_noise_shape(noise_shape)
        if rate > 0:
            self.seed_generator = backend.random.SeedGenerator(seed)
        self.supports_masking = True

        self._build_at_init()

    def _validate_noise_shape(self, noise_shape):
        if noise_shape is None:
            return None

        if isinstance(noise_shape, str):

View on GitHub (pinned to 7a34a03db6)