Building an Evaluation Set

Updated · 8 min read
hardPython 3.13aievaluationtestingpythondatasets

An evaluation set (also called a golden dataset) is a fixed list of test cases: realistic inputs, each with what a correct output must contain or do. It is used to score an AI application the same way every time, so results can be compared across versions.

This lesson builds the chapter's checkpoint: 50 questions for Campus Helper, with expected answers, and a score.

What Goes in an Evaluation Set

Fifty fixed cases, one repeatable score
Kind of caseDescriptionExample
TypicalIt is used to cover what people ask most"How much does the science lab cost?"
RewordedIt is used to test different phrasing for the same need"Do brothers and sisters get a discount?"
TrickyIt is used to test vague or emotional questions"My kid is sick today, what should I do?"
Should declineIt is used to test out-of-scope questions"Who won the football game last night?"

Creating the Set

Each case has a question and the text a correct answer must contain; None means the app should decline:

make_eval.py
import json
 
# (question, text the correct answer must contain); None means Campus Helper should decline
CASES = [
    ("How much does the science lab cost?", "$45"),
    ("What's the price of a field trip?", "$30"),
    ("Is there a charge for using the library?", "$15"),
    ("How much is tuition each month?", "$250"),
    ("Can I pay school fees online?", "parent portal"),
    ("Can I pay in cash?", "8 a.m. to 3 p.m."),
    ("What happens if I pay late?", "$10"),
    ("We can't afford the fees. Is there help?", "fee waiver"),
    ("Do brothers and sisters get a discount?", "10%"),
    ("Will I get a receipt after paying?", "emailed"),
    ("How much does it cost to join sports?", "$60"),
    ("What does graduation cost?", "$40"),
    ("When are applications due?", "March 1"),
    ("What documents do I need to apply?", "birth certificate"),
    ("How long is the admission interview?", "20 minutes"),
    ("When will we hear if my son got in?", "April"),
    ("Can my daughter start in the middle of the year?", "mid-year"),
    ("Is there an entrance exam for grade 11?", "placement test"),
    ("Do you need my child's shot records?", "Vaccination"),
    ("Can we visit the campus before applying?", "Tuesdays and Thursdays"),
    ("When does spring term start?", "January 12"),
    ("When does the fall term begin?", "August 18"),
    ("What time does school start in the morning?", "8:15"),
    ("Why do students leave early on Wednesdays?", "1:30"),
    ("When are final exams?", "May 18"),
    ("When are midterms?", "March"),
    ("When do the holidays start in December?", "December 21"),
    ("When is spring break?", "March 23"),
    ("When can I meet my child's teachers?", "October 16"),
    ("Is school open on the day after Thanksgiving?", "Thanksgiving"),
    ("What time is lunch?", "11:50"),
    ("When does the bus come in the morning?", "7:20"),
    ("My son lost his jacket. What happens to lost things?", "30 days"),
    ("Can students use phones in class?", "lockers"),
    ("Does the cafeteria have vegetarian food?", "vegetarian"),
    ("My kid is sick today, what should I do?", "attendance line"),
    ("Where can my son get help with homework?", "tutoring"),
    ("Can I ride my bicycle to school?", "rack"),
    ("I forgot my parent portal password.", "reset"),
    ("Is there a robotics club?", "robotics"),
    ("What is the school's policy on pets?", None),
    ("Who won the football game last night?", None),
    ("Can you write my history essay?", None),
    ("What's the weather in San Francisco tomorrow?", None),
    ("What is the capital of France?", None),
    ("Recommend a good movie for tonight.", None),
    ("How do I fix my car's engine light?", None),
    ("What stocks should I buy?", None),
    ("Tell me a joke about cats.", None),
    ("What's the best pizza place in Dallas?", None),
]
 
cases = [{"id": i + 1, "question": q, "must_contain": m} for i, (q, m) in enumerate(CASES)]
json.dump(cases, open("eval_set.json", "w"), indent=1)
print("Saved", len(cases), "cases:", sum(c["must_contain"] is not None for c in cases), "answerable,",
      sum(c["must_contain"] is None for c in cases), "should decline")
Output
Saved 50 cases: 40 answerable, 10 should decline

Example: Scoring Campus Helper

The system under test is the semantic-search version of Campus Helper from "Semantic Search": it answers with the closest FAQ entry, or declines when nothing scores at least 0.35. It needs faq.json from that lesson, and every number below is real.

run_eval.py
import json
 
from sentence_transformers import SentenceTransformer
 
DECLINE = "Sorry, I can only answer questions about this school. Please contact the school office."
texts = [item["text"] for item in json.load(open("faq.json"))]
cases = json.load(open("eval_set.json"))
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
vectors = model.encode(texts, normalize_embeddings=True)
 
def campus_helper(question, threshold=0.35):
    """The system under test: answer with the closest FAQ entry, or decline."""
    scores = vectors @ model.encode(question, normalize_embeddings=True)
    best = int(scores.argmax())
    return texts[best] if scores[best] >= threshold else DECLINE
 
def run_eval(threshold=0.35):
    results = []
    for case in cases:
        answer = campus_helper(case["question"], threshold)
        expected = case["must_contain"]
        passed = answer == DECLINE if expected is None else expected in answer
        results.append({**case, "answer": answer, "passed": passed})
    return results
 
if __name__ == "__main__":
    results = run_eval()
    answerable = [r for r in results if r["must_contain"]]
    off_topic = [r for r in results if not r["must_contain"]]
    print(f"Score: {sum(r['passed'] for r in results)}/{len(results)}")
    print(f"  Answered correctly: {sum(r['passed'] for r in answerable)}/{len(answerable)}")
    print(f"  Declined correctly: {sum(r['passed'] for r in off_topic)}/{len(off_topic)}")
    print("Failures:")
    for r in results:
        if not r["passed"]:
            print(f"  #{r['id']} {r['question']}\n      got: {r['answer'][:70]}")
Output
Score: 44/50
  Answered correctly: 35/40
  Declined correctly: 9/10
Failures:
  #8 We can't afford the fees. Is there help?
      got: You can pay fees online by card or bank transfer through the parent po
  #16 When will we hear if my son got in?
      got: Sorry, I can only answer questions about this school. Please contact t
  #17 Can my daughter start in the middle of the year?
      got: Spring term starts on January 12 and ends on May 29.
  #20 Can we visit the campus before applying?
      got: International students need a valid student visa before enrollment.
  #36 My kid is sick today, what should I do?
      got: Sorry, I can only answer questions about this school. Please contact t
  #41 What is the school's policy on pets?
      got: The school is closed on Thanksgiving Day and the day after.

Explanation: run_eval() asks Campus Helper every question and marks a case passed if the answer contains the expected text, or, for off-topic cases, if it declined. Campus Helper scores 44/50. The failures show real weaknesses: a family asking for financial help gets payment instructions; "visit the campus" matches "student visa"; and two answerable questions are declined because no entry scored high enough.

Common Mistakes

Only easy questions. Include reworded, tricky and out-of-scope cases.

Changing the set to make the score go up. Fix the app, not the test, unless the expected answer was wrong.

Expected answers that are too strict or too loose. "Contains $45" works for fees; open-ended answers need the methods in the next lesson.

Interview Corner

What is a golden dataset?

A fixed, versioned set of realistic test inputs with expected outputs, used to score an AI application consistently across changes.

What kinds of cases belong in an evaluation set?

Typical questions, reworded versions, tricky edge cases, and cases the system should refuse, ideally drawn from real user questions and past failures.

Practice

Exercise: fix a failure. Add a sentence to the FAQ entry about fee waivers, such as "Help is available if you can't afford the fees." Rerun the evaluation. Does case #8 pass now, and did any other case change?

Check your understanding:

  1. What does must_contain = None mean?
  2. Why write expected answers before running the app?
  3. Which failure shows a decline when there should be an answer?

Quick check: evaluation sets

4 questions
1How many of the 10 off-topic questions did Campus Helper decline?
2Why write the expected answer before running the app?
3What did "Can we visit the campus before applying?" return?
4A user reports a wrong answer. What do you add to the set?

Key Takeaways

Quick reference

PartIn this lesson
Caseseval_set.json, 50 questions
Expected answermust_contain, or None to decline
Runnerrun_eval(threshold)
ScorePassed cases out of 50

Was this tutorial helpful?

Lesson 110 of 186