rohitg00/ai-engineering-from-scratch · error · ValueError
unknown metric_name: {metric_name}
Error message
unknown metric_name: {metric_name} What it means
Error "unknown metric_name: {metric_name}" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at phases/19-capstone-projects/71-classical-metrics/code/main.py:159
"bleu_4": "per_target_max",
"rouge_l": "per_target_max",
}
def score(metric_name: str, prediction: str, targets: list[str]) -> float:
if not targets:
return 0.0
if metric_name == "exact_match":
return exact_match(prediction, targets)
if metric_name == "accuracy":
return accuracy(prediction, targets)
if metric_name == "f1":
return max(f1_score(prediction, t) for t in targets)
if metric_name == "bleu_4":
return max(bleu4(prediction, t) for t in targets)
if metric_name == "rouge_l":
return max(rouge_l(prediction, t) for t in targets)
raise ValueError(f"unknown metric_name: {metric_name}")
def corpus_mean(scores: list[float]) -> float:
if not scores:
return 0.0
return float(np.mean(scores))
def corpus_bleu(predictions: list[str], references: list[str], max_n: int = 4) -> float:
if len(predictions) != len(references):
raise ValueError("predictions and references must align")
if not predictions:
return 0.0
total_cand_len = 0
total_ref_len = 0
clipped_sums = [0] * max_n
total_sums = [0] * max_n
for cand_text, ref_text in zip(predictions, references):View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at phases/19-capstone-projects/71-classical-metrics/code/main.py:159 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/6d9822e5819a3fb5.
Report an issue: GitHub.