{"record":{"id":"fb6fe6a3daa05f86","repo":"tracel-ai/burn","slug":"top-k-must-be-non-zero-fb6fe6","errorCode":null,"errorMessage":"top_k must be non-zero","messagePattern":"top_k must be non-zero","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-train/src/metric/recall.rs","lineNumber":63,"sourceCode":"    pub fn binary(threshold: f64) -> Self {\n        Self::new(ClassificationMetricConfig {\n            decision_rule: DecisionRule::Threshold(threshold),\n            // binary classification results are the same independently of class_reduction\n            ..Default::default()\n        })\n    }\n\n    /// Recall metric for multiclass classification.\n    ///\n    /// # Arguments\n    ///\n    /// * `top_k` - The number of highest predictions considered to find the correct label (typically `1`).\n    /// * `class_reduction` - [Class reduction](ClassReduction) type.\n    #[allow(dead_code)]\n    pub fn multiclass(top_k: usize, class_reduction: ClassReduction) -> Self {\n        Self::new(ClassificationMetricConfig {\n            decision_rule: DecisionRule::TopK(\n                NonZeroUsize::new(top_k).expect(\"top_k must be non-zero\"),\n            ),\n            class_reduction,\n        })\n    }\n\n    /// Recall metric for multi-label classification.\n    ///\n    /// # Arguments\n    ///\n    /// * `threshold` - The threshold to transform a probability into a binary prediction.\n    /// * `class_reduction` - [Class reduction](ClassReduction) type.\n    #[allow(dead_code)]\n    pub fn multilabel(threshold: f64, class_reduction: ClassReduction) -> Self {\n        Self::new(ClassificationMetricConfig {\n            decision_rule: DecisionRule::Threshold(threshold),\n            class_reduction,\n        })\n    }","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-train/src/metric/recall.rs#L45-L81","documentation":"Config validation in `PrecisionRecallMetric`/`ClassificationMetricConfig`: `top_k` of zero was supplied to the multiclass recall constructor; a zero top-k cannot select any predicted label, so construction panics.","triggerScenarios":"Thrown at crates/burn-train/src/metric/recall.rs:63 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass top_k >= 1 (typically 1)","Validate top_k before metric construction","Use the threshold-based binary constructor when applicable"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}