Pull one bad batch #
What is new: you can revoke a single ingest batch (a poisoned scrape, a mislabelled week of data) instead of a whole source. Every batch ingested after it, every dataset that read through it and every model trained on those are reached; the batches before it, and every other source, are not.
Why it matters: most data problems are a window, not a whole source. Throwing away the source is expensive; keeping a model that saw the bad window is risky. Here the line is drawn exactly.
Three batches of a crawl, and a book corpus #
import hashlib
import tensorchain.cloud as tc
from tensorchain import ingest, provenance, provenance_ops as ops
from tensorchain.workspace import Workspace
p = tc.Local("batches.sqlite")
for s in ("crawl", "books"):
p.add_source(s)
p.license(s, "agent:trainer", ["train"])
week = [["week-%d.warc" % i, hashlib.sha256(b"week %d" % i).hexdigest(), 1 << 20] for i in (1, 2, 3)]
crawl = p.ingest("crawl", week, chunk=1) # one manifest per week, each chained to the last
p.ingest("books", [["books.tar", hashlib.sha256(b"books").hexdigest(), 1 << 22]])
web_model = p.model(p.dataset("agent:trainer", "train", ["crawl"])["dataset"], "a" * 64)["model"]
book_model = p.model(p.dataset("agent:trainer", "train", ["books"])["dataset"], "b" * 64)["model"]
print("crawl manifests:", [r[:10] for r in crawl])
assert len(crawl) == 3
Output (captured at build)
crawl manifests: ['991564bb4b', '69a689e079', 'd4ea244489']
Week 2 was poisoned #
with Workspace(p.path, actor="agent:docs") as ws:
att = ingest.attested(ws)
p.revoke(attestation=att[crawl[1]], reason="week 2 scrape poisoned")
with Workspace(p.path, actor="agent:docs") as ws:
aff = ops.affected(ws, p.reg)
status = lambda r: provenance.verify_attestation(ws, p.reg, r, affected=aff)["status"]
weeks = [status(att[r]) for r in crawl]
states = {m["model"]: m["state"] for m in p.models()}
print("weeks:", weeks)
print("web model:", states[web_model], " book model:", states[book_model])
assert weeks == ["valid", "revoked", "revoked"]
assert states[web_model] == "revoked" and states[book_model] == "usable"
Output (captured at build)
weeks: ['valid', 'revoked', 'revoked'] web model: revoked book model: usable
Week 1 stays valid, weeks 2 and 3 (and everything built on them) are revoked, and the model trained only on books is untouched.