AI training provenance #
What is new: every dataset and model is bound to the exact licensed data it came from, and pulling one source withdraws exactly the models built on it, while the others keep working.
Why it matters: "which of our models learned from this source?" is the question a takedown, a withdrawn consent or an expired licence asks. Here it has a signed answer in seconds, and the next training run on that source is refused before it starts.
Two sources, licensed, fingerprinted #
import hashlib, pathlib
import tensorchain.cloud as tc
p = tc.Local("ai.sqlite")
for name, files in (("photos", ["cat.jpg", "dog.jpg"]), ("captions", ["cat.txt", "dog.txt"])):
d = pathlib.Path("data") / name; d.mkdir(parents=True)
for f in files:
(d / f).write_bytes(("contents of " + f).encode())
p.add_source(name)
p.license(name, "agent:trainer", ["train"], days=90)
p.ingest_folder(name, d, state=f"sent-{name}.json")
again = p.ingest_folder("photos", "data/photos", state="sent-photos.json")
pathlib.Path("data/photos/dog.jpg").write_bytes(b"a corrected dog")
changed = p.ingest_folder("photos", "data/photos", state="sent-photos.json")
print("re-run sent:", len(again), "manifests; after one change:", len(changed))
print({s["source"]: s["manifests"] for s in p.sources()})
assert again == [] and len(changed) == 1
Output (captured at build)
re-run sent: 0 manifests; after one change: 1
{'captions': 1, 'photos': 2}A second run sends nothing; a changed file sends one manifest with one item, chained to the one before it.
Two models, each traced to its data #
def train(tag):
out = pathlib.Path("out"); out.mkdir(exist_ok=True)
(out / f"{tag}.bin").write_bytes(hashlib.sha256(tag.encode()).digest())
return out / f"{tag}.bin"
with p.training("agent:trainer", "train", ["photos", "captions"]) as run:
both = run.model(train("vision-language"))
with p.training("agent:trainer", "train", ["captions"]) as run:
text = run.model(train("text-only"))
print("models:", sorted(m["state"] for m in p.models()))
assert all(p.verify(m["model"])["status"] == "valid" for m in (both, text))
Output (captured at build)
models: ['usable', 'usable']
Pull one source #
p.revoke(source="photos", reason="the photographer withdrew consent")
imp = p.impact("photos")
states = {m["model"]: m["state"] for m in p.models()}
print("impact: manifests", len(imp["manifests"]), "datasets", len(imp["datasets"]), "models", len(imp["models"]))
print("vision-language:", states[both["model"]], " text-only:", states[text["model"]])
assert states[both["model"]] == "revoked" and states[text["model"]] == "usable"
assert imp["models"] == [both["model"]]
Output (captured at build)
impact: manifests 2 datasets 1 models 1 vision-language: revoked text-only: usable
Only the model that learned from photos is withdrawn; the text-only model is untouched. The audit report carries the whole story for an auditor:
a = p.audit()
print(len(a["sources"]), "sources,", len(a["datasets"]), "datasets,", len(a["models"]), "models,",
len(a["revocations"]), "revocation")
assert len(a["revocations"]) == 1 and {s["source"]: s["revoked"] for s in a["sources"]} == {"captions": False, "photos": True}
Output (captured at build)
2 sources, 2 datasets, 2 models, 1 revocation