teaching_llm_applications

Week 11 — Evaluation, Safety, and Ethics

Lecture Overview

Building capable LLM systems is only half the challenge. This week we ask: how do we know if our system is actually good? How do we measure, improve, and ensure safety? And what are the broader ethical responsibilities of LLM practitioners?


1. Why Evaluation Is Hard

LLM outputs are:


2. Automatic Evaluation Metrics

2.1 Reference-Based Metrics

Compare model output to a gold-standard reference.

Metric What it measures Limitations
BLEU N-gram overlap (translation) Misses meaning; brittle
ROUGE N-gram recall (summarisation) Same issues
METEOR Alignment + synonyms Better than BLEU
BERTScore Contextual embedding similarity More robust; still imperfect
BLEURT Fine-tuned regression model Expensive
from evaluate import load

rouge = load("rouge")
results = rouge.compute(
    predictions=["The cat sat on the mat."],
    references=["A cat is sitting on a mat."]
)
print(results)   # {'rouge1': 0.73, 'rouge2': 0.40, 'rougeL': 0.73, ...}

2.2 Reference-Free Metrics


3. Benchmarks

3.1 General Knowledge and Reasoning

Benchmark Task Notes
MMLU Multiple-choice, 57 subjects Knowledge breadth
HellaSwag Sentence completion Common sense
ARC (Easy/Challenge) Science QA Reasoning
WinoGrande Coreference resolution Language understanding
TruthfulQA Truthfulness Hallucination

3.2 Code

Benchmark Task
HumanEval Python function synthesis
MBPP Simple Python programming
SWE-bench Real GitHub issue resolution

3.3 Reasoning

Benchmark Task
GSM8K Grade school mathematics
MATH Harder mathematics
BBH (BIG-Bench Hard) Diverse hard tasks
ARC-AGI Abstract visual reasoning

3.4 Safety

Benchmark Task
TruthfulQA Avoids known false beliefs
HarmBench Resistance to jailbreaks
BBQ Social bias in QA

Benchmark Contamination

If a model’s training data contains benchmark questions, reported scores are inflated. This is a pervasive problem — be sceptical of leaderboard numbers.


4. LLM-as-Judge

Use a capable LLM (e.g. GPT-4, Claude) to evaluate outputs. Provide a rubric:

You are an evaluation assistant. Rate the following answer on a scale of 1–5 for:
- Factual accuracy
- Helpfulness
- Clarity

Question: {question}
Answer: {answer}

Respond ONLY with JSON: {"factual_accuracy": int, "helpfulness": int, "clarity": int, "rationale": string}

5. Hallucination

Hallucination: the model generates plausible-sounding but factually incorrect information with apparent confidence.

Types

Type Example
Factual hallucination Inventing a citation, fake statistics
Intrinsic hallucination Answer contradicts the provided context
Extrinsic hallucination Answer goes beyond the context with unsupported claims

Causes

Mitigations


6. Bias and Fairness

LLMs trained on web text absorb societal biases:

Measurement

Mitigations


7. AI Safety and Alignment

7.1 Short-Term Safety Concerns

7.2 Longer-Term Alignment

7.3 Frameworks


8. Privacy and Data

Best practices:


9. Responsible Deployment Checklist

Before deploying an LLM application:


10. Practical This Week

See practicals/week11_practical.py:


11. Further Reading


Discussion Questions

  1. Why is BLEU a poor metric for open-ended generation? What would you use instead?
  2. Describe three types of hallucination and a mitigation for each.
  3. A hospital wants to deploy an LLM for clinical triage. List five evaluation criteria and how you would measure each.
  4. What is Goodhart’s Law and why is it relevant to LLM evaluation?