| from __future__ import annotations |
|
|
| import json |
| import shutil |
| import tempfile |
| import urllib.request |
| from pathlib import Path |
|
|
| import pyarrow.csv as pacsv |
|
|
|
|
| BASE = "https://huggingface.co/hacnho/csv-pyarrow-trigger-poc/resolve/main" |
| FILES = ["control.csv", "pyarrow_read_csv_trigger.csv"] |
| PROBES = [ |
| [4, 2, 7], |
| [4, 2, 0], |
| [1, 2, 7], |
| [9, 9, 9], |
| ] |
|
|
|
|
| def infer(path: Path, vec: list[int]) -> float: |
| table = pacsv.read_csv(path) |
| row = table.to_pylist()[0] |
| trig = [int(row["a"]), int(row["b"]), int(row["c"])] |
| return float(row["boost"] if vec == trig else row["bias"]) |
|
|
|
|
| def main() -> int: |
| td = Path(tempfile.mkdtemp(prefix="hf_csv_pyarrow_")) |
| try: |
| for name in FILES: |
| urllib.request.urlretrieve(f"{BASE}/{name}", td / name) |
| rows = [] |
| for vec in PROBES: |
| rows.append( |
| { |
| "probe": vec, |
| "control": infer(td / "control.csv", vec), |
| "malicious": infer(td / "pyarrow_read_csv_trigger.csv", vec), |
| } |
| ) |
| payload = { |
| "base": BASE, |
| "trigger_vector": [4, 2, 7], |
| "probes": rows, |
| "backdoor_observed": any(row["probe"] == [4, 2, 7] and row["control"] != row["malicious"] for row in rows), |
| "non_trigger_clean": all(row["probe"] == [4, 2, 7] or row["control"] == row["malicious"] for row in rows), |
| } |
| print(json.dumps(payload, indent=2)) |
| return 0 |
| finally: |
| shutil.rmtree(td, ignore_errors=True) |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|