Download expansion_v2/experiments/source-span/tools/analyze_failures.py from Giuliocc/doxa-methods: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/datasets/Giuliocc/doxa-methods/resolve/main/expansion_v2/experiments/source-span/tools/analyze_failures.py
- Command line
-
hf download hf://datasets/Giuliocc/doxa-methods/expansion_v2/experiments/source-span/tools/analyze_failures.py
-
curl -L -o analyze_failures.py https://huggingface.co/datasets/Giuliocc/doxa-methods/resolve/main/expansion_v2/experiments/source-span/tools/analyze_failures.py
2.29 kB
| """Aggregate boundary failure shapes; never publish source rows or annotations.""" | |
| import argparse | |
| from collections import Counter, defaultdict | |
| import json | |
| from pathlib import Path | |
| import probe | |
| def overlaps(a, b): | |
| return min(a[1], b[1]) > max(a[0], b[0]) | |
| def main(split): | |
| if split == "test": | |
| probe.unlock_receipt() | |
| root = Path(__file__).resolve().parent | |
| records = json.loads((root / f"work/private/{split}_predictions.json").read_text()) | |
| counts = defaultdict(Counter) | |
| for record in records: | |
| key = record["method"] + "/" + record["head"] | |
| gold = sorted(set(tuple(x) for x in record["gold"])) | |
| predicted = sorted(set(tuple(x) for x in record["predicted"])) | |
| counts[key]["reference_spans"] += len(gold) | |
| counts[key]["predicted_spans"] += len(predicted) | |
| for span in predicted: | |
| matches = [x for x in gold if overlaps(span, x)] | |
| if span in gold: | |
| counts[key]["exact_reference_matches"] += 1 | |
| elif not matches: | |
| counts[key]["predicted_spans_without_reference_overlap"] += 1 | |
| elif len(matches) == 1: | |
| counts[key]["partial_boundary_spans"] += 1 | |
| else: | |
| counts[key]["predicted_spans_touching_multiple_references"] += 1 | |
| for span in gold: | |
| matches = [x for x in predicted if overlaps(span, x)] | |
| if not matches: | |
| counts[key]["reference_spans_without_prediction_overlap"] += 1 | |
| elif len(matches) > 1: | |
| counts[key]["reference_spans_fragmented_across_predictions"] += 1 | |
| result = {"split": split, "scope": "exploratory aggregate geometry after fixed scoring; no threshold/model changes", | |
| "source_rows_published": False, "reference_unmatched_is_not_proof_of_harmless_or_biased_language": True, | |
| "methods_heads": {key: dict(value) for key, value in counts.items()}} | |
| (root / f"public/{split.upper()}_FAILURE_GEOMETRY.json").write_text(json.dumps(result, indent=2) + "\n") | |
| print(json.dumps(result, indent=2)) | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--split", choices=("validation", "test"), default="validation") | |
| main(parser.parse_args().split) | |