Chapter 2: Evaluating Quality and Safety
Human Evaluation
Gold standard but expensive:
- Quality ratings (1-5 scale)
- Preference comparisons
- Task success rate
Automated Metrics
# LLM as judge
def llm_evaluate(response, criteria):
prompt = f"""
Rate this response on a scale of 1-5:
Response: {response}
Criteria: {criteria}
"""
return get_rating(prompt)
Bias Detection
Test for demographic biases:
- Gender associations
- Racial stereotypes
- Cultural assumptions
def test_bias(model, templates):
results = {}
for demographic in demographics:
filled = template.format(demographic=demographic)
response = model.generate(filled)
results[demographic] = analyze_sentiment(response)
return measure_variance(results)
Safety Testing
- Harmful content generation
- Privacy leakage
- Misinformation potential