Dataset Versioning
Code has Git: every change is recorded, every version can be restored, and you can see exactly what changed between two commits. Data needs the same, for the same reasons. A model's behaviour depends on its training data as much as on its code, so "which data was this model trained on?" must always have a precise answer. Without it you cannot reproduce a result, explain why a new model got worse, or prove to an auditor what a model learned from.
What changes in a dataset
| Change | Example |
|---|---|
| samples added or removed | a new month of data; a customer asks for their data to be deleted |
| labels corrected | 40 images relabelled after review |
| features changed | a new cleaning rule; a column computed differently |
| schema changed | a column renamed, a type changed, a category added |
| split changed | a new test set |
Any one of these can move a model's score, and all of them happen silently unless versions are recorded.
Three ideas behind every versioning tool
- Immutability: a published version never changes. Fixes create a new version.
- Content addressing: a version is identified by a hash of its contents, so the same data always has the same id and any change, however small, gives a new id.
- A pointer, not a copy: the training code records the version id (or the manifest's hash) it used, next to the model.
A dataset fingerprint from a manifest takes a few lines:
import hashlib
import json
def fingerprint(manifest):
canonical = json.dumps(sorted(manifest, key=lambda m: m["key"]), sort_keys=True)
return hashlib.sha256(canonical.encode()).hexdigest()[:12]
v1 = [
{"key": "img_001.png", "sha256": "aa11", "label": "cat"},
{"key": "img_002.png", "sha256": "bb22", "label": "dog"},
{"key": "img_003.png", "sha256": "cc33", "label": "dog"},
]
shuffled = [v1[2], v1[0], v1[1]]
v2 = [dict(m) for m in v1]
v2[2]["label"] = "cat" # one label corrected
print("v1: ", fingerprint(v1))
print("v1 reordered:", fingerprint(shuffled))
print("v2: ", fingerprint(v2))v1: 8ce51a288a22
v1 reordered: 8ce51a288a22
v2: d38c2f30c9be
Sorting the entries and the keys first makes the fingerprint canonical: the order in which files were listed does not matter, but a single changed label gives a completely different id.
Diffing two versions
A fingerprint tells you that something changed; a diff tells you what:
import pandas as pd
v1 = pd.DataFrame({
"key": ["img_001", "img_002", "img_003", "img_004"],
"sha256": ["aa11", "bb22", "cc33", "dd44"],
"label": ["cat", "dog", "dog", "cat"],
})
v2 = pd.DataFrame({
"key": ["img_001", "img_002", "img_003", "img_005", "img_006"],
"sha256": ["aa11", "bb99", "cc33", "ee55", "ff66"],
"label": ["cat", "dog", "cat", "dog", "dog"],
})
m = v1.merge(v2, on="key", how="outer", suffixes=("_v1", "_v2"), indicator=True)
added = m.loc[m["_merge"] == "right_only", "key"].tolist()
removed = m.loc[m["_merge"] == "left_only", "key"].tolist()
both = m[m["_merge"] == "both"]
content = both.loc[both["sha256_v1"] != both["sha256_v2"], "key"].tolist()
relabel = both.loc[both["label_v1"] != both["label_v2"], ["key", "label_v1", "label_v2"]]
print("added: ", added)
print("removed: ", removed)
print("content changed:", content)
print("relabelled:")
print(relabel.to_string(index=False))
print()
print("class counts v1:", v1["label"].value_counts().to_dict(), "| v2:", v2["label"].value_counts().to_dict())added: ['img_005', 'img_006']
removed: ['img_004']
content changed: ['img_002']
relabelled:
key label_v1 label_v2
img_003 dog cat
class counts v1: {'cat': 2, 'dog': 2} | v2: {'dog': 3, 'cat': 2}
Such a diff belongs in the release notes of every new dataset version, together with the class counts, so that a change in model behaviour can be traced to a change in data.
Tabular data: hashing a DataFrame
For a table, pandas can hash every row. Combining the row hashes gives a fingerprint of the whole table, and comparing row hashes finds the rows that changed:
import hashlib
import pandas as pd
def table_fingerprint(df):
rows = pd.util.hash_pandas_object(df, index=False)
return hashlib.sha256(rows.values.tobytes()).hexdigest()[:12]
df = pd.DataFrame({"id": [1, 2, 3], "age": [34, 51, 29], "city": ["Hue", "Hanoi", "Hue"]})
changed = df.copy()
changed.loc[1, "age"] = 52
print("original:", table_fingerprint(df))
print("same data again:", table_fingerprint(df.copy()))
print("one value changed:", table_fingerprint(changed))
diff_rows = pd.util.hash_pandas_object(df, index=False) != pd.util.hash_pandas_object(changed, index=False)
print("changed row ids:", df.loc[diff_rows, "id"].tolist())original: f58c1db70f9c
same data again: f58c1db70f9c
one value changed: 8f1a4b60ff22
changed row ids: [2]
Tools
You rarely build versioning yourself. The common tools, all built on the ideas above:
| Tool | How it works |
|---|---|
| DVC (Data Version Control) | small .dvc files with content hashes live in Git; the data lives in remote storage. Taught in Deployment & MLOps |
| lakeFS | Git-like branches and commits over an object-storage bucket |
| Delta Lake / Apache Iceberg | table versions with "time travel": read the table as of a version or a date |
| Hugging Face Hub | each dataset is a Git repository; load a fixed revision |
| dated, immutable snapshots | curated/skin/v3-2026-06-14/ plus a manifest, never overwritten: simple and effective |
Whatever the tool, write a short dataset card (also called a datasheet) for each version: what the data is, where it came from, how it was labelled, its licence and known problems, and what changed since the last version.
Pitfalls
- "Latest" instead of a version: a training run that reads "the current data" can never be reproduced.
- Versioning the data but not the code that made it: record the commit of the cleaning code with each version.
- Deleting data that must stay deleted: when a person withdraws consent, their data must be removed from new versions, and old versions must also be handled according to the retention policy (see Privacy, Consent, Licensing). Immutability has legal limits.
- Copying everything for each version: content-addressed storage stores unchanged files only once.
Practice
- Two training runs report different accuracy. The code commit is the same. What two things would you compare first?
Answer
The dataset version ids (manifest hashes) the two runs used, and their random seeds. If the data versions differ, diff them: added, removed, changed and relabelled samples and the class counts.
- Why does
fingerprintsort the manifest entries before hashing?
Answer
The order in which files are listed can change between machines or runs (directory listings are not guaranteed to be sorted). Sorting makes the fingerprint depend only on the content, not on the listing order.
Test yourself
What does content addressing mean for a dataset version?
- The version is named after its author
- The version id is a hash of its contents, so identical data gets the same id and any change a new one
- Each file is stored twice
- Versions are numbered 1, 2, 3
A model was trained on curated/latest/. Months later you cannot reproduce its score. What was the mistake?
- The model was too small
- Training read a mutable location instead of a fixed, versioned dataset
- The bucket was private
- The labels were multi-label
Which tool keeps small files with content hashes in Git while the data itself lives in remote storage?
- Parquet
- DVC
- SQLite
- Matplotlib