{"record":{"id":"e574d09a0cb21032","repo":"keras-team/keras","slug":"unknown-vectorization-mode","errorCode":null,"errorMessage":"Unknown vectorization mode:","messagePattern":"Unknown vectorization mode:","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/preprocessing/text.py","lineNumber":281,"sourceCode":"                counts[j] += 1\n            for j, c in list(counts.items()):\n                if mode == \"count\":\n                    x[i][j] = c\n                elif mode == \"freq\":\n                    x[i][j] = c / len(seq)\n                elif mode == \"binary\":\n                    x[i][j] = 1\n                elif mode == \"tfidf\":\n                    # Use weighting scheme 2 in\n                    # https://en.wikipedia.org/wiki/Tf%E2%80%93idf\n                    tf = 1 + np.log(c)\n                    idf = np.log(\n                        1\n                        + self.document_count / (1 + self.index_docs.get(j, 0))\n                    )\n                    x[i][j] = tf * idf\n                else:\n                    raise ValueError(\"Unknown vectorization mode:\", mode)\n        return x\n\n    def get_config(self):\n        json_word_counts = json.dumps(self.word_counts)\n        json_word_docs = json.dumps(self.word_docs)\n        json_index_docs = json.dumps(self.index_docs)\n        json_word_index = json.dumps(self.word_index)\n        json_index_word = json.dumps(self.index_word)\n\n        return {\n            \"num_words\": self.num_words,\n            \"filters\": self.filters,\n            \"lower\": self.lower,\n            \"split\": self.split,\n            \"char_level\": self.char_level,\n            \"oov_token\": self.oov_token,\n            \"document_count\": self.document_count,\n            \"word_counts\": json_word_counts,","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/preprocessing/text.py#L263-L299","documentation":"sequences_to_matrix accepts only the modes 'binary', 'count', 'tfidf', and 'freq'; anything else falls through to raise ValueError('Unknown vectorization mode:', mode). Note the Keras bug of passing mode as a second positional argument to ValueError, so it shows as a tuple in the traceback rather than in the message text.","triggerScenarios":"Calling texts_to_matrix(texts, mode='tf-idf') (hyphen), mode='TFIDF' (uppercase), or a nonexistent mode like 'onehot'.","commonSituations":"Typos in the mode string; copying 'tf-idf' from other libraries' docs; case-sensitivity surprises.","solutions":["Use one of the exact lowercase strings: 'binary', 'count', 'tfidf', 'freq'","Check for hyphens and casing like 'tf-idf' or 'Tfidf'","For one-hot behavior use to_categorical on sequences instead"],"exampleFix":"# before\ntok.texts_to_matrix(texts, mode='tf-idf')\n# after\ntok.texts_to_matrix(texts, mode='tfidf')","handlingStrategy":"type-guard","validationCode":"MODES = {'binary', 'count', 'tfidf', 'freq'}\nif mode not in MODES:\n    raise ValueError(f'mode must be one of {MODES}')","typeGuard":"def valid_mode(m):\n    return m in {'binary', 'count', 'tfidf', 'freq'}","tryCatchPattern":null,"preventionTips":["Centralize mode strings as constants instead of inline literals"],"tags":["keras","text","tokenizer","mode"],"backgroundTag":"invalid-argument-value","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}