Spaces:
Running
Running
Download toolkit/diagnostics.py from Giuliocc/tacitus-source-lab: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/spaces/Giuliocc/tacitus-source-lab/resolve/main/toolkit/diagnostics.py
- Command line
-
hf download hf://spaces/Giuliocc/tacitus-source-lab/toolkit/diagnostics.py
-
curl -L -o diagnostics.py https://huggingface.co/spaces/Giuliocc/tacitus-source-lab/resolve/main/toolkit/diagnostics.py
1.73 kB
| """Run synthetic Evidence diagnostics and optionally compare with a reviewed DOXA checkout.""" | |
| import argparse | |
| import importlib.util | |
| import json | |
| from pathlib import Path | |
| from tacitus_nlp import Evidence | |
| def doxa_predictor(folder): | |
| spec = importlib.util.spec_from_file_location("doxa_verifier", folder / "verifier.py") | |
| module = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(module) | |
| adapter = module.load_adapter(folder / "adapter.json") | |
| encoder = module.FrozenEncoder() | |
| def predict(text, claim): | |
| raw = module.infer(text, claim, adapter, encoder) | |
| neutral = {"insufficient_context": "insufficient_information"} | |
| return {"verdict": neutral.get(raw["decision"], raw["decision"]), | |
| "scores": {neutral.get(key, key): value for key, value in raw["scores"].items()}} | |
| return predict | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--doxa-folder", type=Path, help="Local, reviewed verifier.py and adapter.json") | |
| args = parser.parse_args() | |
| engine = Evidence.from_pretrained() | |
| doxa = doxa_predictor(args.doxa_folder) if args.doxa_folder else None | |
| fixtures = Path(__file__).parent / "fixtures/evidence.jsonl" | |
| results = [] | |
| for line in fixtures.read_text().splitlines(): | |
| row = json.loads(line) | |
| nli = engine.check(passage=row["text"], claim=row["claim"], document_id=row["document_id"]) | |
| result = {"document_id": row["document_id"], "expected": row["label"], "nli": nli} | |
| if doxa: | |
| result["doxa"] = doxa(row["text"], row["claim"]) | |
| results.append(result) | |
| print(json.dumps(results, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |