keras-team/keras · error · ValueError
`ngrams` must be None, an integer, or a tuple of integers. R
Error message
`ngrams` must be None, an integer, or a tuple of integers. Received: ngrams={ngrams} What it means
Error "`ngrams` must be None, an integer, or a tuple of integers. Received: ngrams={ngrams}" thrown in keras-team/keras.
Source
Thrown at keras/src/layers/preprocessing/text_vectorization.py:294
allowable_strings=(
"int",
"one_hot",
"multi_hot",
"count",
"tf_idf",
),
caller_name=self.__class__.__name__,
arg_name="output_mode",
)
# 'ngrams' must be one of (None, int, tuple(int))
if not (
ngrams is None
or isinstance(ngrams, int)
or isinstance(ngrams, tuple)
and all(isinstance(item, int) for item in ngrams)
):
raise ValueError(
"`ngrams` must be None, an integer, or a tuple of "
f"integers. Received: ngrams={ngrams}"
)
# 'output_sequence_length' must be one of (None, int) and is only
# set if output_mode is "int"".
if output_mode == "int" and not (
isinstance(output_sequence_length, int)
or (output_sequence_length is None)
):
raise ValueError(
"`output_sequence_length` must be either None or an "
"integer when `output_mode` is 'int'. Received: "
f"output_sequence_length={output_sequence_length}"
)
if output_mode != "int" and output_sequence_length is not None:
raise ValueError(View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/text_vectorization.py:294 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/bd8100a7e268d9fd.
Report an issue: GitHub.