keras-team/keras · error · ValueError

Invalid value received for argument `noise_shape`. Expected…

Error message

Invalid value received for argument `noise_shape`. Expected a tuple or list of integers. Received: noise_shape={noise_shape}

What it means

Raised by Dropout._validate_noise_shape when `noise_shape` is a Python string. Strings are iterable, so they would otherwise be silently treated as sequences of characters; the validator explicitly rejects them and expects a tuple or list of integers describing the binary dropout mask shape.

Solutions

  1. Pass `noise_shape` as a tuple/list of ints, e.g. noise_shape=(batch_size, 1, features)
  2. Do not pass a string; if the shape arrives as text, parse it into a tuple of integers first
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

                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):
            raise ValueError(
                f"Invalid value received for argument `noise_shape`. "
                f"Expected a tuple or list of integers. "
                f"Received: noise_shape={noise_shape}"
            )

        if not isinstance(noise_shape, tuple):
            try:
                noise_shape = tuple(noise_shape)
            except TypeError:
                raise ValueError(
                    f"Invalid value received for argument `noise_shape`. "
                    f"Expected an iterable of integers "
                    f"(e.g., a tuple or list). "
                    f"Received: noise_shape={noise_shape}"
                )

        for i, dim in enumerate(noise_shape):
            if dim is not None:

View on GitHub (pinned to 7a34a03db6)