4.4.16Alignment, Prompting & RAG

Evaluation of LLMs (benchmarks, LLM-as-judge)

3,308 words15 min readdifficulty · medium

Core Problem: The Evaluation Gap

Language model evaluation faces three challenges:

  1. Capability diversity: LLMs do everything from math to creative writing to code
  2. Output subjectivity: "Good" varies by task (factual vs. creative vs. helpful)
  3. 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 |

Figure — Evaluation of LLMs (benchmarks, LLM-as-judge)

Deriving Pass@k from First Principles

Problem: Model generates kk code samples per problem. What's the probability ≥1 is correct?

Setup:

  • nn = total problems
  • cc = problems where≥1 of kk samples passed all tests
  • pp = true probability a single sample is correct (unknown)

Derivation: Pass@k=P(≥1 correct in k samples)\text{Pass@}k = \mathbb{P}(\text{≥1 correct in } k \text{ samples})

Why subtract? Easier to compute complement: =1P(all k wrong)= 1 - \mathbb{P}(\text{all } k \text{ wrong})

If samples are independent: =1(1p)k= 1 - (1-p)^k

But we don't know pp! Estimate from data: p^=cn\hat{p} = \frac{c}{n}

Why this estimator? Maximum likelihood: observed success rate = best guess of true rate.

Final formula: Pass@k=1(1cn)k\boxed{\text{Pass@}k = 1 - \left(1 - \frac{c}{n}\right)^k}


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:

  • nn = total comparisons
  • aa = agreements (judge and human pick same winner)
  • dd = disagreements

Cohen's Kappa (accounts for chance agreement):

κ=pope1pe\kappa = \frac{p_o - p_e}{1 - p_e}

Where:

  • pop_o = observed agreement = an\frac{a}{n}
  • pep_e = expected agreement by chance

Why subtract chance? Random guessing gets ~50% agreement in binary choice. We want agreement beyond luck.

Deriving pep_e: If human picks A with probability pAp_A and judge picks A with probability qAq_A: pe=pAqA+pBqBp_e = p_A \cdot q_A + p_B \cdot q_B

Why product? Probability both pick A by chance = (prob human picks A) × (prob judge picks A), assuming independence.

Example calculation:

  • 100 comparisons, 80 agreements → po=0.80p_o = 0.80
  • Human picks A 60% of time, judge picks A 55% of time
  • pe=0.60×0.55+0.40×0.45=0.33+0.18=0.51p_e = 0.60 \times 0.55 + 0.40 \times 0.45 = 0.33 + 0.18 = 0.51
  • κ=0.800.5110.51=0.290.49=0.59\kappa = \frac{0.80 - 0.51}{1 - 0.51} = \frac{0.29}{0.49} = 0.59 (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 d=rtd = rt)

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 κ=0.68\kappa = 0.68 (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?
A standardized dataset with tasks and ground-truth answers designed to measure specific capabilities (e.g., MMLU for knowledge, HumanEval for coding)
What does Pass@k measure in code generation benchmarks?
The probability that at least one of k generated code samples passes all unit tests for a programming problem

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?
Using a strong language model (like GPT-4) to evaluate another model's output when ground truth is unavailable or subjective (creative tasks, open-ended QA, conversational quality, alignment)
What are the two main LM-as-judge setups?
1) Pairwise comparison: judge picks better response between two outputs (A vs B or Tie), 2) Absolute scoring: judge rates output on multiple criteria (1-10 scales for accuracy, helpfulness, safety)
What is Cohen's Kappa and why is it better than simple agreement?
κ = (p_o - p_e)/(1 - p_e) where p_o is observed agreement and p_e is expected chance agreement. It accounts for random agreement—if judges agree 80% but chance is 50%, kappa reveals true beyond-chance consensus
What does MMLU benchmark measure and how?
Massive Multitask Language Understanding: 14k multiple-choice questions across 57 subjects (STEM, humanities, social sciences). Measures broad factual knowledge, scored by accuracy
What does GSM8K test that MMLU doesn't?
Multi-step reasoning ability (not just memorization). GSM8K has 8,500 grade-school math word problems requiring chain-of-thought to solve, tests mathematical reasoning process
What is benchmark contamination (overfitting) and why is it a problem?
When models have seen test set examples during training (data leakage), they memorize answers instead of learning to reason. High scores don't reflect true capability—performance drops on reworded versions of same problems
What are three systematic biases in LLM judges?
1) Position bias: prefer response A or B based on order (not content), 2) Verbosity bias: favor longer responses even if less accurate, 3) Self-preference: rate their own outputs higher than competing models
How do you mitigate position bias in LM-as-judge?
Randomize the order of responses A and B, then average judgments over both orderings. If swapping changes the verdict, the bias is exposed
What is Goodhart's Law in the context of LLM benchmarks?
"When a measure becomes a target, it ceases to be a good measure." Optimizing specifically for benchmark scores leads to gaming metrics (e.g., verbose but unhelpful responses score high but don't help users)
What is MT-Bench and what capability does it test?
Multi-Turn Benchmark: 80 conversations across 8 categories (writing, coding, reasoning, roleplay, etc.) with GPT-4 as judge. Tests conversational ability and context tracking across multiple turns, not just single-shot QA
What is AlpacaEval's evaluation metric?
Win rate: percentage of time a model's response is preferred over a reference baseline (GPT-4-Turbo) across 805 diverse instructions, based on LM judge comparisons
Why can't you rely on a single benchmark to evaluate an LM?
Different benchmarks measure different capabilities (knowledge vs reasoning vs coding). A model might excel at memorization (MMLU) but fail at multi-step math (MATH dataset). Need diverse suite to capture capability profile, not single "IQ" score
How would you validate an LLM-as-judge before trusting it at scale?
1) Collect human expert judgments on a subset (50-200 examples), 2) Compute agreement metrics (Cohen's kappa), 3) Analyze disagrement patterns to catch systematic biases, 4) Use multiple judge models and check consensus, 5) Randomize response order to expose position bias

Concept Map

challenge

challenge

challenge

solved by

solved by

handles

handles

scales past

needs

MMLU

HumanEval

GSM8K

runs

uses

LLM Evaluation Gap

Capability Diversity

Output Subjectivity

Human Eval Cost

Automated Benchmarks

LM-as-Judge

Ground-Truth Dataset

Accuracy

Pass@k Metric

Exact Match

Hidden Test Cases

Stronger Model Grades

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

Go deeper — visual, from zero

Test yourself — Alignment, Prompting & RAG

Connections