{"record":{"id":"46b6ce0326c90e03","repo":"keras-team/keras","slug":"num-labels-is-needed-only-when-multi-label-is","errorCode":null,"errorMessage":"`num_labels` is needed only when `multi_label` is True.","messagePattern":"`num_labels` is needed only when `multi_label` is True\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/metrics/confusion_metrics.py","lineNumber":1286,"sourceCode":"        self.multi_label = multi_label\n        self.num_labels = num_labels\n        if label_weights is not None:\n            label_weights = ops.array(label_weights, dtype=self.dtype)\n            self.label_weights = label_weights\n\n        else:\n            self.label_weights = None\n\n        self._from_logits = from_logits\n\n        self._built = False\n        if self.multi_label:\n            if num_labels:\n                shape = [None, num_labels]\n                self._build(shape)\n        else:\n            if num_labels:\n                raise ValueError(\n                    \"`num_labels` is needed only when `multi_label` is True.\"\n                )\n            self._build(None)\n\n    @property\n    def thresholds(self):\n        \"\"\"The thresholds used for evaluating AUC.\"\"\"\n        return list(self._thresholds)\n\n    def _build(self, shape):\n        \"\"\"Initialize TP, FP, TN, and FN tensors, given the shape of the\n        data.\"\"\"\n        if self.multi_label:\n            if len(shape) != 2:\n                raise ValueError(\n                    \"`y_pred` must have rank 2 when `multi_label=True`. \"\n                    f\"Found rank {len(shape)}. \"\n                    f\"Full shape received for `y_pred`: {shape}\"","sourceCodeStart":1268,"sourceCodeEnd":1304,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/metrics/confusion_metrics.py#L1268-L1304","documentation":"Raised by keras.metrics.AUC's __init__ when num_labels is supplied while multi_label=False. num_labels only defines the output shape [None, num_labels] in multi-label mode; for single-label AUC it is rejected.","triggerScenarios":"keras.metrics.AUC(num_labels=3) without multi_label=True; copying a multi-label AUC config and dropping only the multi_label flag.","commonSituations":"Adapting multi-label example code to binary problems; leftover config keys from earlier experiments.","solutions":["Add multi_label=True if you have a (batch, num_labels) output with independent per-label AUCs.","Remove num_labels for single-label/binary AUC.","Treat multi_label and num_labels as a paired config option."],"exampleFix":"# before\nauc = keras.metrics.AUC(num_labels=3)\n\n# after (multi-label):\nauc = keras.metrics.AUC(multi_label=True, num_labels=3)\n# after (binary):\nauc = keras.metrics.AUC()","handlingStrategy":"validation","validationCode":"if num_labels is not None and not multi_label:\n    raise ValueError('num_labels requires multi_label=True')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat multi_label and num_labels as a paired option in config schemas.","Remove stale keys when adapting example code."],"tags":["keras","metrics","auc","multi-label","argument-misuse"],"backgroundTag":"conflicting-arguments","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}