Evaluation of LLMs (benchmarks, LLM-as-judge)
Core Problem: The Evaluation Gap
Language model evaluation faces three challenges:
- Capability diversity: LLMs do everything from math to creative writing to code
- Output subjectivity: "Good" varies by task (factual vs. creative vs. helpful)
- Human evaluation cost: Expert review doesn't scale to millions of outputs
Solution approach: Combine objective benchmarks (for measurable skills) with model-based judges (for subjective quality).
Part 1: Benchmark Evaluation
How Benchmarks Work
The pipeline:
Model → Prompt with task → Generate output → Compare to answer → Compute metric
Key benchmark types:
| Type | Measures | Example Metric | |------|----------|------|-----| | Multiple choice | Knowledge recall | MMLU (57 subjects) | Accuracy | | Code generation | Programming ability | HumanEval, MBPP | Pass@k (% passing tests) | | Math word problems | Reasoning | GSM8K, MATH Exact match | | Reading comprehension | Understanding | SQuAD, DROP | F1 score | | Instruction following | Alignment | MT-Bench, AlpacaEval | Win rate vs baseline |

Deriving Pass@k from First Principles
Problem: Model generates code samples per problem. What's the probability ≥1 is correct?
Setup:
- = total problems
- = problems where≥1 of samples passed all tests
- = true probability a single sample is correct (unknown)
Derivation:
Why subtract? Easier to compute complement:
If samples are independent:
But we don't know ! Estimate from data:
Why this estimator? Maximum likelihood: observed success rate = best guess of true rate.
Final formula:
Part 2: LLM-as-Judge
Why We Need It
Scenarios where benchmarks fail:
- Creative tasks: "Write a haiku about loneliness" (no ground truth)
- Open-ended QA: "Explain why the sky is blue" (many valid explanations)
- Conversational ability: Multi-turn dialogues (context-dependent quality)
- Alignment: Is the response helpful and safe? (subjective judgment)
Human evaluation problems:
- Expensive: $0.50–5 per rating, millions needed for large-scale tuning
- Slow: Days to weeks for crowdworker consensus
- Inconsistent: Inter-annotator agreement often 60–80%
Solution: Train/prompt a strong LM to mic human preferences.
How LM-as-Judge Works
Pairwise comparison setup (most common):
Prompt to judge:
---
Instruction: {user_question}
Response A: {model_1_output}
Response B: {model_2_output}
Which response is better? Consider accuracy, helpfulness, safety.
Choose: [[A]] or [[B]] or [[Tie]]
---
Judge outputs: "A"
Aggregate over many examples: Model 1 wins 65% vs Model 2 → 1 ranked higher.
Absolute scoring setup:
Rate this response on a scale of 1-10 for:
- Accuracy (factually correct?)
- Helpfulness (answers the question?)
- Safety (avoids harmful content?)
Response: {output}
Judge outputs: "Accuracy: 8, Helpfulness: 9, Safety: 10"
Deriving Agreement Metrics from First Principles
Problem: How well does the LM judge agree with humans?
Setup:
- = total comparisons
- = agreements (judge and human pick same winner)
- = disagreements
Cohen's Kappa (accounts for chance agreement):
Where:
- = observed agreement =
- = expected agreement by chance
Why subtract chance? Random guessing gets ~50% agreement in binary choice. We want agreement beyond luck.
Deriving : If human picks A with probability and judge picks A with probability :
Why product? Probability both pick A by chance = (prob human picks A) × (prob judge picks A), assuming independence.
Example calculation:
- 100 comparisons, 80 agreements →
- Human picks A 60% of time, judge picks A 55% of time
- (moderate agreement)
Part 3: Key Benchmarks in Practice
MMLU (Massive Multitask Language Understanding)
- What: 57 subjects (elementary math to professional law), 14k multiple choice questions
- Why it matters: Broad knowledge test, correlates with "feels smart" to users
- Limitation: Measures memorization, not reasoning depth
GSM8K (Grade School Math 8K)
- What: 8,500 grade-school word problems requiring multi-step reasoning
- Why it matters: Tests chain-of-thought, not just formula recall
- Example: "If a train travels 60 mph for 2.5 hours, how far does it go?" (requires )
HumanEval & MBPP (code generation)
- What: 164 (HumanEval) / 974 (MBPP) Python programming problems with unit tests
- Why it matters: Executable = objective correctness check
- Limitation: Tests algorithmic coding, not software engineering (design, debugging, collaboration)
MT-Bench (Multi-Turn Benchmark)
- What: 80 multi-turn conversations across 8 categories (writing, reasoning, math, coding, roleplay, extraction, STEM, humanities)
- Why it matters: Tests conversational ability + context tracking (real-world chat use)
- Evaluation: GPT-4 as judge, rates1-10 per turn
AlpacaEval
- What: 805 diverse instructions, compares model vs reference (GPT-4-Turbo)
- Why it matters: Measures instruction-following + user preference
- Metric: Win rate (% of time model preferred over baseline)
Part 4: Pitfalls & Limitations
Comprehensive Example: Evaluating a New Model
Scenario: You've fine-tuned LaMA-3-70B on medical data. How do you evaluate it?
Step 1: Benchmark suite
- MedQA (medical licensing exam questions): 78% (baseline: 72%, GPT-4: 86%)
- Interpretation: Above baseline, but not SOTA for medical reasoning
- PubMedQA (yes/no/maybe on research abstracts): 81% (baseline: 76%, GPT-4: 84%)
- Interpretation: Solid biomedical understanding
- HumanEval (general coding): 45% (baseline: 42%)
- Interpretation: Coding not harmed, but no improvement
Step 2: LM-as-judge (GPT-4) on500 custom medical queries
- Prompt: "You are an expert physician. Rate the response for accuracy, clinical relevance, and safety (1-10 each)."
- Results: Accuracy 7.8, Relevance 8.3, Safety 9.1(baseline: 7.2, 7.9, 8.8)
- Interpretation: Fine-tuning improved relevance + safety, small accuracy gain
Step 3: Human expert review (50 samples)
- Agreement with GPT-4 judge: Cohen's (substantial)
- Catch cases where judge was wrong: 4 responses had factual errors judge missed
- Interpretation: LLM judge reliable for screening, but critical decisions need humans
Step 4: A/B test in simulated clinic
- 20 physicians use model vs baseline for 100 patient questions
- Preference: 65% prefer fine-tuned model (AlpacaEval-style win rate)
- Qualitative: "More specific drug recommendations, fewer generic responses"
Conclusion: Model is production-ready for physician assistant role (not autonomous diagnosis). Benchmarks showed capability, judge showed quality improvement, humans validated safety.
Active Recall Practice
Recall Explain to a12-year-old
Imagine you built a super-smart robot that can answer questions, write stories, and even code. But how do you know if it's actually smart or just good at faking it?
Benchmarks are like school tests. You give the robot math problems, reading comprehension, coding challenges—stuff with clear right answers. If it scores 90% on the math test, you know it's good at math!
But what about creative stuff? If you ask it to write a story, there's no "right answer." So you get a smarter robot (like a robot teacher) to read the story and say if it's good. That's "LM-as-judge"—one AI grading another.
The trick is: sometimes the robot teacher is biased (likes long stories even if they're boring), and sometimes the robot memorized the test questions instead of learning. So you need lots of different tests and check if real people agree with the robot teacher.
Connections
- Chain-of-Thought Prompting: GSM8K/MATH benchmarks test CoT reasoning ability
- RLHF (Reinforcement Learning from Human Feedback): Human preference data trains reward models, similar to LM-judge setup
- Prompt Engineering Best Practices: Benchmark prompts must be carefully designed (zero-shot vs few-shot affects scores)
- RAG (Retrieval-Augmented Generation): Evaluation needs benchmarks for retrieval quality (recall, precision) + generation quality (faithfulness)
- Alignment Tax: High benchmark scores don't guarantee safety—need alignment-specific evals (TruthfulQA, BBQ bias benchmark)
- Few-Shot Learning: MT-Bench tests in-context learning across conversation turns
- Constitutional AI: Uses model-as-judge internally to filter harmful outputs during training
#flashcards/ai-ml
What are the three core challenges that make LM evaluation harder than traditional ML evaluation? :: 1) Capability diversity (models do many tasks), 2) Output subjectivity (no single "correct" answer for open-ended tasks), 3) Human evaluation cost (can't scale expert review to millions of outputs)
What is a benchmark in LM evaluation?
What does Pass@k measure in code generation benchmarks?
Derive the Pass@k formula from first principles :: Pass@k = P(≥1 correct in k samples) = 1 - P(all k wrong) = 1 - (1-p)^k where p is the probability a single sample is correct, estimated as c/n (correct solutions / total problems)
What is LM-as-judge and when is it used?
What are the two main LM-as-judge setups?
What is Cohen's Kappa and why is it better than simple agreement?
What does MMLU benchmark measure and how?
What does GSM8K test that MMLU doesn't?
What is benchmark contamination (overfitting) and why is it a problem?
What are three systematic biases in LLM judges?
How do you mitigate position bias in LM-as-judge?
What is Goodhart's Law in the context of LLM benchmarks?
What is MT-Bench and what capability does it test?
What is AlpacaEval's evaluation metric?
Why can't you rely on a single benchmark to evaluate an LM?
How would you validate an LLM-as-judge before trusting it at scale?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
LM evaluation ka problem ye hai ki traditional ML jaise simple nahi hai. Pehle toh accuracy dekh lete the — kitne test cases pass hue. Lekin LM toh essay likhta hai, poems banata hai, conversation karta hai. Ab batao "good poem" ko kaise measure karoge? Koi ek sahi answer nahi hai!
Isliye do tarike hai. Pehla, benchmarks — ye standardized tests hain jaise school mein hote hain. MMLU mein 57 subjects ke multiple choice questions hain (science se lekar law tak). HumanEval mein coding problems hain