{"record":{"id":"b0f5cfdd5128c273","repo":"keras-team/keras","slug":"when-using-textvectorization-to-tokenize-strings","errorCode":null,"errorMessage":"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}","messagePattern":"When using `TextVectorization` to tokenize strings, the input rank must be 1 or the last shape dimension must be 1\\. Received: inputs\\.shape=(.+?) with rank=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/text_vectorization.py","lineNumber":620,"sourceCode":"                    \"strip_punctuation\",\n                    \"lower_and_strip_punctuation\",\n                ):\n                    inputs = tf.strings.regex_replace(\n                        inputs,\n                        r'[!\"#$%&()\\*\\+,-\\./:;<=>?@\\[\\\\\\]^_`{|}~\\']',\n                        \"\",\n                    )\n                if callable(self._standardize):\n                    inputs = self._standardize(inputs)\n\n            if self._split is not None:\n                # If we are splitting, we validate that the 1st axis is of\n                # dimension 1 and so can be squeezed out. We do this here\n                # instead of after splitting for performance reasons - it's\n                # more expensive to squeeze a ragged tensor.\n                if inputs.shape.rank > 1:\n                    if inputs.shape[-1] != 1:\n                        raise ValueError(\n                            \"When using `TextVectorization` to tokenize \"\n                            \"strings, the input rank must be 1 or the last \"\n                            f\"shape dimension must be 1. Received: \"\n                            f\"inputs.shape={inputs.shape} with \"\n                            f\"rank={inputs.shape.rank}\"\n                        )\n                    else:\n                        inputs = tf.squeeze(inputs, axis=-1)\n                if self._split == \"whitespace\":\n                    # This treats multiple whitespaces as one whitespace,\n                    # and strips leading and trailing whitespace.\n                    inputs = tf.strings.split(inputs)\n                elif self._split == \"character\":\n                    inputs = tf.strings.unicode_split(inputs, \"UTF-8\")\n                elif callable(self._split):\n                    inputs = self._split(inputs)\n\n            # Note that 'inputs' here can be either ragged or dense depending","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/text_vectorization.py#L602-L638","documentation":"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.","triggerScenarios":"Thrown at keras/src/layers/preprocessing/text_vectorization.py:620 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}