-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrun_ui.py
More file actions
104 lines (83 loc) · 3.51 KB
/
Copy pathrun_ui.py
File metadata and controls
104 lines (83 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""Run the AICM-to-FAIR-CAM evaluation and display results in the validation UI."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
sys.path.insert(0, str(Path(__file__).parent.parent))
RESULTS_DIR = Path(__file__).parent.parent / "results"
REPORT_PATH = RESULTS_DIR / "report.json"
SAMPLE_PLAN_PATH = RESULTS_DIR / "sample_plan.json"
from llm_classification_validator.models import EvaluationReport
from llm_classification_validator.coherence.sampling import SamplePlan
from llm_classification_validator.ui import launch
def run_fresh():
"""Run the full evaluation and save results."""
from examples.aicm_to_faircam import (
CONTROLS,
EXPERT_DOMAIN_MAPPINGS,
map_control,
run_coherence,
run_consistency,
run_convergent,
run_adversarial,
run_stability,
_USE_LLM,
)
from llm_classification_validator.coherence.sampling import compute_sample_plan
from llm_classification_validator.runner import run_evaluation
from llm_classification_validator.models import ItemReport
mode = "LLM (Claude)" if _USE_LLM else "keyword fallback"
print(f"Classifier: {mode}\n")
report = run_evaluation(
foundation=[run_coherence, run_consistency, run_convergent],
advanced=[run_adversarial, run_stability],
parallel_advanced=True,
)
issues_by_id = {item.item_id: item.issues for item in report.items}
report.items = []
for i, ctrl in enumerate(CONTROLS):
mapping = map_control(ctrl["description"])
expert_domain = EXPERT_DOMAIN_MAPPINGS[i]
issues = issues_by_id.get(ctrl["id"], [])
report.items.append(ItemReport(
item_id=ctrl["id"],
label=ctrl["description"][:80] + ("..." if len(ctrl["description"]) > 80 else ""),
predicted={"domain": mapping["domain"], **{k: v for k, v in mapping.items() if k != "domain"}},
reference={"domain": expert_domain},
issues=issues,
))
sample_items = []
for i, ctrl in enumerate(CONTROLS):
mapping = map_control(ctrl["description"])
sample_items.append({
"id": ctrl["id"],
"source_category": ctrl["id"].split("-")[0],
"target_category": mapping["domain"],
})
sample_plan = compute_sample_plan(sample_items)
report.save(REPORT_PATH)
sample_plan.save(SAMPLE_PLAN_PATH)
print(f"\nResults saved to {RESULTS_DIR}/")
return report, sample_plan
def load_cached():
"""Load previously saved results."""
report = EvaluationReport.load(REPORT_PATH)
sample_plan = SamplePlan.load(SAMPLE_PLAN_PATH)
print(f"Loaded cached results from {RESULTS_DIR}/")
return report, sample_plan
if __name__ == "__main__":
force = "--force" in sys.argv
if not force and REPORT_PATH.exists() and SAMPLE_PLAN_PATH.exists():
report, sample_plan = load_cached()
else:
report, sample_plan = run_fresh()
print(f"Overall: {report.overall_verdict.value}")
for dim in report.dimensions:
print(f" {dim.dimension}: {dim.verdict.value} ({len(dim.item_issues)} item issues)")
print(f" {len(report.items)} items")
print(f" Sample plan: {sample_plan.sample_size}/{sample_plan.total_items} items, "
f"{'sufficient' if sample_plan.sufficient else 'INSUFFICIENT'}")
if sample_plan.warnings:
for w in sample_plan.warnings:
print(f" ! {w}")
print("\nLaunching UI...")
launch(report, sample_plan=sample_plan)