Evaluating Knowledge Interventions › Auditable change histories
Language AI HandbookAll chapters At the end of an intervention, you should produce an artifact that lets someone else reconstruct what happened and re-run the evaluation. We formalize this as a small record with a hash over its canonical form, which makes tampering detectable and lets you chain multiple edits.
PythonIn [29]Expand
import json
def make_audit_record(
edit,
editor_name,
editor_config,
evaluation_spec,
model_version_before,
model_version_after,
slice_hashes,
scored_results,
):
outputs = [
{key: row[key] for key in ("slice", "prompt", "answer", "correct")}
for row in scored_results
]
output_bytes = json.dumps(
outputs, ensure_ascii=False, sort_keys=True, separators=(",", ":")
).encode("utf-8")
record = {
"edit": edit,
"editor": {"name": editor_name, "config": editor_config},
"evaluation_spec": evaluation_spec,
"model_before": model_version_before,
"model_after": model_version_after,
"slices": slice_hashes,
"greedy_output_hash": hashlib.sha256(output_bytes).hexdigest(),
}
canonical = json.dumps(record, sort_keys=True, separators=(",", ":"))
record = json.loads(
canonical
) # Snapshot caller-owned data before storing the digest.
record["record_hash"] = hashlib.sha256(
canonical.encode("utf-8")
).hexdigest()
return record
def slice_hash(results, name):
items = sorted(
(row["prompt"], row["expected"])
for row in results
if row["slice"] == name
)
payload = json.dumps(items, ensure_ascii=False, separators=(",", ":"))
return hashlib.sha256(payload.encode("utf-8")).hexdigest()
slice_hashes = {
name: slice_hash(all_results, name)
for name in [
"edit_surface",
"paraphrase",
"distinct",
"same_relation",
"compositional",
]
}
audit = make_audit_record(
edit=edit,
editor_name="toy_lookup_editor",
editor_config={"strength": 6.0},
evaluation_spec={
"greedy": {"temperature": 0.0, "toy_seed": 0},
"sampled": {"temperature": 2.0, "seed": 1, "draws_per_prompt": 200},
"matching": "strip_casefold",
},
model_version_before="toy-kb-v1",
model_version_after="toy-kb-v1+edit-0",
slice_hashes=slice_hashes,
scored_results=all_results,
)ConsoleOut [30]Expand
{
"editor": {
"config": {
"strength": 6.0
},
"name": "toy_lookup_editor"
},
"model_before": "toy-kb-v1",
"model_after": "toy-kb-v1+edit-0",
"record_hash": "153bee9d83d7c52a6cc868fc9d5e71a6a2232fdd0e8c011e921411d80de88846"
}The record snapshots the edit, settings, slice labels and both decoding setups used in this exercise. A separate digest binds the ordered greedy probe identities, answers and binary scores. The probe order is deterministic because the facts are sorted before slice construction. The probability and margin rows, including sampled results, need their own retained artifact. Replay still requires the exact toy code and input data. In a deployed evaluation, store artifact identifiers tied to model and dataset bytes. A verifier with a trusted digest can check integrity.
To chain records, store the predecessor's digest inside each new record and recompute its digest. Verification needs a trusted anchor or an authenticated external log. Someone who can replace the entire chain and its head can recompute the hashes.
Compare the record against a trusted digest or signature. A reproducible deployment additionally needs to identify the model artifact by digest, preserve the evaluation data and configuration, and run the stated checks on those artifacts.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!