{"record":{"id":"13f5ccc04f420b6d","repo":"rohitg00/ai-engineering-from-scratch","slug":"confidences-must-be-1-d","errorCode":null,"errorMessage":"confidences must be 1-D","messagePattern":"confidences must be 1-D","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/73-perplexity-calibration/code/main.py","lineNumber":61,"sourceCode":"            if n < 0:\n                raise ValueError(\"token_counts must be non-negative\")\n            total_nll += float(nll)\n            total_tokens += int(n)\n        if total_tokens == 0:\n            return cls(perplexity=float(\"nan\"), avg_neg_log_likelihood=0.0, total_tokens=0)\n        avg_nll = total_nll / total_tokens\n        return cls(perplexity=math.exp(avg_nll), avg_neg_log_likelihood=avg_nll, total_tokens=total_tokens)\n\n\ndef perplexity(neg_log_probs: Sequence[float], token_counts: Sequence[int]) -> float:\n    return PerplexityResult.from_token_nll(neg_log_probs, token_counts).perplexity\n\n\ndef _validate_probs(confidences: np.ndarray, correct: np.ndarray) -> None:\n    if confidences.shape != correct.shape:\n        raise ValueError(\"confidences and correct must have the same shape\")\n    if confidences.ndim != 1:\n        raise ValueError(\"confidences must be 1-D\")\n    if confidences.size == 0:\n        return\n    if float(confidences.min()) < 0.0 or float(confidences.max()) > 1.0:\n        raise ValueError(\"confidences must lie in [0, 1]\")\n    uniq = set(np.unique(correct).tolist())\n    if not uniq.issubset({0, 1, 0.0, 1.0, True, False}):\n        raise ValueError(\"correct must be 0/1 or boolean\")\n\n\ndef _bin_indices(confidences: np.ndarray, n_bins: int) -> np.ndarray:\n    edges = np.linspace(0.0, 1.0, n_bins + 1)\n    idx = np.searchsorted(edges, confidences, side=\"right\") - 1\n    idx = np.clip(idx, 0, n_bins - 1)\n    return idx\n\n\ndef expected_calibration_error(confidences: Sequence[float], correct: Sequence[int], bins: int = 10) -> tuple[float, int]:\n    conf = np.asarray(confidences, dtype=np.float64)","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/73-perplexity-calibration/code/main.py#L43-L79","documentation":"Error \"confidences must be 1-D\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/19-capstone-projects/73-perplexity-calibration/code/main.py:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}