AI Engineer Portal
Your personal operating system for career transition.
Exercise
Implement a judge calibration pipeline
Implement a Judge Calibration Pipeline
You have an LLM-as-judge that scores RAG responses for faithfulness, but you don't know if it agrees with humans. Build a calibration pipeline that measures how well the judge aligns with human labels and flags when calibration degrades.
Requirements
-
JudgeCalibrationRundataclass: storescase_id,judge_score,human_score,dimension(faithfulness/relevance/helpfulness), andtimestamp. -
compute_calibration_metrics(runs: list[JudgeCalibrationRun]) -> dictthat returns:agreement_rate: fraction of cases whereabs(judge_score - human_score) <= 0.2mean_absolute_error: averageabs(judge_score - human_score)bias: mean ofjudge_score - human_score(positive = judge rates higher than humans)cohens_kappa: Cohen's Kappa treating scores >= 0.7 as "pass" and < 0.7 as "fail"by_dimension: the above metrics broken down per dimension
-
is_calibration_healthy(metrics: dict) -> tuple[bool, list[str]]that returns(True, [])when calibration is acceptable, or(False, [reason, ...])when it fails. Flag when:agreement_rate < 0.75,mean_absolute_error > 0.25, orabs(bias) > 0.15. -
A standalone
cohens_kappa(predicted: list[bool], actual: list[bool]) -> floatfunction using the formula(p_o - p_e) / (1 - p_e)wherep_ois observed agreement andp_eis expected agreement by chance.
Constraints
- No external ML libraries. Pure Python only.
compute_calibration_metricsmust handle the case where a dimension has no data (skip it inby_dimension).- All scores are floats in [0.0, 1.0].
Evaluation / hard / Step 35 of 36
Evaluation and review loops
Separate the scoring logic from the interpretation logic. Your goal is not just a number; it is a useful next action.
- - Produces a useful signal, not decorative output
- - Makes regression review easier
- - Would support a benchmark or observability loop
- - Would this output help decide what to fix next?
- - Are important failure modes visible?
- - Does the score hide any ambiguity I should record?
Practice
Generate a variation
Generate a new exercise variation to deepen understanding or practice a related concept.
Attempt history
Recent submissions
Before you submit, decide what a strong answer should make obvious to the reviewer.
No attempts yet.