keras-team/keras · error · ValueError
`output_sequence_length` must be either None or an integer…
Error message
`output_sequence_length` must be either None or an integer when `output_mode` is 'int'. Received: output_sequence_length={output_sequence_length} What it means
Constructor guard in TextVectorization.__init__: with output_mode='int', output_sequence_length was set to something other than None or an int (e.g. a float or a list). Integer-index output requires the padding length to be a plain integer or absent.
Solutions
- Pass output_sequence_length=None (variable length) or a plain int like 100
- Cast floats: output_sequence_length=int(value)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/text_vectorization.py:305 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/d54340666f96b1dc.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/preprocessing/text_vectorization.py:305
# '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(
"`output_sequence_length` must not be set if `output_mode` is "
"not 'int'. "
f"Received output_sequence_length={output_sequence_length}."
)
if ragged and output_mode != "int":
raise ValueError(
"`ragged` must not be true if `output_mode` is "
f"`'int'`. Received: ragged={ragged} and "
f"output_mode={output_mode}"
)View on GitHub (pinned to 7a34a03db6)