Machine Learning • 3 min read

Data, Model, and Experiment Versioning

Two engineers may train the same algorithm and report different results. The difference might come from a changed dataset, preprocessing rule, library version, random seed, or evaluation split. Versioning makes those differences discoverable instead of mysterious.

Three things you must version

Code version identifies the implementation, usually with a Git commit. Data version identifies the records and labels used for a run. Model version identifies an output artifact created by a particular training process. An experiment record links all three, plus hyperparameters, environment, and metrics.

A model name such as classifier-final.pkl is not useful provenance. Even v2 is ambiguous unless the team knows what changed.

What a reproducible run should record

ItemExampleWhy it matters
Code revisionGit commit hashIdentifies implementation
Dataset snapshotContent hash or immutable dataset IDIdentifies inputs
Split methodTime split at a recorded cutoffExplains evaluation population
ConfigurationAlgorithm, learning rate, seedDefines the training recipe
EnvironmentPython and package versionsReduces dependency surprises
ArtifactsModel weights and fitted preprocessorMakes inference reconstructable
EvaluationMetrics, test slice, dateExplains evidence behind promotion

Data versioning is harder than it looks

Large datasets may not fit sensibly in Git. Instead, use immutable snapshots in object storage or dedicated data-versioning systems, and store manifests or identifiers in the repository. A dataset version should include schema and labeling criteria. If the underlying source is mutable, a filename alone does not preserve the exact records.

Privacy and retention policies still apply. Versioning should not mean retaining personal information forever or cloning sensitive datasets into public repositories.

Model artifacts require context

A trained model usually depends on the exact preprocessing pipeline that created its inputs. Store the tokenizer, category mappings, standardization parameters, label mapping, and inference contract alongside weights when appropriate. Record compatibility requirements and artifact integrity checks.

Be cautious with untrusted serialized Python objects: some formats can execute code when loaded. Only load artifacts from trusted sources and use safer formats where feasible.

A simple hash demonstration

A cryptographic hash can help detect whether file bytes changed. It does not, by itself, prove a dataset is authentic or legally permissible.

from hashlib import sha256
from pathlib import Path

path = Path('training.csv')
if path.exists():
    digest = sha256(path.read_bytes()).hexdigest()
    print({'filename': path.name, 'sha256': digest})
else:
    print('Place training.csv next to this script to calculate its hash.')

For very large files, compute the hash in chunks rather than reading the entire dataset into memory.

Experiments are evidence, not just scores

A complete experiment log records what question was tested and what comparison was made. If Run B improves accuracy by 0.3 percentage points, inspect confidence intervals, dataset composition, and operational costs before claiming meaningful progress. A small benchmark improvement is not automatically a product improvement.

Centralized tracking systems can store parameters, metrics, plots, tags, and artifacts. The precise tool is less important than an enforced habit of capturing run provenance.

Releasing and rolling back

Before promotion, record who approved a model, which evaluations passed, what serving environment is required, and how to restore an earlier version. Model and dataset versions should have stable identifiers that logs can reference when incidents occur.

References

Related articles in

Image preview

Fit