{"record":{"id":"8b8e3317104abadb","repo":"rohitg00/ai-engineering-from-scratch","slug":"predictions-and-references-must-align","errorCode":null,"errorMessage":"predictions and references must align","messagePattern":"predictions and references must align","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/71-classical-metrics/code/main.py","lineNumber":170,"sourceCode":"        return accuracy(prediction, targets)\n    if metric_name == \"f1\":\n        return max(f1_score(prediction, t) for t in targets)\n    if metric_name == \"bleu_4\":\n        return max(bleu4(prediction, t) for t in targets)\n    if metric_name == \"rouge_l\":\n        return max(rouge_l(prediction, t) for t in targets)\n    raise ValueError(f\"unknown metric_name: {metric_name}\")\n\n\ndef corpus_mean(scores: list[float]) -> float:\n    if not scores:\n        return 0.0\n    return float(np.mean(scores))\n\n\ndef corpus_bleu(predictions: list[str], references: list[str], max_n: int = 4) -> float:\n    if len(predictions) != len(references):\n        raise ValueError(\"predictions and references must align\")\n    if not predictions:\n        return 0.0\n    total_cand_len = 0\n    total_ref_len = 0\n    clipped_sums = [0] * max_n\n    total_sums = [0] * max_n\n    for cand_text, ref_text in zip(predictions, references):\n        cand = tokenize(cand_text)\n        ref = tokenize(ref_text)\n        total_cand_len += len(cand)\n        total_ref_len += len(ref)\n        for n in range(1, max_n + 1):\n            clipped, total = _modified_precision(cand, ref, n)\n            clipped_sums[n - 1] += clipped\n            total_sums[n - 1] += total\n    if total_cand_len == 0:\n        return 0.0\n    log_p_sum = 0.0","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/71-classical-metrics/code/main.py#L152-L188","documentation":"Error \"predictions and references must align\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/19-capstone-projects/71-classical-metrics/code/main.py:170 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"}