{"record":{"id":"ada8a30032e19c4d","repo":"keras-team/keras","slug":"output-mode-must-be-int-when-invert-is-tru","errorCode":null,"errorMessage":"`output_mode` must be `'int'` when `invert` is true. Received: output_mode={output_mode}","messagePattern":"`output_mode` must be `'int'` when `invert` is true\\. Received: output_mode=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/index_lookup.py","lineNumber":196,"sourceCode":"        if output_mode == \"binary\":\n            output_mode = \"multi_hot\"\n        if output_mode == \"tf-idf\":\n            output_mode = \"tf_idf\"\n        argument_validation.validate_string_arg(\n            output_mode,\n            allowable_strings=(\n                \"int\",\n                \"one_hot\",\n                \"multi_hot\",\n                \"count\",\n                \"tf_idf\",\n            ),\n            caller_name=self.__class__.__name__,\n            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            )","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/index_lookup.py#L178-L214","documentation":"With `invert=True` the layer maps indices back to tokens, which only makes sense for dense integer output. The constructor therefore requires `output_mode='int'` when inverting.","triggerScenarios":"`IndexLookup(invert=True, output_mode='multi_hot')` (or 'one_hot', 'count', 'tf_idf').","commonSituations":"Building a decoder layer by copying an encoder's config and flipping `invert`, forgetting the encoder used multi_hot or tf_idf mode.","solutions":["Set `output_mode='int'` when `invert=True`.","Or build the inverse mapping from the vocabulary with a separate non-inverted lookup layer."],"exampleFix":"# before\ninv = IndexLookup(vocabulary=vocab, invert=True, output_mode='multi_hot')\n\n# after\ninv = IndexLookup(vocabulary=vocab, invert=True, output_mode='int')","handlingStrategy":"validation","validationCode":"if invert and output_mode != 'int':\n    output_mode = 'int'\nlayer = IndexLookup(invert=invert, output_mode=output_mode)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep decoder (invert) layers on output_mode='int' by convention.","When cloning an encoder config for a decoder, reset mode-dependent flags."],"tags":["keras","preprocessing","index-lookup","argument-validation"],"backgroundTag":"invalid-argument-combination","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}