audit: composite AUDIT_PASSED verdict; missing shards are unmeasured, not clean
Browse files- build/audit_contamination.py +17 -0
build/audit_contamination.py
CHANGED
|
@@ -129,10 +129,14 @@ def main():
|
|
| 129 |
hits = {k: 0 for k in ref_sets}
|
| 130 |
hits_by_source = {}
|
| 131 |
docs = grams_seen = 0
|
|
|
|
| 132 |
import build_mix as BM
|
| 133 |
for rec in man["shards"]:
|
| 134 |
p = os.path.join(a.root, rec["file"])
|
| 135 |
if not os.path.exists(p):
|
|
|
|
|
|
|
|
|
|
| 136 |
continue
|
| 137 |
for d in BM.iter_shard_docs(p):
|
| 138 |
docs += 1
|
|
@@ -150,22 +154,35 @@ def main():
|
|
| 150 |
if docs % 200000 < 5000:
|
| 151 |
print(f" audited {docs:,} docs, {grams_seen:,} mix grams", flush=True)
|
| 152 |
|
|
|
|
| 153 |
report = {
|
| 154 |
"k": K,
|
| 155 |
"reference": {k: {"distinct_grams": len(v)} for k, v in ref_sets.items()},
|
| 156 |
"reference_unreadable": errors,
|
|
|
|
|
|
|
| 157 |
"mix_documents_audited": docs,
|
| 158 |
"mix_grams_audited": grams_seen,
|
| 159 |
"overlap_grams_total_by_ref": hits,
|
| 160 |
"overlap_rate_by_ref": {k: round(v / max(1, grams_seen), 8) for k, v in hits.items()},
|
| 161 |
"overlap_by_source": hits_by_source,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
"note": ("counts only; no item text was read or printed. Reference splits are train/validation/dev "
|
| 163 |
"per task -- never test, per §3.3. Any source with a non-zero overlap here must be dropped "
|
| 164 |
"or cleaned before Gate 2 is claimed."),
|
| 165 |
}
|
|
|
|
|
|
|
| 166 |
print("AUDIT_JSON_BEGIN")
|
| 167 |
print(json.dumps(report, indent=1, default=str))
|
| 168 |
print("AUDIT_JSON_END")
|
|
|
|
| 169 |
|
| 170 |
|
| 171 |
if __name__ == "__main__":
|
|
|
|
| 129 |
hits = {k: 0 for k in ref_sets}
|
| 130 |
hits_by_source = {}
|
| 131 |
docs = grams_seen = 0
|
| 132 |
+
missing = []
|
| 133 |
import build_mix as BM
|
| 134 |
for rec in man["shards"]:
|
| 135 |
p = os.path.join(a.root, rec["file"])
|
| 136 |
if not os.path.exists(p):
|
| 137 |
+
# A shard that is not on disk is not "clean", it is unmeasured. Silence here would let an
|
| 138 |
+
# audit over an empty directory report zero contamination (E-017's shape).
|
| 139 |
+
missing.append(rec["file"])
|
| 140 |
continue
|
| 141 |
for d in BM.iter_shard_docs(p):
|
| 142 |
docs += 1
|
|
|
|
| 154 |
if docs % 200000 < 5000:
|
| 155 |
print(f" audited {docs:,} docs, {grams_seen:,} mix grams", flush=True)
|
| 156 |
|
| 157 |
+
total_overlap = sum(hits.values())
|
| 158 |
report = {
|
| 159 |
"k": K,
|
| 160 |
"reference": {k: {"distinct_grams": len(v)} for k, v in ref_sets.items()},
|
| 161 |
"reference_unreadable": errors,
|
| 162 |
+
"shards_expected": len(man["shards"]),
|
| 163 |
+
"shards_missing": missing,
|
| 164 |
"mix_documents_audited": docs,
|
| 165 |
"mix_grams_audited": grams_seen,
|
| 166 |
"overlap_grams_total_by_ref": hits,
|
| 167 |
"overlap_rate_by_ref": {k: round(v / max(1, grams_seen), 8) for k, v in hits.items()},
|
| 168 |
"overlap_by_source": hits_by_source,
|
| 169 |
+
# Composite, so Gate 2 cannot be claimed on an audit that measured nothing. Every clause here
|
| 170 |
+
# has been observed to fail independently: unreadable refs, absent shards, zero docs.
|
| 171 |
+
"COVERED_ALL_SHARDS": not missing and len(man["shards"]) > 0,
|
| 172 |
+
"MEASURED": docs > 0 and grams_seen > 0 and len(ref_sets) >= 6 and not errors,
|
| 173 |
+
"CLEAN": total_overlap == 0,
|
| 174 |
+
"AUDIT_PASSED": bool(not missing and man["shards"] and docs > 0 and grams_seen > 0
|
| 175 |
+
and len(ref_sets) >= 6 and not errors and total_overlap == 0),
|
| 176 |
"note": ("counts only; no item text was read or printed. Reference splits are train/validation/dev "
|
| 177 |
"per task -- never test, per §3.3. Any source with a non-zero overlap here must be dropped "
|
| 178 |
"or cleaned before Gate 2 is claimed."),
|
| 179 |
}
|
| 180 |
+
print(f"VERDICT AUDIT_PASSED={report['AUDIT_PASSED']} docs={docs:,} overlap={total_overlap} "
|
| 181 |
+
f"missing_shards={len(missing)} refs_ok={len(ref_sets)} refs_failed={len(errors)}")
|
| 182 |
print("AUDIT_JSON_BEGIN")
|
| 183 |
print(json.dumps(report, indent=1, default=str))
|
| 184 |
print("AUDIT_JSON_END")
|
| 185 |
+
raise SystemExit(0 if report["AUDIT_PASSED"] else (6 if report["MEASURED"] else 7))
|
| 186 |
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|