keras-team/keras · error · ValueError
When using `TextVectorization` to tokenize strings, the inpu
Error message
When using `TextVectorization` to tokenize strings, the input rank must be 1 or the last shape dimension must be 1. Received: inputs.shape={inputs.shape} with rank={inputs.shape.rank} What it means
Error "When using `TextVectorization` to tokenize strings, the input rank must be 1 or the last shape dimension must be 1. Received: inputs.shape={inputs.shape} with rank={inputs.shape.rank}" thrown in keras-team/keras.
Source
Thrown at keras/src/layers/preprocessing/text_vectorization.py:620
"strip_punctuation",
"lower_and_strip_punctuation",
):
inputs = tf.strings.regex_replace(
inputs,
r'[!"#$%&()\*\+,-\./:;<=>?@\[\\\]^_`{|}~\']',
"",
)
if callable(self._standardize):
inputs = self._standardize(inputs)
if self._split is not None:
# If we are splitting, we validate that the 1st axis is of
# dimension 1 and so can be squeezed out. We do this here
# instead of after splitting for performance reasons - it's
# more expensive to squeeze a ragged tensor.
if inputs.shape.rank > 1:
if inputs.shape[-1] != 1:
raise ValueError(
"When using `TextVectorization` to tokenize "
"strings, the input rank must be 1 or the last "
f"shape dimension must be 1. Received: "
f"inputs.shape={inputs.shape} with "
f"rank={inputs.shape.rank}"
)
else:
inputs = tf.squeeze(inputs, axis=-1)
if self._split == "whitespace":
# This treats multiple whitespaces as one whitespace,
# and strips leading and trailing whitespace.
inputs = tf.strings.split(inputs)
elif self._split == "character":
inputs = tf.strings.unicode_split(inputs, "UTF-8")
elif callable(self._split):
inputs = self._split(inputs)
# Note that 'inputs' here can be either ragged or dense dependingView on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/text_vectorization.py:620 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/b0f5cfdd5128c273.
Report an issue: GitHub.