Use cases/Dataset versioning

How to know which data trained each model

A step-by-step guide to saving your training data as versions, recording the version behind each model, and fixing bad data without breaking anyone’s next run.

  • 12 min read
  • TypeScript
  • Beginner friendly
ModelTrained on
ticket-tagger-v8fix/spam-labelscff0c59
ticket-tagger-v7maina3c031e

The question nobody could answer

A model remembers its training data only by a folder name. The folder keeps changing: people clean it up in place, and new exports land on top. The model doesn’t change. A week later the name points to different data, so when the model starts making mistakes, the first question, what did it learn from?, has no answer. The model is in production, and nobody can say what it learned from.

The usual fixes help a little. You can copy the folder before each run, and soon you have tickets_v2, tickets_v2_clean and tickets_final, each a full copy, and still no record of which one trained which model. Or you can write a note with the file names and a checksum. That tells you the data changed, but it can’t give you the old data back.

The usual setup

tickets_v2/tickets_v2_clean/tickets_final/ Which one?Model v7

What we’ll build

a3c031ecff0c59One historyEach model names its commit

In this guide we’ll keep one dataset with a full history instead. Every change is a commit, a saved version with its own id. Each model gets a small card that names the commit it trained on. Old versions never go away, and a copy for an experiment costs nothing, because it copies nothing.

What we’re building

By the end, you’ll have:

  • Your training data saved as a branch, with every change kept as a commit.
  • A training step that reads one exact commit and records it on a model card.
  • A way to open the exact files behind any model, months later.
  • Forks, so you can clean the data without touching anyone else’s runs.
  • A clear list of what changed between two versions, before you keep a fix.

You’ll need a Skywake API key and Node. Set SKYWAKE_API_KEY, then install the SDK with npm i skywake.

Step 1

Save the dataset as a version

Start with the folder you train from today. Ours is a few files of labeled tickets, one JSON object per line:

tickets/

  • train/billing.jsonl
  • train/shipping.jsonl
  • train/spam.jsonl# where the trouble is
  • train/old-2019.jsonl
  • eval/holdout.jsonl# the tickets we test on

We’ll save it to a disk, a set of files with branches and history, on its first branch, main. A branch works like a Git branch: each save is a commit, and every commit stays readable.

save-data.ts
import { Skywake } from "skywake";

const sky = new Skywake();

const data = sky.disk("tickets");
const v1 = await data.upload("./tickets", {
  message: "Support tickets, March export",
});

v1 is the id of the commit we just made. That one id names this exact set of files, forever, whatever happens to main later.

Step 2

Train from one version, and write it down

Now the part that was missing in the story. Before training, we write the branch out to a local folder. download reads every file from a single commit and returns its id. Then we save that id on a model card.

The cards live on their own disk, so the dataset’s history shows only changes to the data.

train.ts
import type { Disk } from "skywake";

const cards = sky.disk("models");

async function train(data: Disk, model: string) {
  const commit = await data.download(`./runs/${model}`);
  const card = { model, branch: data.branch, commit };
  await cards.write(`${model}.json`, JSON.stringify(card, null, 2), {
    message: `Trained ${model}`,
  });
  return commit;
}

await train(data, "ticket-tagger-v7");

The card for v7 now says main and the commit id. If someone commits to main a minute later, the card still points to the files v7 really saw.

Tip: record the commit, not the branch

A branch name moves every time someone saves. A commit id never does. Keep the branch name on the card to help people read it, but always trust the commit.

Step 3

Open the data behind a model

Say v7 starts sending refund requests to spam, and main has changed since it was trained. We don’t need to guess. We read the card, then read the spam file at the commit it names:

open-data.ts
const card = JSON.parse(await cards.read("ticket-tagger-v7.json"));
const file = await data.read("train/spam.jsonl", { at: card.commit });
console.log(file);

The at option reads a file as it was at an older commit. The answer is right there: the same spam line twice, and a refund request labeled as spam. v7 learned exactly what we taught it.

train/spam.jsonl a3c031e
  • “You won a free cruise, click here” → spam
  • “You won a free cruise, click here” → spamthe same line twice
  • “I want a refund for my order” → spama refund, labeled spam

Step 4

Fix the data on a fork

The obvious move is to edit the file in place. But a teammate may be training from main right now, and a half-done cleanup would end up in their model too.

So we fork instead. A fork is a new branch that starts as an exact copy of another. It copies no files, so it is quick however big the data is, and nothing you do on it touches main.

fix.ts
const fix = await data.fork("fix/spam-labels");

const spam = {
  text: "You won a free cruise, click here",
  label: "spam",
};
await fix.write("train/spam.jsonl", JSON.stringify(spam) + "\n", {
  message: "Fix spam labels",
});
await fix.delete("train/old-2019.jsonl", {
  message: "Drop 2019 tickets",
});

Two small commits do the job: spam.jsonl keeps one real spam example, and the outdated 2019 file is gone. On main, both files are exactly as they were.

Step 5

See exactly what changed

Before anyone trains on the fix, it’s worth a look at what it really changes. A diff lists every file that differs between two branches.

diff.ts
for (const { change, path } of await fix.diff("main")) {
  console.log(change, path);
}

Nobody changed main since we forked it, so the diff shows only what the fork changed:

fix/spam-labels compared with main

  • removedtrain/old-2019.jsonloutdated tickets
  • modifiedtrain/spam.jsonltwo bad lines gone

This is the list to paste into a pull request, or a training report. Anyone can see what the next model will learn differently, file by file.

Step 6

Train again, and keep the fix

Train v8 from the fork with the same train function. If it does better on the holdout tickets, merge the fork into main, so everyone’s next run starts from clean data.

keep.ts
await train(fix, "ticket-tagger-v8");

const merged = await fix.mergeInto("main");
console.log("main now has the fix:", merged.commit);

The merge brings the fix into main. If someone changed the same files on main meanwhile, mergeInto throws a MergeConflict that lists them, and saves nothing. And now each model has a clear source:

ticket-tagger-v7

Learned that some refunds are spam.

main@ a3c031e

ticket-tagger-v8

Trained on the fixed spam file.

fix/spam-labels@ cff0c59
Every model, one exact commit

Both commits stay readable through main after the merge, even if you delete the fork. And cards.log() lists every training run, newest first, as its own small history.

Running it for real

A few habits that keep this working as the team and the data grow:

  • Give training a read key. Training only downloads. A key with the read role, narrowed to the tickets disk, can’t change the data by mistake.
  • Forks stay cheap. Creating a branch takes about 13 ms, and it copies no files. Give every experiment its own.
  • Any model can be trained again. Download the commit on its card, and you get back the exact same files, byte for byte.
  • It all stays yours. The data and its history live in your own bucket, not in copies spread across laptops.
rebuild.ts
const training = await sky.createKey({
  name: "training",
  role: "read",
  only: ["tickets"],
});

await data.download("./runs/v7-again", { at: card.commit });

Questions

Start building with Skywake.

One shared disk for all your agents, with search built in.