Download tests/test_drill_graph_subgroups.py from haidang2405/telen: direct link, hf CLI and curl.
- Browser
- Download file 1.58 kB
-
https://huggingface.co/haidang2405/telen/resolve/main/tests/test_drill_graph_subgroups.py
- Command line
-
hf download hf://haidang2405/telen/tests/test_drill_graph_subgroups.py
-
curl -L -o test_drill_graph_subgroups.py https://huggingface.co/haidang2405/telen/resolve/main/tests/test_drill_graph_subgroups.py
1.58 kB
| from __future__ import annotations | |
| import numpy as np | |
| from scripts.analyze_drill_graph_subgroups import ( | |
| build_subgroup_masks, | |
| summarize_subgroups, | |
| ) | |
| def test_build_subgroup_masks_separates_same_and_multi_document_qrels() -> None: | |
| documents = ("law-a", "law-a", "law-b", "law-c") | |
| qrels = (frozenset({0}), frozenset({0, 1}), frozenset({1, 2})) | |
| masks = build_subgroup_masks( | |
| documents, | |
| qrels, | |
| np.asarray([False, True, True]), | |
| np.asarray([False, False, True]), | |
| ) | |
| assert masks["single_qrel"].tolist() == [True, False, False] | |
| assert masks["multiple_qrels_single_gold_document"].tolist() == [False, True, False] | |
| assert masks["multiple_gold_documents"].tolist() == [False, False, True] | |
| assert masks["gold_document_incident_to_exposed_causal_link"].tolist() == [ | |
| False, | |
| False, | |
| True, | |
| ] | |
| def test_subgroup_summary_uses_paired_differences() -> None: | |
| observations = { | |
| "graph": np.asarray([0.8, 0.6, 0.4]), | |
| "text": np.asarray([0.7, 0.5, 0.5]), | |
| "sham": np.asarray([0.6, 0.4, 0.3]), | |
| "causal_ablation": np.asarray([0.75, 0.55, 0.4]), | |
| } | |
| summary = summarize_subgroups( | |
| observations, | |
| {"first_two": np.asarray([True, True, False])}, | |
| bootstrap_samples=100, | |
| bootstrap_seed=7, | |
| ) | |
| subgroup = summary["first_two"] | |
| assert subgroup["query_count"] == 2 | |
| assert np.isclose(subgroup["graph_minus_text"]["observed_difference"], 0.1) | |
| assert np.isclose(subgroup["graph_minus_sham"]["observed_difference"], 0.2) | |