Download code/check_overlap.py from SamJoshua/terse-tool-output-heldout: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/datasets/SamJoshua/terse-tool-output-heldout/resolve/main/code/check_overlap.py
- Command line
-
hf download hf://datasets/SamJoshua/terse-tool-output-heldout/code/check_overlap.py
-
curl -L -o check_overlap.py https://huggingface.co/datasets/SamJoshua/terse-tool-output-heldout/resolve/main/code/check_overlap.py
1.84 kB
| """Overlap checks: thread strings, the 408-row bench, and the strings Horizon's gen_terse.py generates (train+test negatives).""" | |
| import json, sys, importlib.util | |
| import pandas as pd | |
| from huggingface_hub import hf_hub_download | |
| rows=[json.loads(l) for l in open("data/terse_heldout.jsonl")] | |
| texts={r["text"] for r in rows}; inners={r["inner_text"] for r in rows} | |
| thread=['{"jsonrpc":"2.0","id":"q3481","result":{"content":[{"type":"text","text":"probe q3481 ok n=11"}],"isError":false}}', | |
| '{"content":[{"type":"text","text":"probe q3481 ok n=11"}],"isError":false}','probe q3481 ok n=11','q3481 ok n=11','ping q3481 ok n=11','probe', | |
| 'Probe q3481 returned OK (n=11).','status: ok, rows: 11','Order ord_3000 delivered to Example City.','done','job 77 finished exit=0','ack','OK','sync ok 3/3','200 OK'] | |
| bench=set(pd.read_parquet(hf_hub_download("SamJoshua/tool-output-injection-bench","data/all.parquet",repo_type="dataset")).text) | |
| from huggingface_hub import hf_hub_download | |
| gtp=hf_hub_download("Horizon-Labs/prompt-injection-guard-small","code/inj/gen_terse.py",revision="v2.6") | |
| spec=importlib.util.spec_from_file_location("gt",gtp); gt=importlib.util.module_from_spec(spec); spec.loader.exec_module(gt) | |
| tn,_=gt.make("train",6000,[],11); sn,_=gt.make("test",600,[],12) | |
| hz=set(tn.text)|set(sn.text) | |
| res={"rows":len(rows),"unique_text":len(texts)==len(rows), | |
| "thread_exact_text":len(texts&set(thread)),"thread_exact_inner":len(inners&set(thread)), | |
| "bench_exact":len(texts&bench),"bench_inner":len(inners&bench), | |
| "gen_terse_negatives_generated":len(hz),"gen_terse_exact_text":len(texts&hz),"gen_terse_exact_inner":len(inners&hz), | |
| "unique_inner_benign":len({r["inner_text"] for r in rows if not r["label"]}), | |
| "unique_attack_sentences":22} | |
| print(json.dumps(res,indent=1)); json.dump(res,open("results/overlap_check.json","w"),indent=1) | |