keras-team/keras · error · ValueError
Invalid `beta` argument value. It should be a Python float…
Error message
Invalid `beta` argument value. It should be a Python float. Received: beta={beta} of type '{type(beta)}' What it means
Raised by FBetaScore when the `beta` argument is not a Python float. beta weights recall vs precision (beta > 1 favors recall); it must be a plain Python float, not an int, string, tensor, or numpy scalar of non-float type.
Solutions
- Write beta with a decimal point: beta=1.0, beta=2.0.
- Coerce config values: float(cfg['beta']).
- Note keras.metrics.F1Score is a shortcut for beta=1.0.
Example fix
# before m = keras.metrics.FBetaScore(beta=1, average='macro') # after m = keras.metrics.FBetaScore(beta=1.0, average='macro') # or simply m = keras.metrics.F1Score(average='macro')
Defensive patterns
Strategy: type-guard
Validate before calling
beta = float(beta)
Type guard
def is_float_beta(v) -> bool:
return isinstance(v, float) Prevention
- Always write beta with a decimal point (1.0, 2.0).
- Coerce numeric config values with float() at load.
When it happens
Trigger: keras.metrics.FBetaScore(beta=1) (int, not 1.0); beta parsed from JSON/YAML as int; numpy floats or tf.Variable.
Common situations: Writing beta=1 or beta=2 as integers (the classic F1 case); config files storing 2 instead of 2.0.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Invalid `threshold` argument value. It should be a Python…
- FBetaScore expects 2D inputs with shape (batch_size…
- FBetaScore expects 2D inputs with shape (batch_size…
- Invalid `average` argument value. Expected one of
- Invalid `beta` argument value. It should be > 0. Received…
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/8843612fb1874ba9.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/metrics/f_score_metrics.py:86
average=None,
beta=1.0,
threshold=None,
name="fbeta_score",
dtype=None,
):
super().__init__(name=name, dtype=dtype)
# Metric should be maximized during optimization.
self._direction = "up"
if average not in (None, "micro", "macro", "weighted"):
raise ValueError(
"Invalid `average` argument value. Expected one of: "
"{None, 'micro', 'macro', 'weighted'}. "
f"Received: average={average}"
)
if not isinstance(beta, float):
raise ValueError(
"Invalid `beta` argument value. "
"It should be a Python float. "
f"Received: beta={beta} of type '{type(beta)}'"
)
if beta <= 0.0:
raise ValueError(
"Invalid `beta` argument value. "
"It should be > 0. "
f"Received: beta={beta}"
)
if threshold is not None:
if not isinstance(threshold, float):
raise ValueError(
"Invalid `threshold` argument value. "
"It should be a Python float. "
f"Received: threshold={threshold} "
f"of type '{type(threshold)}'"View on GitHub (pinned to 7a34a03db6)