{"record":{"id":"2ed9413bb74fe077","repo":"keras-team/keras","slug":"output-dim-must-be-a-positive-integer-received","errorCode":null,"errorMessage":"`output_dim` must be a positive integer. Received: output_dim={output_dim} (of type {type(output_dim).__name__}).","messagePattern":"`output_dim` must be a positive integer\\. Received: output_dim=(.+?) \\(of type (.+?)\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/embedding.py","lineNumber":116,"sourceCode":"        quantization_config=None,\n        **kwargs,\n    ):\n        if (\n            not isinstance(input_dim, int)\n            or isinstance(input_dim, bool)\n            or input_dim <= 0\n        ):\n            raise ValueError(\n                \"`input_dim` must be a positive integer. \"\n                f\"Received: input_dim={input_dim} \"\n                f\"(of type {type(input_dim).__name__}).\"\n            )\n        if (\n            not isinstance(output_dim, int)\n            or isinstance(output_dim, bool)\n            or output_dim <= 0\n        ):\n            raise ValueError(\n                \"`output_dim` must be a positive integer. \"\n                f\"Received: output_dim={output_dim} \"\n                f\"(of type {type(output_dim).__name__}).\"\n            )\n        input_length = kwargs.pop(\"input_length\", None)\n        if input_length is not None:\n            warnings.warn(\n                \"Argument `input_length` is deprecated. Just remove it.\"\n            )\n        super().__init__(**kwargs)\n        self.input_dim = input_dim\n        self.output_dim = output_dim\n        self.embeddings_initializer = initializers.get(embeddings_initializer)\n        self.embeddings_regularizer = regularizers.get(embeddings_regularizer)\n        self.embeddings_constraint = constraints.get(embeddings_constraint)\n        self.mask_zero = mask_zero\n        self.supports_masking = mask_zero\n        self.autocast = False","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/embedding.py#L98-L134","documentation":"keras.layers.Embedding requires output_dim (embedding vector length) to be a Python int strictly greater than 0; bools are rejected explicitly. Floats, numpy ints, 0, negatives, or True all fail this check in __init__ immediately after the input_dim check.","triggerScenarios":"Constructing Embedding with output_dim=0, output_dim=-16, output_dim=128.0, output_dim=np.int32(64), or output_dim=True.","commonSituations":"Hyperparameters loaded from YAML/JSON configs (deserialized as floats); argparse values not cast to int; deriving output_dim from arithmetic that yields a float.","solutions":["Pass a plain Python int greater than 0, e.g. Embedding(input_dim=10000, output_dim=128)","Cast config values with int(...) at the call site","Ensure the value is not accidentally a boolean flag"],"exampleFix":"# before\nlayer = keras.layers.Embedding(input_dim=10000, output_dim=float(cfg['dim']))\n# after\nlayer = keras.layers.Embedding(input_dim=10000, output_dim=int(cfg['dim']))","handlingStrategy":"type-guard","validationCode":"assert isinstance(output_dim, int) and not isinstance(output_dim, bool) and output_dim > 0","typeGuard":"def is_positive_int(v):\n    return isinstance(v, int) and not isinstance(v, bool) and v > 0","tryCatchPattern":null,"preventionTips":["Cast hyperparameters from argparse/config files to int","Validate hyperparameters in config-loading code, not at model construction"],"tags":["keras","embedding","constructor-validation","output-dim"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}