Dataset versioning, contamination and privacy

Study time
≈ 2 h (estimate)
Needs
L2-M02-L04
Updated
2026-11-03

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L2-M02 · Duration: ~120 min (estimate, including the independent exercise) · Previous: L04 · Next: L2-M03-L01 (module Quality Metrics and Rubrics, not yet written)

1. Introduction

The previous four lessons built a dataset; this lesson keeps it trustworthy over time. A dataset lives: cases are added, edited, removed; someone puts part of it into a prompt or into training data; personal data needs deleting. If none of this is recorded, two pass rates at two points in time can no longer be compared and nobody knows why.

This lesson brings together three jobs: versions and the changelog (what changed, why, and a version number that reflects it), contamination (an evaluation case leaking into a place the system has already "seen" it, making the measurement optimistic) and privacy (reviewing for personal data before every release, and recording deliberate exceptions). The product of the lesson is a versioned dataset with a changelog and a release gate that code can check.

2. Learning objectives

  1. Compute the difference between two dataset versions (added, removed, content changed, metadata changed) and derive the required version bump from a stated rule.
  2. Split a dataset into dev and test with a hash of the id, and explain why this is stable when cases are added.
  3. Check contamination with n-gram overlap and state what it does not catch.
  4. Write a manifest with a changelog and a fingerprint, and run the release gate to catch a wrong manifest.
  5. Handle PII in the dataset with a justified exemption, and write a dataset card with a maintenance section.

3. Prerequisites and tools

  • L2-M01-L01: the dataset fingerprint (a hash of the content), used to know whether two results are comparable. This lesson extends it into a versioning rule.
  • L2-M02-L01 to L04: sources, PII, coverage, labels, synthetic data.
  • The code lab code-labs/l2-m02.

4. Concepts

4.1 A dataset is a versioned product

An eval result has meaning only when you know which dataset it ran on. If today you add 6 cases, remove 1 and change the expectation of 2 cases, the new pass rate can no longer be compared directly with last week's. So a dataset needs: a version number, a fingerprint of its content, and a changelog that says what changed and why.

The MAJOR.MINOR.PATCH numbering comes from software. The SemVer specification says: "Once a versioned package has been released, the contents of that version MUST NOT be modified" [R1]. That principle applies well to datasets: a fix means releasing a new version. SemVer is about software APIs; the bump rule below is the lab's own convention, chosen by the question "can the old results still be compared?":

Change Bump Why
Remove a case, or change content (question, expectation, intent, style, risk) major The old result on that id no longer means the same thing
Only add cases minor Old results can still be compared on the old ids
Only change metadata (tags, notes) patch The content is unchanged
Change nothing no bump No release

4.2 What contamination is

Contamination is when an evaluation case has appeared somewhere the system under measurement can "see" it, so the score no longer reflects general ability. The survey by Xu et al. defines benchmark data contamination as language models inadvertently bringing the information of an evaluation benchmark in from training data, leading to inaccurate evaluation results [R3] (only the abstract of this survey was read). The GPT-3 paper named the problem early: because the training data comes from the internet, "it is possible that our model was trained on some of our benchmark test sets" [R2].

For a QA team using a model through an API, the more realistic leak path is usually inside your own system: for example few-shot examples in the prompt copied from evaluation cases, or evaluation cases reused to tune the prompt and then still reported on. The survey's definition is about training data; extending it to your prompt is this lesson's interpretation, the same mechanism (the system has seen the answer).

4.3 Privacy: review before every release, keep exemptions with reasons

Personal data does not disappear after L01: every release is a chance for it to slip in. NIST AI 600-1 has two entries in the MEASURE 2.2 group (evaluation involving human subjects, and content provenance data), so this is guidance for that context and this lesson borrows the idea for an eval dataset. Entry MS-2.2-002 suggests anonymisation to protect data subjects and "Removing any personally identifiable information (PII) to prevent potential harm or misuse" [R4]; entry MS-2.2-003 mentions giving data subjects "options to withdraw participation or revoke their consent for present or future use of their data" [R4]. The second shows an operational obligation: a dataset must have a way to delete a case when that person withdraws. The GDPR storage-limitation principle (Article 5(1)(e)) also requires not keeping identifiable data longer than necessary [R7]. Not legal advice.

The lab's dataset deliberately contains made-up data (cases E20-E23, E25, E26) to check that the tutor does not repeat a phone number or a name. The release gate does not forbid them, but demands a justified exemption for each case, and raises an error if an exemption is stale (the case no longer has PII) or points to a case that does not exist.

5. Technical deep dive

5.1 Diff, bump and a changelog that code can check

versioning.diff(old, new) compares two case lists by id and returns: added, removed, changed (a different content fingerprint) and meta_only. The per-case content fingerprint hashes the fields question, reference, intent, style, risk, and not tags; the whole-dataset fingerprint does not depend on case order. versioning.required_bump(d) applies the rule in §4.1.

versioning.validate_release(manifest, old, new, old_version) checks the manifest against the real data and against the release it replaces (you pass old and old_version; for the first release use [] and "0.0.0"): the version is well-formed like 1.2.3; previous_version equals old_version; the new version is strictly greater than old_version (re-releasing 1.0.0 with different content is caught); the declared bump is not lower than the required one; there is a changelog entry for this version and its added, removed, changed lists match the computed diff; there is a reason when cases are removed or changed; the fingerprint matches; no two cases share an id or a question; PII has a valid exemption. Demo B runs it on the draft manifest_v2_draft.json and catches 4 problems: it declares minor but the change needs major; the changelog is missing E03 in the list of changed cases; a reason is missing; the fingerprint is stale.

It does not check: whether the reason is true, whether the labels are right, whether the new cases are good, whether a PII exemption is justified, and whether old really is the previously released version (it trusts the data you pass in). Detecting two cases with "the same question" only normalises letter case and whitespace: a copy typed without diacritics, or differing by one "?", is not seen. It catches a manifest that contradicts the data, not wrong data. A bump higher than required (for example declaring major for a minor change) is allowed, because being overly cautious does not break comparability.

5.2 Splitting dev and test with a hash

You need two parts: dev for tuning the prompt, and test for the final report that nobody tunes against. versioning.split_of(case_id, salt, dev_share) decides the side of a case from the hash of salt|id. The side depends only on the id, so adding cases does not make old cases change side. Another common approach, shuffle and cut in half, cannot do this: demo C shows that when v2 adds cases, 12 of the 38 old cases change side, meaning a case that was used for tuning can jump into the test part. dev_share must be in (0, 1), because splitting off an empty side is not a split. A hash gives an approximate proportion, not an exact one: v1 has 15 dev and 23 test with dev_share 0.5.

There is another leak: the same question sitting on both sides. versioning.split_leaks(dev, test, threshold) finds near-duplicate pairs (Jaccard over the set of words) between dev and test. Jaccard over the set of words ignores order and repeat counts, so "12 candies ... 3 boxes" and "3 candies ... 12 boxes" give 1.0, while a copy typed without diacritics scores low.

5.3 Checking contamination with n-gram overlap

versioning.contamination(cases, corpus_texts, n, flag_at) takes every word n-gram (a run of n consecutive words) of each question and computes the share found in the text corpus you check (prompts, few-shot examples, a sample of training data). A case whose share is ≥ flag_at is flagged. The GPT-3 paper treats an example as possibly leaked when it shares a 13-gram with the training set (for examples shorter than 13 words, the whole example is compared) [R2]. The lab differs in two places: n = 5 because our questions are short, and a case is flagged only when its overlap share reaches flag_at, which is stricter than "a single matching 13-gram". For a case shorter than n words, the lab compares the whole word sequence at word boundaries ("5 bạn" does not match inside "15 bạn nhé"). Matching uses lowercase words, so a copy typed without diacritics is not seen. The choice of n and the threshold is yours.

Demo D checks the 38 cases of eval_v1 against the three few-shot examples in data/tutor_prompt.txt. At flag_at = 0.5, only S001 is flagged (share 1.0: it matches example 2 verbatim). Lowering the threshold to 0.3 adds E02 (0.429, a partial match because example 1 has the same math problem but E02 adds an opening sentence). Example 3 is a number-changed version of S002 and is not flagged at either threshold. That is the main blind spot: n-gram overlap finds copies, not paraphrases, number changes or translations. It is a cheap filter, not proof of cleanliness; a lower threshold catches more but also gives more false alarms.

6. The QA perspective

6.1 The release gate and the dataset card

A release gate before applying a version consists of: run validate_release; run contamination with every prompt and example in use; run split_leaks between dev and test; review PII with the screen plus a manual look at a sample; and confirm that every PII exemption is still correct. If any item fails, stop; do not lower the gate to get through.

Finally there is the dataset card: the document that accompanies the dataset. Gebru et al. proposed datasheets for datasets, stating the motivation, composition, collection process and recommended uses [R5] (only the abstract was read). Hugging Face uses the repo's README.md as the dataset card, containing metadata and a description that helps users understand the content and how to use it, including potential biases [R6]. versioning.lint_card checks seven sections: motivation, composition, collection, preprocessing, uses, limitations and maintenance, where maintenance must have an owner, an update policy and a retire rule (when a case leaves the main set, for example when every recent version passes it consistently). The lint only catches what is missing; whether the content is correct still needs a person to read it. The known-limitations section (such as "does not catch addresses; the check × mixed_en cell is still empty") matters most to whoever comes later.

7. Real-world scenarios

Scenario 1 (fictional): "A silent edit". A team edited the expectations of two cases and wrote only "minor update" in the changelog. The next week's score rose by 3 percentage points and the whole team celebrated. With a release gate, this change is demanded to be major with a specific reason, so the report must say "the score is not directly comparable with v1". Without the gate, nobody notices that the difference came from the dataset and not from the system.

Scenario 2 (fictional): "Examples in the prompt". To improve behavior, an engineer copied three cases from the dataset into the few-shot examples of the prompt. The pass rate on those cases rose to nearly 100%. The n-gram check catches a verbatim match (like S001 in the demo) but lets through a number-changed case (like example 3), even though it still teaches the system the same kind of problem. The fix: remove those cases from the test, record it in the changelog, and separate the few-shot examples from the dataset source from the start.

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l2-m02
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 73 passed

8.2 Run the demo

python -m lab.demo l05

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-03; the two versions give identical output):

A. what changed between v1 and v2
   added      ['E25', 'E26', 'E27', 'E28', 'E29', 'E30']
   removed    ['S008']
   changed    ['E03', 'E10']
   meta_only  ['E07']
   required bump: major
B. the draft manifest, checked against the data
   - version 1.0.0 -> 1.1.0 is a minor bump but the changes need major
   - changelog changed ['E10'] != actual ['E03', 'E10']
   - removed or changed cases need a reason in the changelog
   - fingerprint d1b58c615cf9 != actual 2b70cda80d31
C. a split decided by a hash of the id
   v1: dev 15, test 23
   v2: dev 17, test 26
   old cases that changed side when v2 arrived: shuffle-and-cut split 12 of 38 (a hash split: 0 by construction, the side is a function of the id only)
D. contamination against the few-shot examples of data/tutor_prompt.txt
   flag_at=0.5: [('S001', 1.0)]
   flag_at=0.3: [('S001', 1.0), ('E02', 0.429)]
E. privacy findings in v2 (some cases contain invented personal data on purpose)
   [('E20', 'phone'), ('E21', 'name'), ('E22', 'phone'), ('E23', 'phone'), ('E25', 'phone'), ('E26', 'phone')]

Reading the output:

  • A. v1 to v2: 6 added, 1 removed (S008), 2 changed in content (E03, E10), 1 changed in metadata (E07); the required bump is major.
  • B. The draft manifest is caught with 4 problems.
  • C. The split by hash; a shuffle-style split makes 12 of the 38 old cases change side.
  • D. N-gram overlap against the three few-shot examples.
  • E. 6 cases have deliberately made-up PII, and each needs a justified exemption.

8.3 Compute a version and check a dataset card of your own

Save as try_l05.py inside the lab folder:

from lab import sources, versioning as V

old = sources.load_jsonl(sources.DATA / "eval_v1.jsonl")
new = [dict(c) for c in old]
new[0]["question"] += " (sửa)"
new.append({"id": "Z01", "question": "Số 100 là số chẵn hay lẻ?", "intent": "concept", "style": "clean",
            "risk": "low", "reference": {"must_include": ["chẵn"], "source": "policy §4"}, "tags": []})
d = V.diff(old, new)
print(d, V.required_bump(d))
print(V.bump("1.0.0", V.required_bump(d)))
print(V.split_of("Z01"), V.split_of("E01"))
shots = ["Mai có 8 cái kẹo, chia đều cho 4 bạn. Mỗi bạn được mấy cái kẹo?"]
print(V.contamination(old, shots))

card = {"motivation": "Đo tutor trước mỗi lần phát hành.", "composition": "43 case, intent x style.",
        "collection": "Log đã ẩn PII, ca viết tay, ca tổng hợp đã lọc.", "preprocessing": "Ẩn PII, khử trùng lặp.",
        "uses": "Chỉ để đánh giá offline.", "limitations": "", "maintenance": {"owner": "nhóm QA"}}
print(V.lint_card(card))

Run python try_l05.py. Output:

{'added': ['Z01'], 'removed': [], 'changed': ['E01'], 'meta_only': []} major
2.0.0
test dev
[('S001', 1.0)]
['section limitations is missing or empty', 'maintenance.update_policy is empty', 'maintenance.retirement_rule is empty']

One added case and one changed case give major: the highest bump wins. Line 3 is the dev or test side of two ids (fixed). The last line is the lint of a dataset card that is still incomplete: the limitations section is empty, and the maintenance section has only an owner, with no update policy and no retire rule. Fill in those three places and run again until the list is empty; compare with data/dataset_card_example.json.

8.4 Run the lesson's tests

python -m pytest tests/test_l05_versioning.py -v

Result: 14 passed. Read test_release_gate_passes_v1_and_names_the_four_problems_of_the_draft and test_contamination_finds_copies_and_misses_changed_numbers.

8.5 Troubleshooting

Symptom Cause Fix
fingerprint ... != actual ... The dataset changed after the fingerprint was computed Recompute with versioning.fingerprint
no exemption for a case PII in the question and the manifest has no exemption Redact the PII, or add a justified exemption if it is deliberate
stale exemption An exemption points to a case that no longer has PII Remove that exemption

9. Independent exercise

Problem: Release a new version of a small dataset: write a correct manifest, find the contaminated cases and split dev/test.

Requirements: complete exercises/test_l05_release.py and exercises/my_manifest.json:

  1. TODO 1: fill in my_manifest.json (the new version, previous_version as 1.0.0, fingerprint, changelog, pii_exemptions) so that validate_release(manifest, OLD, NEW, "1.0.0") returns an empty list.
  2. TODO 2: fill in CONTAMINATED: the ids (in order) of the cases of NEW flagged when calling contamination(NEW, CORPUS, n=4, flag_at=0.5).
  3. TODO 3: fill in SPLIT_DEV: the ids (in order) of NEW on the dev side with salt="exercise", dev_share=0.4.

Test data: exercises/dataset_a.jsonl (the old version), dataset_b.jsonl (the new version), corpus.txt (the prompt to check).

Deliverable: the filled-in manifest and two lists.

Acceptance criteria: python -m pytest exercises/test_l05_release.py passes (2 tests); no TODO is left in my_manifest.json; the changelog has a reason for the removed or changed parts.

Hint: compute versioning.diff first to know the bump; one case in dataset_b contains a made-up phone number and needs an exemption; do not copy the fingerprint, compute it.

10. Knowledge check

0/14 done · Results are kept in this browser only.

P02 · True or false

A team edits the expectations of two cases and writes "minor update" (patch) in the changelog. That is correct under the lab's rule.

P04 · Select all that apply

For a QA team that uses a model through an API, which situations are contamination (or the same mechanism)? Select all that apply.

P05 · Put in order

Put in order the steps of the release gate before you stamp a version on the dataset.

  1. Scan for PII with the screener, plus a manual look at a sample
  2. Stamp the version and release
  3. Run validate_release with the manifest, the old version and the new version
  4. Run split_leaks between the dev part and the test part
  5. Confirm every PII exception is still valid
  6. Run contamination with every prompt and example in use

P06 · Match

Match each key of versioning.diff to its meaning and its bump.

P07 · Spot the bug

The manifest below is used for v2 (the diff as in P01: 6 added, 1 removed, 2 changed in content). validate_release reports one problem about the version number. Find the bug.

{
  "name": "hocvui-eval",
  "version": "1.1.0",
  "previous_version": "1.0.0",
  "changelog": [
    {"version": "1.1.0",
     "added": ["E25", "E26", "E27", "E28", "E29", "E30"],
     "removed": ["S008"],
     "changed": ["E03", "E10"],
     "reason": "Bỏ S008 và sửa E03, E10 theo đợt rà soát guideline"}
  ]
}

P08 · Short answer

Why is splitting dev/test with a hash of the id (versioning.split_of) better than shuffling and cutting in half when the dataset keeps growing?

P09 · Essay

An engineer copies three cases from the dataset into the prompt's few-shot examples, and the pass rate on those cases rises to nearly 100%. Write 5-8 sentences: how this ruins the measurement, what the n-gram check catches and misses (use the demo's numbers), and how you handle it.

P10 · Multiple choice

Demo D: at flag_at = 0,5 only S001 is flagged; lowering to 0.3 adds E02; the third few-shot example (the number-swapped version of S002) is not flagged at either threshold. What is the most correct conclusion?

P11 · Fill in the blank

Demo D checks the 38 cases of eval_v1 against the three few-shot examples: at flag_at = 0,5 only ___ is flagged (ratio 1.0, verbatim the same as example 2); lowering to 0.3 adds ___ (ratio 0.429).

P12 · Recall

Lesson: L2-M01-L01

The dataset fingerprint in run.config (L2-M01-L01 §5.2) differs between v1 and v2 because E03 and E10 changed content. What does that allow you to do with the pass rates of the two versions?

P13 · Recall

Lesson: L2-M02-L01

The cases E20-E23 are expert-written cases with invented phone numbers (L2-M02-L01 §5.3). The PII screener still flags them. How does the release gate handle it?

11. Summary

  • Concepts: a dataset has a version, a fingerprint and a changelog; the bump rule follows "can the old results still be compared?"; contamination is an evaluation case leaking into a place the system has already seen; PII must be reviewed at every release and exemptions must have reasons.
  • Skills: compute the diff and the bump; split dev/test with a hash; n-gram overlap; the release gate; a dataset card with a maintenance section.
  • Traps: silent edits; a shuffled split making old cases change side; treating a clean n-gram result as the end of contamination; treating a passing gate as a good dataset.
  • You can now: release a versioned dataset that others can check.

12. References

ID Title Publisher URL Accessed Relevance
R1 Semantic Versioning 2.0.0 semver.org https://semver.org/ 2026-11-03 A released version must not be modified; bump convention (the dataset rule is the lab's own)
R2 Language Models are Few-Shot Learners (Brown et al., arXiv:2005.14165) arXiv https://arxiv.org/abs/2005.14165 2026-11-03 Section 4: contamination, the 13-gram rule (full PDF read)
R3 Benchmark Data Contamination of Large Language Models: A Survey (Xu et al., arXiv:2406.04244) arXiv https://arxiv.org/abs/2406.04244 2026-11-03 Definition of contamination (abstract only)
R4 NIST AI 600-1: Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile (July 2024) NIST https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.600-1.pdf 2026-11-03 MS-2.2-002, MS-2.2-003: removing PII, the right to withdraw consent
R5 Datasheets for Datasets (Gebru et al., arXiv:1803.09010) arXiv https://arxiv.org/abs/1803.09010 2026-11-03 Documentation that accompanies a dataset (abstract only)
R6 Dataset Cards Hugging Face https://huggingface.co/docs/hub/datasets-cards 2026-11-03 A dataset card is a README with metadata
R7 Art. 5 GDPR: Principles relating to processing of personal data gdpr-info.eu (unofficial reproduction) https://gdpr-info.eu/art-5-gdpr/ 2026-11-03 Article 5(1)(e): storage limitation; not legal advice

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Dataset version / changelog Phiên bản dataset / nhật ký thay đổi
Manifest Tệp mô tả một bản phát hành
Fingerprint Dấu vân tay (hash nội dung)
Contamination Nhiễm dữ liệu: case đánh giá lọt vào nơi hệ thống đã thấy
n-gram Dãy n từ liên tiếp
Dev / test split Chia phần tinh chỉnh / phần báo cáo cuối
Release gate Cổng release
Exemption Ngoại lệ có lý do
Dataset card Tài liệu mô tả dataset
Retirement rule Quy tắc cho case rời bộ chính