keras-team/keras · error · ValueError
Invalid value for attribute `regularizer`. Expected a…
Error message
Invalid value for attribute `regularizer`. Expected a callable (such as a `keras.regularizers.Regularizer` instance) or `None`. Received: regularizer={value} What it means
Raised by the regularizer property setter when the assigned value is neither None nor callable. Keras accepts a Regularizer instance (which is callable) or None; strings, dicts, or other non-callable objects fail the callable check in this generic guard.
Solutions
- Pass a keras.regularizers.Regularizer instance, e.g. variable.regularizer = keras.regularizers.L2(1e-4), or None to disable.
- Resolve string identifiers first: keras.regularizers.get('l2') before assigning.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/common/variables.py:378 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/7d41025e05eba012.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/common/variables.py:378
return self._overwrite_with_gradient
@overwrite_with_gradient.setter
def overwrite_with_gradient(self, value):
if not isinstance(value, bool):
raise TypeError(
"`overwrite_with_gradient` must be a boolean. "
f"Received: {value}"
)
self._overwrite_with_gradient = value
@property
def regularizer(self):
return self._regularizer
@regularizer.setter
def regularizer(self, value):
if value is not None and not callable(value):
raise ValueError(
"Invalid value for attribute `regularizer`. Expected a "
"callable (such as a `keras.regularizers.Regularizer` "
f"instance) or `None`. Received: regularizer={value}"
)
self._regularizer = value
@property
def constraint(self):
return self._constraint
@constraint.setter
def constraint(self, value):
if value is not None and not callable(value):
raise ValueError(
"Invalid value for attribute `constraint`. Expected a "
"callable (such as a `keras.constraints.Constraint` instance) "
f"or `None`. Received: constraint={value}"
)View on GitHub (pinned to 7a34a03db6)