{"record":{"id":"24a81939ad95b068","repo":"keras-team/keras","slug":"idf-weights-should-only-be-set-if-output-mode","errorCode":null,"errorMessage":"`idf_weights` should only be set if `output_mode` is `'tf_idf'`. Received: idf_weights={idf_weights} and output_mode={output_mode}","messagePattern":"`idf_weights` should only be set if `output_mode` is `'tf_idf'`\\. Received: idf_weights=(.+?) and output_mode=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/index_lookup.py","lineNumber":210,"sourceCode":"            arg_name=\"output_mode\",\n        )\n\n        if invert and output_mode != \"int\":\n            raise ValueError(\n                \"`output_mode` must be `'int'` when `invert` is true. \"\n                f\"Received: output_mode={output_mode}\"\n            )\n\n        if sparse and output_mode == \"int\":\n            raise ValueError(\n                \"`sparse` may only be true if `output_mode` is \"\n                \"`'one_hot'`, `'multi_hot'`, `'count'` or `'tf_idf'`. \"\n                f\"Received: sparse={sparse} and \"\n                f\"output_mode={output_mode}\"\n            )\n\n        if idf_weights is not None and output_mode != \"tf_idf\":\n            raise ValueError(\n                \"`idf_weights` should only be set if `output_mode` is \"\n                f\"`'tf_idf'`. Received: idf_weights={idf_weights} and \"\n                f\"output_mode={output_mode}\"\n            )\n\n        super().__init__(name=name)\n        self._convert_input_args = False\n        self._allow_non_tensor_positional_args = True\n        self.supports_jit = False\n\n        self.invert = invert\n        self.max_tokens = max_tokens\n        self.num_oov_indices = num_oov_indices\n        self.mask_token = mask_token\n        self.oov_token = oov_token\n        self.output_mode = output_mode\n        self.sparse = sparse\n        self.pad_to_max_tokens = pad_to_max_tokens","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/index_lookup.py#L192-L228","documentation":"`idf_weights` are per-token inverse-document-frequency scaling factors, which only exist in TF-IDF output mode. Supplying them with any other output_mode is rejected at construction.","triggerScenarios":"`IndexLookup(vocabulary=vocab, idf_weights=w)` while output_mode is 'int' (default), 'multi_hot', 'count' or 'one_hot'.","commonSituations":"Reusing a TF-IDF layer's full argument set after switching output_mode, or loading idf weights from a fitted sklearn TfidfVectorizer into a count-mode layer.","solutions":["Set `output_mode='tf_idf'` if you want idf weighting.","Or remove the `idf_weights` argument."],"exampleFix":"# before\nlayer = IndexLookup(vocabulary=vocab, idf_weights=idf)\n\n# after\nlayer = IndexLookup(vocabulary=vocab, idf_weights=idf, output_mode='tf_idf')","handlingStrategy":"validation","validationCode":"if idf_weights is not None and output_mode != 'tf_idf':\n    raise ValueError('idf_weights requires output_mode=tf_idf')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat idf_weights as a tf_idf-only argument in config schemas.","When porting sklearn vectorizers, set output_mode first, then weights."],"tags":["keras","preprocessing","index-lookup","tf-idf","argument-validation"],"backgroundTag":"invalid-argument-combination","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}