keras-team/keras · error · ValueError

If a string is passed to `window`, it must be one of…

Error message

If a string is passed to `window`, it must be one of `"hann"`, `"hamming"`. Received: window={window}

What it means

Raised by the JAX backend stft when the window argument is a string but not one of the two window names this backend recognizes ("hann" or "hamming"). The string is forwarded to scipy.signal.get_window, but only these two names are whitelisted; any other name (e.g. "blackman", "kaiser") or a typo is rejected before computation.

Solutions

  1. Use window="hann" or window="hamming"
  2. For other window types, compute the window yourself (e.g. scipy.signal.get_window("blackman", sequence_length)) and pass it as an array/tensor instead of a string
  3. Check for typos and case: the name must match exactly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/jax/ops/math.py:179 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/7c46ee79e0349304. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/jax/ops/math.py:179


def stft(
    x, sequence_length, sequence_stride, fft_length, window="hann", center=True
):
    if standardize_dtype(x.dtype) not in {"float32", "float64"}:
        raise TypeError(
            "Invalid input type. Expected `float32` or `float64`. "
            f"Received: input type={x.dtype}"
        )
    if fft_length < sequence_length:
        raise ValueError(
            "`fft_length` must equal or larger than `sequence_length`. "
            f"Received: sequence_length={sequence_length}, "
            f"fft_length={fft_length}"
        )
    if isinstance(window, str):
        if window not in {"hann", "hamming"}:
            raise ValueError(
                "If a string is passed to `window`, it must be one of "
                f'`"hann"`, `"hamming"`. Received: window={window}'
            )
    x = convert_to_tensor(x)

    if center:
        pad_width = [(0, 0) for _ in range(len(x.shape))]
        pad_width[-1] = (fft_length // 2, fft_length // 2)
        x = jnp.pad(x, pad_width, mode="reflect")

    l_pad = (fft_length - sequence_length) // 2
    r_pad = fft_length - sequence_length - l_pad

    if window is not None:
        if isinstance(window, str):
            win = convert_to_tensor(
                scipy.signal.get_window(window, sequence_length), dtype=x.dtype
            )

View on GitHub (pinned to 7a34a03db6)