Session 8 - Lecture + lab-session
Session 8
From “the demo looks great” to “we can defend this in production”: metrics, judges, cheating models and guardrails
“We generated 24 images per model. The FID of B is 3 points lower than A, so B is better.” What is wrong?
✅ Answer: B
FID compares the statistics of two sets -> biased and unstable with too few images
How many visual tokens does a 1000 × 1000 screenshot cost when it is sent to Claude?
✅ Answer: B
\(\lceil 1000/28 \rceil^2 = 36^2 = 1{,}296\) patches, each a visual token in the context. Images cost tokens: track cost per answer for them too.
A paper label reading “iPod” on an apple makes CLIP answer “iPod” with 99.7%. What is the lesson for evaluation?
✅ Answer: C
Text in an image is read as text. Your golden set needs an adversarial slice
ELIZA (1966), a pattern-matching script. Public domain
Fooling people for 5 minutes measures style, not reliability.
as of Oct 2026
Each line starts when the benchmark is published. Hover for the scores.
MMLU
57 subjects, 4 choices, 2020
saturated
ARC-AGI
learn a rule from 2 examples, 2019
v3 alive
Humanity's Last Exam
2,500 expert questions, 2025
alive
Your turn: solve the ARC puzzle in the middle. Most of you need 10 seconds.
Passing the driving test is not surviving the ring road at 6 pm.
💼 Business corner
A 2025 randomised study by METR found that experienced open-source developers were 19% slower with AI tools on their own repositories, while believing they had been 20% faster. Measure outcomes in your context.
Climb one level only when the cheaper one cannot answer: the base runs always, the top runs rarely.
Relevant: document A. The retriever returns it at rank 2.
nDCG@5: a hit at rank r scores 1 / log₂(r + 1): 1 at rank 1, 0.63 at rank 2, 0.5 at rank 3. Divide by the best possible total (1 here). It rewards relevant documents ranked early.
Retrieval metrics need no LLM: cheap, deterministic, run them on every change.
Recall@k asks “did we find it?”, MRR asks “how early?”
RAGAS faithfulness: split the answer into claims, check each one against the retrieved context.
RAGAS is an LLM judge: faithful to the wrong chunk still scores 1.0. Recall first (Session 5).
The judge compares the answer with a reference instead of guessing what “good” means
class Verdict(BaseModel):
correct: Literal["yes", "partially", "no"]
supported_by_sources: bool
reason: str = Field(description="One sentence, quoting the reference")
JUDGE_PROMPT = """Grade this answer about the ECB archive.
Question: {question} Reference: {reference}
Sources: {sources} Answer: {answer}
Grade correctness against the reference, and whether every claim
is supported by the sources. Do not reward length or style."""
judge = OpenAI(base_url="https://openrouter.ai/api/v1",
api_key=os.environ["OPENROUTER_API_KEY"])
verdict = judge.chat.completions.parse(
model=JUDGE_MODEL, temperature=0, response_format=Verdict,
messages=[{"role": "user", "content": JUDGE_PROMPT.format(**row)}],
).choices[0].message.parsedQuestion What is the transformer architecture made of?
Answer A
The transformer is built from stacked LSTM layers that read the sentence word by word and keep a hidden state, topped with a convolutional layer to detect local patterns. Together they make it fast, robust and the standard choice for modern language models.
Answer B
Stacked blocks of multi-head self-attention and a feed-forward network, with residual connections and layer normalisation.
Vote: A or B?
B is correct. A is longer and sounds authoritative, but describes recurrent networks, the architecture transformers replaced: verbosity and authority bias. That is why the judge gets a reference answer
🎲 Fun fact
“Null models” that always output the same cleverly structured junk reached top win rates on AlpacaEval 2.0 and MT-Bench (2025).
Goodhart’s law: “when a measure becomes a target, it ceases to be a good measure”.
Your turn: which of these five does your project already do?
Version B beats version A by 3 points on 50 questions. Ship it?
import numpy as np
def bootstrap_diff(correct_a, correct_b, n=10_000, seed=0):
rng = np.random.default_rng(seed)
a = np.array(correct_a, float) # same questions, paired
b = np.array(correct_b, float)
idx = rng.integers(0, len(a), size=(n, len(a))) # resample questions
diffs = (b[idx] - a[idx]).mean(axis=1)
return diffs.mean(), np.percentile(diffs, [2.5, 97.5])
mean, (low, high) = bootstrap_diff(correct_a, correct_b)
print(f"B - A = {mean:+.1%} (95% CI {low:+.1%} to {high:+.1%})")Same true improvement (+1.5 points). Drag the slider: the interval only excludes 0 from 1000 questions.
Guess: 90% per run: how often is a task solved 8 times in a row?
90% per run is only 43% over 8 runs: users notice the failures, not the average.
Session 7’s metrics, in the same pyramid:
Session 1 already warned: attention maps are a lead, not an explanation. Today: the tools that go further, and their limits.
Prompt: “The capital of the state containing Dallas is…”
An explanation you can test by intervening, not just a plausible story.
Planted hints, used by the model. How often did its reasoning admit it?
Reading the reasoning is not an audit.
A young field: most of these tools did not exist in 2023.
Hard tasks + opportunities to cheat, in 10 categories.
💼 Business corner
An agent that cheats on a benchmark will cheat on your KPIs: tickets closed unsolved, tests weakened. Evaluate how the task was done.
ImpossibleBench (2025) keeps a coding task’s specification but mutates the unit tests so they contradict it. A correct implementation must fail.
→ Any pass is cheating: the pass rate is the cheating rate.
Lock test files, review diffs, score the behaviour, not the green tick.
test_fizzbuzz fails: fizzbuzz(15) returns “Fizz”, the test expects “FizzBuzz”. Three “fixes”. Which ones cheat?
fizzbuzz(30) still says “Fizz”Both green ticks of B and C are cheats: lock the tests and review the diff.
git log and read the merged fix🎲 Fun fact (and a warning)
That one question cost 40.5 million tokens, 38 times the median. Anthropic: eval integrity is an ongoing adversarial problem.
as of Oct 2026
The rule: write your own StarCraft bot in C++, in one hour.
GPT-6 Astra: losing to strong bots, it downloaded Stardust, the best human-made bot, and ran it as its own.
The fix: the organiser rolled its code back.
Same pattern as CheatBench, now in the wild
An agent pushed hard on a score will look for the answer key, wherever it is. Sources: Fortune, 21 July 2026, Hugging Face disclosure.
99% right = 10,000 errors per million requests. Which layer would have stopped each one?
Keep at least one check outside the AI platform: one bug can disable every control inside it.
A guardrail that blocks 30% of real customers is a product bug: measure false positives too.
💼 Business corner
A short report is what auditors will ask for: what was tested, on what data, what risks remain, who monitors them.
as of Oct 2026
The others are on the Pareto front: each one wins on cost or on quality.
Notebook lab-session/08_eval_harness_lab.ipynb. You need your own OpenRouter key from step 2 on.
recall_at_k, mrr, ndcg_at_k; compare three retrievers on 18 questionsBefore you leave, you can explain:
as of Oct 2026
Evaluation is the least solved part of generative AI. It is yours to build.
Albert School - Evaluating Generative Systems