Download tools/challenge.py from Giuliocc/doxa-methods: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/datasets/Giuliocc/doxa-methods/resolve/main/tools/challenge.py
- Command line
-
hf download hf://datasets/Giuliocc/doxa-methods/tools/challenge.py
-
curl -L -o challenge.py https://huggingface.co/datasets/Giuliocc/doxa-methods/resolve/main/tools/challenge.py
1.71 kB
| """Score context-switch diagnostics with templates held outside training.""" | |
| import csv | |
| from build_data import ROOT, digest, json_file | |
| from evidence_model import PortableModel, evaluate | |
| def run(): | |
| rows=[] | |
| with (ROOT/"corpus"/"context_challenge.tsv").open() as file: | |
| for record in csv.DictReader(file,delimiter="\t"): | |
| for label in ("asserted","attributed"): | |
| context=record[f"{label}_context"] | |
| cue=record[f"{label}_evidence"] | |
| offset=context.index(cue) | |
| rows.append({"unit_id":digest(record["event_id"]+"|"+label)[:18], | |
| "event_id":record["event_id"],"family":"context_flip", | |
| "text":record["passage"],"context":context,"label":label, | |
| "origin":"fictional","annotation_status":"ai_provisional", | |
| "reference_span":{"segment":"context","start":offset,"end":offset+len(cue),"quote":cue}}) | |
| work=ROOT/"work" | |
| import pyarrow as pa | |
| import pyarrow.parquet as pq | |
| pq.write_table(pa.Table.from_pylist(rows),work/"context_challenge.parquet") | |
| model=PortableModel(work/"model.json") | |
| report={mode:evaluate(model,rows,mode) for mode in ("passage_only","with_context")} | |
| report["status"]="Fictional manual diagnostics added after model design. No tuning on them." | |
| json_file(work/"challenge_results.json",report) | |
| for mode in ("passage_only","with_context"): | |
| stats=report[mode] | |
| print(mode,stats["paired_both_correct"],"/",stats["paired_context_switches"], | |
| "both decisions correct", round(stats["coverage"],3),"coverage") | |
| if __name__=="__main__": | |
| run() | |