keras-team/keras · error · ValueError
`output_sequence_length` must not be set if `output_mode`…
Error message
`output_sequence_length` must not be set if `output_mode` is not 'int'. Received output_sequence_length={output_sequence_length}. What it means
Constructor guard in TextVectorization.__init__: output_sequence_length was set (not None) while output_mode is not 'int'. Sequence padding only exists for integer-index output; bag-of-words modes (one_hot, multi_hot, count, tf_idf) produce fixed-size vectors where the argument is meaningless, so it is rejected.
Solutions
- Set output_sequence_length=None when using output_mode in {'one_hot', 'multi_hot', 'count', 'tf_idf'}
- Only pass output_sequence_length together with output_mode='int'
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/text_vectorization.py:312 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/7cd62054251f2971.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/preprocessing/text_vectorization.py:312
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}"
)
self._max_tokens = max_tokens
self._standardize = standardize
self._split = split
self._ngrams_arg = ngrams
if isinstance(ngrams, int):
self._ngrams = tuple(range(1, ngrams + 1))View on GitHub (pinned to 7a34a03db6)