rohitg00/ai-engineering-from-scratch · error · ValueError

unknown scale

Error message

unknown scale {self.scale!r}

What it means

MetricSpec.validate guard: the scale field is neither LINEAR nor LOG, so the evaluator cannot know whether to log-transform metric values before statistics.

Solutions

  1. Set scale to the LINEAR or LOG constant exactly
  2. Use LOG only for strictly positive metrics such as perplexity
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phases/19-capstone-projects/53-result-evaluator/code/main.py:50 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/27afc84a0b24c8dc. Report an issue: GitHub.

Appendix: source

Thrown at phases/19-capstone-projects/53-result-evaluator/code/main.py:50

    construct lightweight instances directly so the evaluator can be tested
    in isolation.
    """
    spec_id: str
    terminal: str
    metrics: dict


@dataclass
class MetricSpec:
    name: str
    direction: str = HIGHER
    scale: str = LINEAR

    def validate(self) -> None:
        if self.direction not in (HIGHER, LOWER):
            raise ValueError(f"unknown direction {self.direction!r}")
        if self.scale not in (LINEAR, LOG):
            raise ValueError(f"unknown scale {self.scale!r}")


@dataclass
class Verdict:
    hypothesis_id: int
    metric: str
    direction: str
    scale: str
    candidate_mean: float
    baseline_mean: float
    improvement: float
    p_value: float | None
    significance_threshold: float
    improvement_threshold: float
    verdict: str
    rationale: str

    def to_dict(self) -> dict:

View on GitHub (pinned to 39ea8a1c6d)