Skip to content
Streak:0Loading your progress…Sign in

Module 12 · Lesson 1 of 2

Datasets & metrics

If you can't measure it, you're guessing. Evals are unit tests for model behaviour. ~30 min

Lesson notes

An eval = a dataset of inputs (with expected outputs or grading criteria) + a way to run your system on them + a grader + a summary metric. Start with 20–50 hand-written examples covering the common cases *and* known failure modes; grow it from real production failures. Keep a held-out set you don't tune against.

Grader types, cheapest first: code-based (exact match, regex, JSON schema valid, contains citation) → model-based (LLM-as-judge with a rubric) → human review. Use the cheapest grader that's trustworthy for each criterion.

Retrieval metrics for RAG: recall@k (did any relevant doc make the top k?) and MRR (mean of 1/rank of the first relevant doc). Evaluate retrieval separately from generation — when answers are wrong you need to know which half failed.

Practice

  1. 1. Accuracy with a breakdown

    medium25 XP

    Write score(dataset, predict) where each example is {"input", "expected", "tag"}. Grade with normalised exact match (case-insensitive, whitespace-trimmed, collapse internal whitespace). If predict raises, count it as a failure with error recorded. Return {"accuracy": float(4dp), "by_tag": {tag: float(4dp)}, "failures": [{"input", "expected", "got"}]} where got is the prediction or "error: <ExceptionType>".

    Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor

  2. 2. recall@k and MRR

    medium25 XP

    Write retrieval_metrics(results, k) where results is a list of (retrieved_ids, relevant_ids) pairs. Return {"recall_at_k": ..., "mrr": ...} rounded to 4dp. recall@k = fraction of queries with at least one relevant id in the top k. MRR = mean of 1/rank (1-based) of the first relevant id in the full retrieved list, 0 if none.

    Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor