tracel-ai/burn · error
top_k must be non-zero
Error message
top_k must be non-zero
What it means
Config validation in `FBetaScore`/`ClassificationMetricConfig` construction: the `top_k` argument passed to the multiclass (or related) constructor is zero, which would make top-k classification undefined; config building panics.
Source
Thrown at crates/burn-train/src/metric/fbetascore.rs:74
..Default::default()
},
beta,
)
}
/// F-beta score metric for multiclass classification.
///
/// # Arguments
///
/// * `beta` - Positive real factor to weight recall's importance.
/// * `top_k` - The number of highest predictions considered to find the correct label (typically `1`).
/// * `class_reduction` - [Class reduction](ClassReduction) type.
#[allow(dead_code)]
pub fn multiclass(beta: f64, top_k: usize, class_reduction: ClassReduction) -> Self {
Self::new(
ClassificationMetricConfig {
decision_rule: DecisionRule::TopK(
NonZeroUsize::new(top_k).expect("top_k must be non-zero"),
),
class_reduction,
},
beta,
)
}
/// F-beta score metric for multi-label classification.
///
/// # Arguments
///
/// * `beta` - Positive real factor to weight recall's importance.
/// * `threshold` - The threshold to transform a probability into a binary prediction.
/// * `class_reduction` - [Class reduction](ClassReduction) type.
#[allow(dead_code)]
pub fn multilabel(beta: f64, threshold: f64, class_reduction: ClassReduction) -> Self {
Self::new(
ClassificationMetricConfig {View on GitHub (pinned to d16f7ba2ed)
Solutions
- Pass top_k >= 1 (typically 1)
- Validate user-provided top_k before constructing the metric
- Use the binary/threshold variant if top-k is not needed
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/burn-train/src/metric/fbetascore.rs:74 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/9a15d056924c53e5.
Report an issue: GitHub.