Download tools/validate_submission.py from WaguyMZ/ForensicBench: direct link, hf CLI and curl.
- Browser
- Download file 2.4 kB
-
https://huggingface.co/datasets/WaguyMZ/ForensicBench/resolve/main/tools/validate_submission.py
- Command line
-
hf download hf://datasets/WaguyMZ/ForensicBench/tools/validate_submission.py
-
curl -L -o validate_submission.py https://huggingface.co/datasets/WaguyMZ/ForensicBench/resolve/main/tools/validate_submission.py
2.4 kB
| """Check a ForensicBench submission file before uploading it. | |
| Usage: | |
| python tools/validate_submission.py my_flags.csv --data-dir data | |
| Expected columns: sector, document_id, scheme_type, plus replicate for the multi run format | |
| (`rationale` is optional). Sectors: energy, healthcare, luxurygoods, manufacturing, transport. | |
| Scheme types: fictitious_ap_disbursements, revenue_manipulation, vendor_collusion, | |
| shadow_payroll, inventory_manipulation. | |
| """ | |
| import argparse, sys | |
| import pandas as pd | |
| SECTORS = ["energy", "healthcare", "luxurygoods", "manufacturing", "transport"] | |
| TYPES = {"fictitious_ap_disbursements", "revenue_manipulation", "vendor_collusion", "shadow_payroll", "inventory_manipulation", "unknown"} | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("file") | |
| ap.add_argument("--data-dir", default="data") | |
| a = ap.parse_args() | |
| df = pd.read_csv(a.file, dtype=str) if a.file.endswith(".csv") else pd.read_json(a.file, lines=True, dtype=str) | |
| errors = [] | |
| for c in ["sector", "document_id", "scheme_type"]: | |
| if c not in df.columns: | |
| errors.append(f"missing column: {c}") | |
| if errors: | |
| print("\n".join(errors)); sys.exit(1) | |
| bad = set(df["sector"]) - set(SECTORS) | |
| if bad: errors.append(f"unknown sectors: {sorted(bad)}") | |
| bad = set(df["scheme_type"]) - TYPES | |
| if bad: errors.append(f"unknown scheme types: {sorted(bad)}") | |
| for s in sorted(set(df["sector"]) & set(SECTORS)): | |
| ids = set(pd.read_parquet(f"{a.data_dir}/{s}/je_header.parquet", columns=["document_id"])["document_id"].str.lower()) | |
| sub = df[df["sector"] == s]["document_id"].str.lower() | |
| unknown = set(sub) - ids | |
| if unknown: | |
| print(f"warning: {s}: {len(unknown)} document_id values are not in the ledger (they count as false positives)") | |
| if len(set(df["sector"]) & set(SECTORS)) < 5: | |
| errors.append("a submission must cover all 5 sectors") | |
| if "replicate" in df.columns: | |
| reps = df.groupby("sector")["replicate"].nunique().to_dict() | |
| print("replicates per sector:", reps) | |
| if any(v < 5 for v in reps.values()): | |
| print("note: the full protocol uses 5 replicates per sector (25 runs)") | |
| else: | |
| print("single run format (no replicate column)") | |
| if errors: | |
| print("\n".join(errors)); sys.exit(1) | |
| print("OK") | |
| if __name__ == "__main__": | |
| main() | |