Evaluate LLMs and use them responsibly
Build evals for your task, use metrics like exact match and pass@k, and know the limits of benchmarks and LLM judges.
- Design a task-specific evaluation set
- Compute exact match and pass@k
- Recognize benchmark contamination and LLM-judge biases
Public benchmarks tell you how a model does on someone else’s test. For your product you need evals: a set of realistic inputs with a way to grade outputs, run every time you change the model, prompt or tools.
Grading options, from strict to flexible:
- Exact match (after normalizing case, punctuation and articles) for short factual answers.
- Execution for code: run the tests. pass@k (Chen et al., 2021) is the chance that at least one of k samples passes.
- Rubrics graded by people or by an LLM judge for open-ended text.
LLM judges scale well but have known biases - favoring longer answers, the first option shown, or their own style - so check them against human labels before trusting them.
Try it
Up to 15 XPHow would you grade it?
Pick the most appropriate grading method for each task.
““What year was the Eiffel Tower completed?””
““Write a function that parses ISO dates””
““Draft a polite reply to an angry customer””
““Convert this SQL query to pandas””
““Classify this ticket as billing, bug or feature request””
from math import comb
n, correct, k = 10, 3, 1
print(1 - comb(n - correct, k) / comb(n, k))0.30000000000000004
Key takeaways
Build task-specific evals and rerun them on every change.
Exact match for short answers, execution for code, rubrics (human or LLM judge) for open text.
Watch for benchmark contamination and LLM-judge biases.
Lesson quiz
6 questions · pass with 5 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: write Python
Write Python in the editor and run it against sample inputs. Python runs locally in your browser using a WebAssembly runtime.
Normalized exact match
Each line is prediction|reference. Normalize both: lowercase, remove punctuation, remove the articles a/an/the, collapse spaces. Print match or miss per line, then exact match: M/N (P%) (whole percent).
- Four answers
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Compute pass@k
Each line is n c k: n samples were generated, c passed the tests. Print the unbiased with 3 decimals: pass@k = X.
- Three cases
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…