rho-eval 2.2.1__tar.gz → 2.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. {rho_eval-2.2.1 → rho_eval-2.2.2}/PKG-INFO +1 -1
  2. {rho_eval-2.2.1 → rho_eval-2.2.2}/pyproject.toml +3 -1
  3. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/__init__.py +3 -0
  4. rho_eval-2.2.2/src/rho_eval/benchmarking/leaderboard.py +281 -0
  5. rho_eval-2.2.2/src/rho_eval/benchmarking/probe_registry.py +315 -0
  6. rho_eval-2.2.2/src/rho_eval/cli/rho_hybrid.py +199 -0
  7. rho_eval-2.2.2/src/rho_eval/cli/rho_leaderboard.py +189 -0
  8. rho_eval-2.2.2/src/rho_eval/hybrid/__init__.py +44 -0
  9. rho_eval-2.2.2/src/rho_eval/hybrid/pipeline.py +434 -0
  10. rho_eval-2.2.2/src/rho_eval/hybrid/schema.py +254 -0
  11. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/steering/collect.py +7 -8
  12. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval.egg-info/PKG-INFO +1 -1
  13. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval.egg-info/SOURCES.txt +7 -0
  14. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval.egg-info/entry_points.txt +2 -0
  15. {rho_eval-2.2.1 → rho_eval-2.2.2}/LICENSE +0 -0
  16. {rho_eval-2.2.1 → rho_eval-2.2.2}/README.md +0 -0
  17. {rho_eval-2.2.1 → rho_eval-2.2.2}/setup.cfg +0 -0
  18. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/__init__.py +0 -0
  19. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/__main__.py +0 -0
  20. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/audit.py +0 -0
  21. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/behavioral.py +0 -0
  22. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/behaviors/__init__.py +0 -0
  23. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/behaviors/base.py +0 -0
  24. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/behaviors/bias.py +0 -0
  25. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/behaviors/factual.py +0 -0
  26. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/behaviors/metrics.py +0 -0
  27. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/behaviors/reasoning.py +0 -0
  28. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/behaviors/sycophancy.py +0 -0
  29. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/behaviors/toxicity.py +0 -0
  30. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/calibration.py +0 -0
  31. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/cartography/__init__.py +0 -0
  32. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/cartography/engine.py +0 -0
  33. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/cartography/schema.py +0 -0
  34. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/cli/__init__.py +0 -0
  35. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/cli/rho_audit.py +0 -0
  36. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/core.py +0 -0
  37. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/denoise.py +0 -0
  38. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/output/__init__.py +0 -0
  39. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/output/comparator.py +0 -0
  40. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/output/exporters.py +0 -0
  41. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/output/schema.py +0 -0
  42. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/__init__.py +0 -0
  43. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/data/bias/bbq_300.json +0 -0
  44. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/data/factual/commonsense.json +0 -0
  45. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/data/factual/default.json +0 -0
  46. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/data/factual/mandela.json +0 -0
  47. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/data/factual/medical.json +0 -0
  48. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/data/factual/truthfulqa.json +0 -0
  49. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/data/reasoning/gsm8k_100.json +0 -0
  50. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/data/sycophancy/anthropic_150.json +0 -0
  51. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/data/toxicity/toxigen_200.json +0 -0
  52. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/probes/registry.py +0 -0
  53. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/svd/__init__.py +0 -0
  54. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/svd/compress.py +0 -0
  55. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/svd/freeze.py +0 -0
  56. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/svd/importance.py +0 -0
  57. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/knowledge_fidelity/utils.py +0 -0
  58. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/__main__.py +0 -0
  59. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/_compat.py +0 -0
  60. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/alignment/__init__.py +0 -0
  61. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/alignment/dataset.py +0 -0
  62. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/alignment/losses.py +0 -0
  63. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/alignment/mlx_losses.py +0 -0
  64. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/alignment/mlx_trainer.py +0 -0
  65. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/alignment/trainer.py +0 -0
  66. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/audit.py +0 -0
  67. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behavioral.py +0 -0
  68. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/__init__.py +0 -0
  69. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/base.py +0 -0
  70. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/bias.py +0 -0
  71. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/deception.py +0 -0
  72. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/factual.py +0 -0
  73. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/metrics.py +0 -0
  74. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/overrefusal.py +0 -0
  75. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/reasoning.py +0 -0
  76. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/refusal.py +0 -0
  77. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/sycophancy.py +0 -0
  78. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/behaviors/toxicity.py +0 -0
  79. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/benchmarking/__init__.py +0 -0
  80. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/benchmarking/adversarial.py +0 -0
  81. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/benchmarking/loader.py +0 -0
  82. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/benchmarking/reports.py +0 -0
  83. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/benchmarking/schema.py +0 -0
  84. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/benchmarking/scorers.py +0 -0
  85. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/calibration.py +0 -0
  86. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/cartography/__init__.py +0 -0
  87. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/cartography/engine.py +0 -0
  88. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/cartography/schema.py +0 -0
  89. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/cli/__init__.py +0 -0
  90. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/cli/rho_align.py +0 -0
  91. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/cli/rho_audit.py +0 -0
  92. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/cli/rho_bench.py +0 -0
  93. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/cli/rho_interpret.py +0 -0
  94. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/cli/rho_steer.py +0 -0
  95. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/core.py +0 -0
  96. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/denoise.py +0 -0
  97. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/interpretability/__init__.py +0 -0
  98. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/interpretability/activation.py +0 -0
  99. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/interpretability/heads.py +0 -0
  100. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/interpretability/overlap.py +0 -0
  101. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/interpretability/schema.py +0 -0
  102. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/interpretability/subspaces.py +0 -0
  103. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/interpretability/surgical.py +0 -0
  104. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/interpretability/visualize.py +0 -0
  105. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/output/__init__.py +0 -0
  106. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/output/comparator.py +0 -0
  107. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/output/exporters.py +0 -0
  108. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/output/schema.py +0 -0
  109. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/__init__.py +0 -0
  110. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/bench/clinical.json +0 -0
  111. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/bench/logic.json +0 -0
  112. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/bench/social.json +0 -0
  113. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/bias/bbq_300.json +0 -0
  114. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/deception/hh_rlhf_100.json +0 -0
  115. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/factual/commonsense.json +0 -0
  116. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/factual/default.json +0 -0
  117. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/factual/mandela.json +0 -0
  118. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/factual/medical.json +0 -0
  119. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/factual/truthfulqa.json +0 -0
  120. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/overrefusal/benign_edgy_80.json +0 -0
  121. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/reasoning/gsm8k_100.json +0 -0
  122. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/refusal/harmful_benign_100.json +0 -0
  123. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/sycophancy/anthropic_150.json +0 -0
  124. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/data/toxicity/toxigen_200.json +0 -0
  125. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/probes/registry.py +0 -0
  126. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/steering/__init__.py +0 -0
  127. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/steering/analyze.py +0 -0
  128. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/steering/sae.py +0 -0
  129. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/steering/schema.py +0 -0
  130. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/steering/steer.py +0 -0
  131. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/steering/train.py +0 -0
  132. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/svd/__init__.py +0 -0
  133. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/svd/compress.py +0 -0
  134. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/svd/freeze.py +0 -0
  135. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/svd/importance.py +0 -0
  136. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval/utils.py +0 -0
  137. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval.egg-info/dependency_links.txt +0 -0
  138. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval.egg-info/requires.txt +0 -0
  139. {rho_eval-2.2.1 → rho_eval-2.2.2}/src/rho_eval.egg-info/top_level.txt +0 -0
  140. {rho_eval-2.2.1 → rho_eval-2.2.2}/tests/test_alignment.py +0 -0
  141. {rho_eval-2.2.1 → rho_eval-2.2.2}/tests/test_benchmarking.py +0 -0
  142. {rho_eval-2.2.1 → rho_eval-2.2.2}/tests/test_cli.py +0 -0
  143. {rho_eval-2.2.1 → rho_eval-2.2.2}/tests/test_interpretability.py +0 -0
  144. {rho_eval-2.2.1 → rho_eval-2.2.2}/tests/test_metrics.py +0 -0
  145. {rho_eval-2.2.1 → rho_eval-2.2.2}/tests/test_output.py +0 -0
  146. {rho_eval-2.2.1 → rho_eval-2.2.2}/tests/test_probes.py +0 -0
  147. {rho_eval-2.2.1 → rho_eval-2.2.2}/tests/test_registry.py +0 -0
  148. {rho_eval-2.2.1 → rho_eval-2.2.2}/tests/test_steering.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rho-eval
3
- Version: 2.2.1
3
+ Version: 2.2.2
4
4
  Summary: Behavioral auditing toolkit for LLMs — audit any model across 8 dimensions (factual, toxicity, bias, sycophancy, reasoning, refusal, deception, over-refusal) using teacher-forced confidence probes.
5
5
  Author: Bryan Sanchez
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rho-eval"
7
- version = "2.2.1"
7
+ version = "2.2.2"
8
8
  description = "Behavioral auditing toolkit for LLMs — audit any model across 8 dimensions (factual, toxicity, bias, sycophancy, reasoning, refusal, deception, over-refusal) using teacher-forced confidence probes."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -83,6 +83,8 @@ rho-interpret = "rho_eval.cli.rho_interpret:main"
83
83
  rho-align = "rho_eval.cli.rho_align:main"
84
84
  rho-steer = "rho_eval.cli.rho_steer:main"
85
85
  rho-bench = "rho_eval.cli.rho_bench:main"
86
+ rho-hybrid = "rho_eval.cli.rho_hybrid:main"
87
+ rho-leaderboard = "rho_eval.cli.rho_leaderboard:main"
86
88
 
87
89
  [project.urls]
88
90
  Homepage = "https://github.com/SolomonB14D3/knowledge-fidelity"
@@ -56,6 +56,9 @@ from .alignment import (
56
56
  # ── Steering (v2.3) — opt-in, not auto-imported ────────────────────────────
57
57
  # SAE-based behavioral steering: from rho_eval.steering import GatedSAE, ...
58
58
 
59
+ # ── Hybrid Control (v2.4) — opt-in, not auto-imported ───────────────────────
60
+ # Hybrid weight + activation control: from rho_eval.hybrid import HybridConfig, apply_hybrid_control
61
+
59
62
  # ── Benchmarking (v2.5) — Fidelity-Bench 2.0 ─────────────────────────────
60
63
  from .benchmarking import (
61
64
  generate_certificate,
@@ -0,0 +1,281 @@
1
+ """Fidelity-Bench Leaderboard — local and HF Hub leaderboard for model comparison.
2
+
3
+ Tracks model fidelity grades, composite scores, truth-gaps, and domain
4
+ breakdowns across Fidelity-Bench runs. Supports local persistence
5
+ (JSON) and optional push/pull to a HuggingFace Hub dataset.
6
+
7
+ Usage:
8
+ from rho_eval.benchmarking.leaderboard import Leaderboard
9
+
10
+ lb = Leaderboard()
11
+ lb.submit(cert) # Add a FidelityCertificate
12
+ print(lb.to_markdown()) # Ranked table
13
+ lb.save("leaderboard.json")
14
+
15
+ # Compare two models side-by-side
16
+ print(lb.compare("model-a", "model-b"))
17
+
18
+ # Push to HF Hub
19
+ lb.push_to_hub("rho-eval/fidelity-bench")
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ import hashlib
25
+ import json
26
+ from dataclasses import dataclass, field, asdict
27
+ from datetime import datetime, timezone
28
+ from pathlib import Path
29
+ from typing import Optional
30
+
31
+ from .schema import FidelityCertificate
32
+
33
+
34
+ # ── Leaderboard Entry ─────────────────────────────────────────────────────
35
+
36
+ @dataclass
37
+ class LeaderboardEntry:
38
+ """One row in the Fidelity-Bench leaderboard."""
39
+
40
+ model: str
41
+ """Model name or HuggingFace ID."""
42
+
43
+ fidelity_grade: str
44
+ """Letter grade A-F from FidelityCertificate."""
45
+
46
+ composite_score: float
47
+ """Overall fidelity composite (0-1)."""
48
+
49
+ truth_gap: float
50
+ """Mean ΔF = ρ_baseline - ρ_pressured across domains."""
51
+
52
+ domain_scores: dict[str, float] = field(default_factory=dict)
53
+ """Per-domain fidelity scores: {domain: score}."""
54
+
55
+ timestamp: str = field(
56
+ default_factory=lambda: datetime.now(timezone.utc).isoformat()
57
+ )
58
+ """When this entry was created."""
59
+
60
+ cert_hash: str = ""
61
+ """SHA256 hash of the serialized FidelityCertificate for verification."""
62
+
63
+ benchmark_version: str = ""
64
+ """Version of Fidelity-Bench used to generate this entry."""
65
+
66
+ metadata: dict = field(default_factory=dict)
67
+ """Optional metadata (device, runtime, notes)."""
68
+
69
+ def to_dict(self) -> dict:
70
+ return asdict(self)
71
+
72
+
73
+ # ── Leaderboard ───────────────────────────────────────────────────────────
74
+
75
+ class Leaderboard:
76
+ """Local + HF Hub leaderboard for Fidelity-Bench results.
77
+
78
+ Maintains a ranked list of LeaderboardEntry objects, supports
79
+ persistence to JSON, and optional sync with a HuggingFace Hub dataset.
80
+ """
81
+
82
+ def __init__(self, entries: Optional[list[LeaderboardEntry]] = None):
83
+ self.entries: list[LeaderboardEntry] = entries or []
84
+
85
+ def submit(self, cert: FidelityCertificate) -> LeaderboardEntry:
86
+ """Add a FidelityCertificate to the leaderboard.
87
+
88
+ Parameters
89
+ ----------
90
+ cert : FidelityCertificate
91
+ A completed benchmark certificate from generate_certificate().
92
+
93
+ Returns
94
+ -------
95
+ LeaderboardEntry
96
+ The newly created leaderboard entry.
97
+
98
+ Raises
99
+ ------
100
+ ValueError
101
+ If the certificate is missing required fields.
102
+ """
103
+ # TODO: Implement
104
+ # Validate certificate
105
+ # Compute cert hash
106
+ # Extract domain scores from cert
107
+ # Create entry
108
+ # Append to self.entries
109
+ # Return entry
110
+ raise NotImplementedError(
111
+ "Leaderboard.submit() not yet implemented. "
112
+ "See FidelityCertificate schema for the input format."
113
+ )
114
+
115
+ def rank(self, metric: str = "composite") -> list[LeaderboardEntry]:
116
+ """Return entries sorted by metric (descending = better).
117
+
118
+ Parameters
119
+ ----------
120
+ metric : str
121
+ Sort key: "composite", "truth_gap", "grade", or a domain name.
122
+ For truth_gap, lower is better (ascending sort).
123
+
124
+ Returns
125
+ -------
126
+ list[LeaderboardEntry]
127
+ Sorted entries.
128
+ """
129
+ # TODO: Implement
130
+ # if metric == "composite":
131
+ # return sorted(self.entries, key=lambda e: e.composite_score, reverse=True)
132
+ # elif metric == "truth_gap":
133
+ # return sorted(self.entries, key=lambda e: e.truth_gap) # lower = better
134
+ # elif metric == "grade":
135
+ # grade_order = {"A": 5, "B": 4, "C": 3, "D": 2, "F": 1}
136
+ # return sorted(self.entries, key=lambda e: grade_order.get(e.fidelity_grade, 0), reverse=True)
137
+ # else:
138
+ # # Sort by domain score
139
+ # return sorted(self.entries, key=lambda e: e.domain_scores.get(metric, 0), reverse=True)
140
+ raise NotImplementedError(
141
+ "Leaderboard.rank() not yet implemented."
142
+ )
143
+
144
+ def compare(self, model_a: str, model_b: str) -> str:
145
+ """Side-by-side comparison of two models.
146
+
147
+ Parameters
148
+ ----------
149
+ model_a, model_b : str
150
+ Model names to compare (matched against entry.model).
151
+
152
+ Returns
153
+ -------
154
+ str
155
+ Formatted comparison table.
156
+ """
157
+ # TODO: Implement
158
+ # Find entries for model_a and model_b
159
+ # Build side-by-side table: metric | model_a | model_b | delta
160
+ raise NotImplementedError(
161
+ "Leaderboard.compare() not yet implemented."
162
+ )
163
+
164
+ def to_markdown(self) -> str:
165
+ """Render the leaderboard as a Markdown table.
166
+
167
+ Returns
168
+ -------
169
+ str
170
+ Markdown-formatted leaderboard ranked by composite score.
171
+ """
172
+ # TODO: Implement
173
+ # ranked = self.rank("composite")
174
+ # lines = [
175
+ # "# Fidelity-Bench Leaderboard",
176
+ # "",
177
+ # "| Rank | Model | Grade | Composite | Truth-Gap | Date |",
178
+ # "|------|-------|-------|-----------|-----------|------|",
179
+ # ]
180
+ # for i, e in enumerate(ranked, 1):
181
+ # lines.append(
182
+ # f"| {i} | {e.model} | {e.fidelity_grade} | "
183
+ # f"{e.composite_score:.3f} | {e.truth_gap:.4f} | "
184
+ # f"{e.timestamp[:10]} |"
185
+ # )
186
+ # return "\n".join(lines)
187
+ raise NotImplementedError(
188
+ "Leaderboard.to_markdown() not yet implemented."
189
+ )
190
+
191
+ def save(self, path: Path | str) -> None:
192
+ """Save leaderboard to a JSON file.
193
+
194
+ Parameters
195
+ ----------
196
+ path : Path or str
197
+ Output file path.
198
+ """
199
+ path = Path(path)
200
+ data = {
201
+ "version": "1.0.0",
202
+ "updated": datetime.now(timezone.utc).isoformat(),
203
+ "entries": [e.to_dict() for e in self.entries],
204
+ }
205
+ path.write_text(json.dumps(data, indent=2, default=str))
206
+
207
+ @classmethod
208
+ def load(cls, path: Path | str) -> "Leaderboard":
209
+ """Load leaderboard from a JSON file.
210
+
211
+ Parameters
212
+ ----------
213
+ path : Path or str
214
+ Input file path.
215
+
216
+ Returns
217
+ -------
218
+ Leaderboard
219
+ Loaded leaderboard instance.
220
+ """
221
+ path = Path(path)
222
+ data = json.loads(path.read_text())
223
+ entries = [LeaderboardEntry(**e) for e in data.get("entries", [])]
224
+ return cls(entries=entries)
225
+
226
+ def push_to_hub(self, repo_id: str, token: Optional[str] = None) -> str:
227
+ """Push leaderboard data to a HuggingFace Hub dataset.
228
+
229
+ Creates or updates a dataset repository with the leaderboard
230
+ entries as a JSONL file + a rendered README.md.
231
+
232
+ Parameters
233
+ ----------
234
+ repo_id : str
235
+ HuggingFace Hub dataset ID (e.g., "rho-eval/fidelity-bench").
236
+ token : str, optional
237
+ HF API token. If None, uses cached token from `huggingface-cli login`.
238
+
239
+ Returns
240
+ -------
241
+ str
242
+ URL of the pushed dataset.
243
+ """
244
+ # TODO: Implement
245
+ # from huggingface_hub import HfApi, create_repo
246
+ # api = HfApi(token=token)
247
+ # create_repo(repo_id, repo_type="dataset", exist_ok=True, token=token)
248
+ # Save JSONL + README to temp dir
249
+ # api.upload_folder(...)
250
+ # return f"https://huggingface.co/datasets/{repo_id}"
251
+ raise NotImplementedError(
252
+ "Leaderboard.push_to_hub() not yet implemented. "
253
+ "Requires: pip install huggingface-hub"
254
+ )
255
+
256
+ def pull_from_hub(self, repo_id: str, token: Optional[str] = None) -> None:
257
+ """Pull leaderboard data from a HuggingFace Hub dataset.
258
+
259
+ Parameters
260
+ ----------
261
+ repo_id : str
262
+ HuggingFace Hub dataset ID.
263
+ token : str, optional
264
+ HF API token.
265
+ """
266
+ # TODO: Implement
267
+ # from huggingface_hub import hf_hub_download
268
+ # path = hf_hub_download(repo_id, "leaderboard.json",
269
+ # repo_type="dataset", token=token)
270
+ # loaded = Leaderboard.load(path)
271
+ # self.entries = loaded.entries
272
+ raise NotImplementedError(
273
+ "Leaderboard.pull_from_hub() not yet implemented. "
274
+ "Requires: pip install huggingface-hub"
275
+ )
276
+
277
+ def __len__(self) -> int:
278
+ return len(self.entries)
279
+
280
+ def __repr__(self) -> str:
281
+ return f"Leaderboard({len(self.entries)} entries)"
@@ -0,0 +1,315 @@
1
+ """Community Probe Registry — validate and register custom probe domains.
2
+
3
+ Allows community contributions of new probe domains to Fidelity-Bench
4
+ while enforcing quality standards (format, coverage, class balance).
5
+
6
+ Usage:
7
+ from rho_eval.benchmarking.probe_registry import (
8
+ ProbeValidator, register_probe_domain, list_registered_domains,
9
+ )
10
+
11
+ # Validate a new probe set
12
+ validator = ProbeValidator()
13
+ errors = validator.validate_format("my_probes.json")
14
+ if not errors:
15
+ stats = validator.validate_coverage(probes)
16
+ balance = validator.validate_balance(probes)
17
+ print(f"Coverage: {stats}")
18
+ print(f"Balance: {balance}")
19
+
20
+ # Register for use in Fidelity-Bench
21
+ register_probe_domain("my_domain", "my_probes.json", domain_type="custom")
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import json
27
+ import logging
28
+ from dataclasses import dataclass, field
29
+ from pathlib import Path
30
+ from typing import Any, Optional
31
+
32
+ logger = logging.getLogger(__name__)
33
+
34
+
35
+ # ── Required probe fields ────────────────────────────────────────────────
36
+
37
+ REQUIRED_PROBE_FIELDS = {
38
+ "id": str, # Unique identifier (e.g., "custom_001")
39
+ "text": str, # The probe text (claim/question)
40
+ "label": (int, bool), # Ground truth: 1/True = correct, 0/False = incorrect
41
+ }
42
+
43
+ OPTIONAL_PROBE_FIELDS = {
44
+ "category": str, # Sub-category within the domain
45
+ "difficulty": str, # "easy" / "medium" / "hard"
46
+ "source": str, # Where this probe came from
47
+ "notes": str, # Any additional context
48
+ }
49
+
50
+ # Minimum requirements for a valid probe domain
51
+ MIN_PROBES = 20
52
+ MIN_POSITIVE_RATIO = 0.3 # At least 30% positive labels
53
+ MAX_POSITIVE_RATIO = 0.7 # At most 70% positive labels
54
+
55
+
56
+ # ── Probe Validator ──────────────────────────────────────────────────────
57
+
58
+ class ProbeValidator:
59
+ """Validates new probe submissions for Fidelity-Bench.
60
+
61
+ Checks format (required fields, types), coverage (enough probes,
62
+ reasonable diversity), and class balance (not too skewed).
63
+ """
64
+
65
+ def validate_format(self, probes_path: Path | str) -> list[str]:
66
+ """Validate that a probe JSON file has the correct format.
67
+
68
+ Parameters
69
+ ----------
70
+ probes_path : Path or str
71
+ Path to a JSON file containing a list of probe dicts.
72
+
73
+ Returns
74
+ -------
75
+ list[str]
76
+ List of error messages. Empty list = valid.
77
+ """
78
+ # TODO: Implement
79
+ # errors = []
80
+ # try:
81
+ # data = json.loads(Path(probes_path).read_text())
82
+ # except json.JSONDecodeError as e:
83
+ # return [f"Invalid JSON: {e}"]
84
+ #
85
+ # if not isinstance(data, list):
86
+ # return ["Root element must be a JSON array"]
87
+ #
88
+ # ids_seen = set()
89
+ # for i, probe in enumerate(data):
90
+ # if not isinstance(probe, dict):
91
+ # errors.append(f"Probe {i}: not a dict")
92
+ # continue
93
+ # for field_name, expected_type in REQUIRED_PROBE_FIELDS.items():
94
+ # if field_name not in probe:
95
+ # errors.append(f"Probe {i}: missing required field '{field_name}'")
96
+ # elif not isinstance(probe[field_name], expected_type):
97
+ # errors.append(f"Probe {i}: '{field_name}' has wrong type")
98
+ # if "id" in probe:
99
+ # if probe["id"] in ids_seen:
100
+ # errors.append(f"Probe {i}: duplicate id '{probe['id']}'")
101
+ # ids_seen.add(probe["id"])
102
+ # return errors
103
+ raise NotImplementedError(
104
+ "ProbeValidator.validate_format() not yet implemented."
105
+ )
106
+
107
+ def validate_coverage(self, probes: list[dict]) -> dict[str, Any]:
108
+ """Check coverage statistics of a probe set.
109
+
110
+ Parameters
111
+ ----------
112
+ probes : list[dict]
113
+ List of validated probe dicts.
114
+
115
+ Returns
116
+ -------
117
+ dict
118
+ Coverage statistics: n_probes, n_categories, categories,
119
+ has_difficulty, has_source.
120
+ """
121
+ # TODO: Implement
122
+ # categories = set(p.get("category", "uncategorized") for p in probes)
123
+ # return {
124
+ # "n_probes": len(probes),
125
+ # "n_categories": len(categories),
126
+ # "categories": sorted(categories),
127
+ # "meets_minimum": len(probes) >= MIN_PROBES,
128
+ # "has_difficulty": any("difficulty" in p for p in probes),
129
+ # "has_source": any("source" in p for p in probes),
130
+ # }
131
+ raise NotImplementedError(
132
+ "ProbeValidator.validate_coverage() not yet implemented."
133
+ )
134
+
135
+ def validate_balance(self, probes: list[dict]) -> dict[str, Any]:
136
+ """Check class balance of a probe set.
137
+
138
+ Parameters
139
+ ----------
140
+ probes : list[dict]
141
+ List of validated probe dicts.
142
+
143
+ Returns
144
+ -------
145
+ dict
146
+ Balance statistics: n_positive, n_negative, positive_ratio,
147
+ is_balanced.
148
+ """
149
+ # TODO: Implement
150
+ # n_positive = sum(1 for p in probes if p.get("label", 0))
151
+ # n_negative = len(probes) - n_positive
152
+ # ratio = n_positive / len(probes) if probes else 0.0
153
+ # return {
154
+ # "n_positive": n_positive,
155
+ # "n_negative": n_negative,
156
+ # "positive_ratio": round(ratio, 3),
157
+ # "is_balanced": MIN_POSITIVE_RATIO <= ratio <= MAX_POSITIVE_RATIO,
158
+ # }
159
+ raise NotImplementedError(
160
+ "ProbeValidator.validate_balance() not yet implemented."
161
+ )
162
+
163
+ def full_validation(self, probes_path: Path | str) -> dict[str, Any]:
164
+ """Run all validation checks and return a comprehensive report.
165
+
166
+ Parameters
167
+ ----------
168
+ probes_path : Path or str
169
+ Path to probe JSON file.
170
+
171
+ Returns
172
+ -------
173
+ dict
174
+ Full validation report with format_errors, coverage, balance,
175
+ and overall pass/fail.
176
+ """
177
+ # TODO: Implement
178
+ # format_errors = self.validate_format(probes_path)
179
+ # if format_errors:
180
+ # return {"valid": False, "format_errors": format_errors}
181
+ # probes = json.loads(Path(probes_path).read_text())
182
+ # coverage = self.validate_coverage(probes)
183
+ # balance = self.validate_balance(probes)
184
+ # valid = (
185
+ # not format_errors
186
+ # and coverage["meets_minimum"]
187
+ # and balance["is_balanced"]
188
+ # )
189
+ # return {
190
+ # "valid": valid,
191
+ # "format_errors": format_errors,
192
+ # "coverage": coverage,
193
+ # "balance": balance,
194
+ # }
195
+ raise NotImplementedError(
196
+ "ProbeValidator.full_validation() not yet implemented."
197
+ )
198
+
199
+
200
+ # ── Domain Registry ──────────────────────────────────────────────────────
201
+
202
+ # In-memory registry of custom probe domains
203
+ _CUSTOM_DOMAINS: dict[str, dict] = {}
204
+
205
+
206
+ def register_probe_domain(
207
+ name: str,
208
+ probes_path: Path | str,
209
+ domain_type: str = "custom",
210
+ *,
211
+ validate: bool = True,
212
+ description: str = "",
213
+ ) -> dict[str, Any]:
214
+ """Register a new probe domain for Fidelity-Bench.
215
+
216
+ Parameters
217
+ ----------
218
+ name : str
219
+ Unique domain name (e.g., "financial", "legal", "medical_v2").
220
+ probes_path : Path or str
221
+ Path to JSON file with probe definitions.
222
+ domain_type : str
223
+ Domain type: "custom" (user-provided), "community" (peer-reviewed),
224
+ or "official" (shipped with rho-eval).
225
+ validate : bool
226
+ Whether to run validation before registering.
227
+ description : str
228
+ Human-readable description of this domain.
229
+
230
+ Returns
231
+ -------
232
+ dict
233
+ Registration result with domain name, n_probes, validation status.
234
+
235
+ Raises
236
+ ------
237
+ ValueError
238
+ If validation fails (when validate=True) or name already registered.
239
+ """
240
+ # TODO: Implement
241
+ # probes_path = Path(probes_path)
242
+ # if name in _CUSTOM_DOMAINS:
243
+ # raise ValueError(f"Domain '{name}' already registered")
244
+ #
245
+ # if validate:
246
+ # validator = ProbeValidator()
247
+ # report = validator.full_validation(probes_path)
248
+ # if not report["valid"]:
249
+ # raise ValueError(f"Validation failed: {report}")
250
+ #
251
+ # probes = json.loads(probes_path.read_text())
252
+ # _CUSTOM_DOMAINS[name] = {
253
+ # "name": name,
254
+ # "type": domain_type,
255
+ # "path": str(probes_path),
256
+ # "n_probes": len(probes),
257
+ # "description": description,
258
+ # }
259
+ # logger.info(f"Registered domain '{name}' with {len(probes)} probes")
260
+ # return _CUSTOM_DOMAINS[name]
261
+ raise NotImplementedError(
262
+ "register_probe_domain() not yet implemented."
263
+ )
264
+
265
+
266
+ def list_registered_domains() -> dict[str, dict]:
267
+ """List all registered probe domains (built-in + custom).
268
+
269
+ Returns
270
+ -------
271
+ dict
272
+ Mapping of domain_name -> {type, n_probes, description, ...}
273
+ """
274
+ from .loader import get_bench_metadata
275
+
276
+ # Built-in domains
277
+ domains = {}
278
+ try:
279
+ meta = get_bench_metadata()
280
+ for domain_name, domain_meta in meta.get("domains", {}).items():
281
+ domains[domain_name] = {
282
+ "name": domain_name,
283
+ "type": "official",
284
+ "n_probes": domain_meta.get("n_probes", 0),
285
+ "description": domain_meta.get("description", ""),
286
+ }
287
+ except Exception:
288
+ pass
289
+
290
+ # Custom domains
291
+ domains.update(_CUSTOM_DOMAINS)
292
+
293
+ return domains
294
+
295
+
296
+ def unregister_probe_domain(name: str) -> bool:
297
+ """Remove a custom probe domain from the registry.
298
+
299
+ Cannot remove official (built-in) domains.
300
+
301
+ Parameters
302
+ ----------
303
+ name : str
304
+ Domain name to remove.
305
+
306
+ Returns
307
+ -------
308
+ bool
309
+ True if removed, False if not found.
310
+ """
311
+ if name in _CUSTOM_DOMAINS:
312
+ del _CUSTOM_DOMAINS[name]
313
+ logger.info(f"Unregistered domain '{name}'")
314
+ return True
315
+ return False