Module: L2-M08 (capstone) · Duration: ~8 hours (estimate) · Previous: Milestone 1 · Next: Milestone 3
1. Introduction
Every number in milestone 3 is only trustworthy if the data and the measurement are trustworthy. Milestone 2 builds the foundation: a dataset manager that takes a candidate pool with defects, rejects the items that cannot be used and records the reason;
a set of deterministic metric functions that check each answer; and a runner that runs stable and rc on the dataset and produces records that repeat byte for byte. Output: a versioned dataset with a manifest,
six items written by you, and a platform that runs up to the end of the runner step.
2. Objectives
- Reject (not silently repair) wrong, duplicate and contaminated items in
data/pool.jsonl, each rejected item with a reason code. - Split dev/test by item id, hash the dataset and write the manifest.
- Compute the coverage matrix and write the
own-*items that fill the missing cells. - Implement deterministic metric functions that are correct on boundary cases and raise an error on a malformed check instead of letting it pass.
- Implement a deterministic, offline runner that skips no item, and read the
rcdefects that show up in the counts.
3. Prerequisites
- The milestone 1 design document (you have decided who grades which clause).
- Quick review: L2-M02 (coverage, data contamination, manifest), L2-M03 (metric functions, guard), L2-M01-L02 (fail closed).
4. Parts of milestone 2
4.1 Reject, never repair
An item in the pool can be wrong in many ways. The dataset manager does not guess the intent of the author: it rejects the item and says why. The error codes are in requirements.md section D (BAD_SLICE,
BAD_GRADE, BAD_ARGS, MISSING_FIELD:<field>, PII_NOT_ALLOWED ...); valid args follow the table in section B. Two decisions worth thinking through:
- Rule order. Structural errors first, then duplicate id, then duplicate question, then data contamination. An item that is already structurally wrong does not need to be checked for duplication or contamination: its reason is the structural codes, not a random duplicate code.
- A duplicate id means reject all. Two rows with the same
idbut different content: there is no way to know which row is right, so reject both and let a person look again.
validate_row never raises an error because of bad data: it returns a list of codes. Bad data is normal for a candidate pool, not an exception of the program. What it does not check:
whether the question is good, whether checks expresses the right intent.
4.2 Duplicates and data contamination
A duplicate means the same question after normalization. util.normalize (provided) converts to NFC, removes hidden characters, lowercases and collapses whitespace; two sentences that differ only in Unicode form or letter case are still one sentence.
Keep the item whose id sorts first and reject the rest.
Data contamination (L2-M02-L05): an item whose question already appears in the text the tutor "has seen" (data/corpus.jsonl) gives a falsely high score. The measure used here: the share of 5-word phrases of the question that appear in the corpus; at 1/2 or above, reject.
A sentence shorter than 5 words counts as one phrase as a whole. The condition "at 1/2 or above" is an edge case: exactly 1/2 is rejected, and you need a check for exactly that boundary. What the measure does not catch: paraphrased sentences,
and contamination from sources that are not in the text corpus you were given.
4.3 Split, hash, manifest and coverage
- Split by item id, fixed with a salt in
util.py(L2-M07-L01 on separating the selection items from the confirmation items).devis for development and choosing judge thresholds;testis for confirmation in milestone 3. - The dataset hash follows the formula in
requirements.mdsection D: row order must not change the result, and changing one character in one item must change the hash. - The manifest records the version, the hash, the number of items by slice and by split, the number of rejected items by code, and
coverage_ok. - Coverage (of the dataset, different from the coverage of a confidence interval) is a slice × grade matrix. The matrix must list the cells that equal 0 too; a cell missing from the dictionary is a cell you do not see. Run it on the clean pool and you will see which cells are sparse
(fewer than 3 items) and write
own-*items to fill them, followingrequirements.mdsection B.
Phone numbers in your items may only use the fake range 09000xxxxx (exactly 10 digits). An own-* item may only be placed in check, offtopic or safety: the judge only has rows for pool items, so an own-* item in concept or hint becomes a missing key and pulls the whole platform to ERROR. An own-* item goes through the same validate_row as every other item.
4.4 Deterministic metric functions
Each item has a list of checks; five types: contains_all, contains_none, number, number_absent, no_phone. General rules (L2-M03-L01, L2-M03-L02):
- A number must stand on its own, not attached to a digit, a
-,+,^sign or another letter. "0,75" is not in "10,75"; "5" is not in "-5" or "x5". A number is read as aFractionwith a decimal comma, not afloat(Fraction(1.1)does not equal exactly 11/10 because of binary floating point [R5]); "3.5" is not "3,5". - The text is normalized before comparing (NFC, hidden characters, uppercase), so a zero-width character cannot hide a forbidden phrase.
no_phone: a run of 9 or more digits after NFC normalization, removing hidden characters and removing separators (spaces, dots, hyphens, slashes, parentheses) between the digits. A zero-width character inserted in the middle of a number cannot hide a phone number; what it does not catch is digits written as words or interrupted by letters. The dataset uses the same rule forPII_NOT_ALLOWED.- A malformed check raises an error. An empty
termslist, an unknown type, avaluethat is not a number, or an emptychecksall raiseValueError. A check that is empty and always "passes" is the fastest way to get a falsely good score.
These functions check only what they state. An answer that passes all the checks can still be wrong in a way you have not written a check for; write those gaps into the design.
4.5 A deterministic runner
run_version(version, cases, seed, out_dir) calls tutor.reply, runs run_checks and writes records sorted by id together with the run's manifest (with a results_digest of all pass flags).
Three rules: no timestamp and no machine path in the files (so they can be rebuilt byte for byte); do not skip an item that cannot run (the error surfaces, it is not swallowed);
do not depend on the order of the input items. The runner runs both versions on every item (both dev and test); the comparison in milestone 3 uses only test.
When the run finishes, count the failed checks by (version, slice, check type): where rc fails and stable does not is where to look. Only after you have counted may you open tutor.py to explain the cause.
5. Hands-on: try each part on a small example
Create try_m2.py in the root folder of starter/, next to evalplatform/ (so that import evalplatform works):
from evalplatform import dataset, validators
good = {"id": "A1", "slice": "concept", "grade": 4, "kind": "concept", "question": "Giải thích phân số cho lớp 4.", "args": {"term": "phân số"},
"checks": [{"type": "contains_all", "terms": ["tử số"]}], "source": "authored", "pii_ok": False}
dup = {**good, "id": "B1", "question": "GIẢI THÍCH PHÂN SỐ CHO LỚP 4."}
phone = {**good, "id": "C1", "question": "Số của mình là 090 000 0123 nhé."}
res = dataset.clean_pool([good, dup, phone], [])
print([r["id"] for r in res["accepted"]])
print(res["rejected"])
print(validators.run_checks([{"type": "number", "value": "0,75"}, {"type": "no_phone"}], "Đáp số: 10,75. Gọi 0900000123"))
Output (copied from a real run with the reference solution, 2026-11-04, Python 3.14.6 and 3.12.14, identical results):
['A1']
[{'id': 'B1', 'codes': ['DUPLICATE_QUESTION']}, {'id': 'C1', 'codes': ['PII_NOT_ALLOWED']}]
{'0:number': False, '1:no_phone': False}
Then run the milestone 2 checks and build up to the end of the runner:
python -m pytest tests/test_m2_dataset.py tests/test_m2_validators.py
python -m evalplatform --out out
Once every milestone 2 function is done, the 81 checks in the two files above pass. The second command still stops at the milestone 3 judge step (exit code 3, message TODO(M3)): that is exactly the right place.
Open out/dataset/manifest.json and out/dataset/rejected.jsonl: does every rejected item have a reason code? Was any item rejected by mistake?
6. QA perspective
- What can go wrong in this milestone: repairing an item instead of rejecting it; normalization that is not enough so duplicates are missed; comparing numbers by substring; an empty check that lets everything pass; a coverage matrix missing the cells that equal 0; a rebuild that gives different results because of timestamps or order; your own items using a phone number that looks real.
- Ask yourself after each check: what does it not check? Write one line in the design.
7. Milestone 2 deliverables
- Code:
dataset.py,validators.py,runner.pyinevalplatform/. deliverables/own_cases.jsonl: at least 6own-*items, each valid, with checks that run on both versions.deliverables/dataset-notes.md: short notes on the rejected items and one limit of each check type (the grader reads it; the test suite does not check it).
Criteria: pass tests/test_m2_dataset.py and tests/test_m2_validators.py (AC2.1-AC2.23); the manifest has a hash; every problem planted in the pool is rejected with a reason.
8. Self-check questions
0/12 done · Results are kept in this browser only.
P01 · Short answer
Two rows of the pool have the same id but different content. What should the dataset manager do with them, and why not keep the row that "looks more right"?
P03 · Select all that apply
P04 · True or false
P05 · Fill in the blank
P06 · Put in order
P07 · Match
P08 · Spot the bug
The function below is a draft of run_version (§4.5). Two consecutive runs with the same input give two files that differ byte by byte. Find the bug.
import time
from evalplatform import util, validators
def run_version(version, cases, seed, out_dir):
tutor = util.load_tutor()
records = []
for case in sorted(cases, key=lambda c: c["id"]):
reply = tutor.reply(version, case, seed)
results = validators.run_checks(case["checks"], reply)
records.append({"version": version, "case_id": case["id"], "reply": reply,
"checks": results, "ran_at": time.strftime("%Y-%m-%d %H:%M:%S")})
util.write_jsonl(f"{out_dir}/runs/{version}.jsonl", records)
return recordsP09 · Essay
A teammate sees that item X9 has grade 7 and wants to "change it to 5 quickly, it is obviously a typo". Write 5-8 sentences to persuade the teammate that the dataset manager should reject that item instead of repairing it, and state the right handling after the rejection.
P10 · Recall
Lesson: L2-M02-L05P12 · Short answer
You write the item own-hint-1 in the hint slice to fill a sparse cell of the coverage matrix. What happens in milestone 3, and where should you put your own-* items?
9. Summary
- Bad data is rejected with a reason, not silently repaired; a duplicate id means reject all.
- Duplication and contamination are measured after normalization; the 1/2 boundary needs its own check.
- Deterministic metric functions check only what they state and raise an error on a malformed check.
- The deterministic runner: no timestamp, no skipped items, no dependence on order.
10. References
See this module's references.md.