keras-team/keras · error · ValueError
Received an invalid value for `threshold`, expected a…
Error message
Received an invalid value for `threshold`, expected a non-negative float or None. Received: threshold={threshold} What it means
Value guard in TernaryDense.__init__ executed after the type check: a numeric `threshold` was provided but it is negative, which would produce a nonsensical ternarization cutoff. Only non-negative floats (or None) are meaningful.
Solutions
- Use a non-negative threshold, e.g. threshold=0.0 or a small positive value
- Pass threshold=None to let the layer pick its default threshold
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/core/ternary_dense.py:135 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/a88426bfb0b01105.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/core/ternary_dense.py:135
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
**kwargs,
):
if not isinstance(units, int) or units <= 0:
raise ValueError(
"Received an invalid value for `units`, expected a positive "
f"integer. Received: units={units}"
)
if threshold is not None and not isinstance(threshold, (int, float)):
raise ValueError(
"Received an invalid value for `threshold`, expected a float "
f"or None. Received: threshold={threshold}"
)
if threshold is not None and threshold < 0:
raise ValueError(
"Received an invalid value for `threshold`, expected a "
"non-negative float or None. "
f"Received: threshold={threshold}"
)
super().__init__(activity_regularizer=activity_regularizer, **kwargs)
self.units = units
self.threshold = threshold
self.activation = activations.get(activation)
self.use_bias = use_bias
self.kernel_initializer = initializers.get(kernel_initializer)
self.bias_initializer = initializers.get(bias_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)
self.bias_regularizer = regularizers.get(bias_regularizer)
self.kernel_constraint = constraints.get(kernel_constraint)
self.bias_constraint = constraints.get(bias_constraint)
self.input_spec = InputSpec(min_ndim=2)
self.supports_masking = TrueView on GitHub (pinned to 7a34a03db6)