{"record":{"id":"b6081c039308d9aa","repo":"keras-team/keras","slug":"the-theta-value-of-a-thresholded-relu-layer-should","errorCode":null,"errorMessage":"The theta value of a Thresholded ReLU layer should be >=0. Received: {theta}","messagePattern":"The theta value of a Thresholded ReLU layer should be >=0\\. Received: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/layers.py","lineNumber":227,"sourceCode":"            \"seed\": self.seed,\n        }\n        base_config = super().get_config()\n        return {**base_config, **config}\n\n\n@keras_export(\"keras._legacy.layers.ThresholdedReLU\")\nclass ThresholdedReLU(Layer):\n    \"\"\"DEPRECATED.\"\"\"\n\n    def __init__(self, theta=1.0, **kwargs):\n        super().__init__(**kwargs)\n        if theta is None:\n            raise ValueError(\n                \"Theta of a Thresholded ReLU layer cannot be None, expecting a \"\n                f\"float. Received: {theta}\"\n            )\n        if theta < 0:\n            raise ValueError(\n                \"The theta value of a Thresholded ReLU layer \"\n                f\"should be >=0. Received: {theta}\"\n            )\n        self.supports_masking = True\n        self.theta = tf.convert_to_tensor(theta, dtype=self.compute_dtype)\n\n    def call(self, inputs):\n        dtype = self.compute_dtype\n        return inputs * tf.cast(tf.greater(inputs, self.theta), dtype)\n\n    def get_config(self):\n        config = {\"theta\": float(self.theta)}\n        base_config = super().get_config()\n        return {**base_config, **config}\n\n    def compute_output_shape(self, input_shape):\n        return input_shape\n","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/layers.py#L209-L245","documentation":"ThresholdedReLU activates inputs strictly greater than `theta`, and the layer requires theta >= 0 so it behaves as a threshold on positive activations. __init__ raises this ValueError when a negative theta is passed, whether directly or from a loaded config.","triggerScenarios":"Constructing ThresholdedReLU(theta=-0.5) or loading a serialized model config containing a negative theta value.","commonSituations":"Tuning theta via a sweep that crosses zero without constraints; hand-editing saved model configs; confusing theta with a bias-like parameter that is allowed to be negative.","solutions":["Use theta >= 0, e.g. ThresholdedReLU(theta=0.5); theta=0 degenerates toward plain ReLU — prefer keras.layers.ReLU then","Clip swept theta values to [0, inf) or constrain the search space","Validate deserialized configs before layer construction"],"exampleFix":"# before\nlayer = ThresholdedReLU(theta=-0.5)\n# after\nlayer = ThresholdedReLU(theta=0.5)","handlingStrategy":"validation","validationCode":"theta = cfg.get('theta', 1.0)\nassert theta >= 0, f'theta must be >= 0, got {theta}'","typeGuard":"def is_valid_theta(t) -> bool:\n    return isinstance(t, (int, float)) and t >= 0","tryCatchPattern":null,"preventionTips":["Clip theta in sweeps: theta = max(0.0, theta)","Prefer keras.layers.ReLU(threshold=...) in new code; it documents the same >=0 contract"],"tags":["keras","activation","argument-validation","legacy","relu"],"backgroundTag":"argument-out-of-range","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}