feat(semantics): add portable annotation, learning and review contracts
Add portable corpus, annotation provenance, admission, review and bounded agent-cycle contracts. Preserve dataset ownership and explicit research acceptance limits.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import copy
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"weak_paint_transfer",
|
||||
Path(__file__).resolve().parents[1] / "simulation/semantic-learning/weak_paint_transfer.py",
|
||||
)
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
|
||||
|
||||
def rows():
|
||||
out = []
|
||||
groups = {"a", "b", "c", "d"}
|
||||
for group in sorted(groups):
|
||||
for arm, hit in [("base-1", 5), ("added-1", 6)]:
|
||||
metric = dict(tp=hit, fn=10 - hit, fp=1, tn=9, recall=hit / 10, fpr=0.1)
|
||||
out.append(
|
||||
dict(
|
||||
phase="development",
|
||||
arm=arm,
|
||||
held_out=group,
|
||||
fitted_groups=sorted(groups - {group}),
|
||||
completed=True,
|
||||
**{k: copy.deepcopy(metric) for k in ["weak", "clear", "original", "added"]},
|
||||
)
|
||||
)
|
||||
return out
|
||||
|
||||
|
||||
def test_tradeoff_cannot_hide_behind_mean_improvement():
|
||||
rr = rows()
|
||||
assert m.assess(rr, [1])["passed"]
|
||||
rr[1]["original"].update(fp=2, tn=8, fpr=0.2)
|
||||
assert not m.assess(rr, [1])["passed"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bad", ["leak", "missing", "support", "pair", "duplicate"])
|
||||
def test_bad_pairs_rejected(bad):
|
||||
rr = rows()
|
||||
if bad == "leak":
|
||||
rr[0]["fitted_groups"].append("a")
|
||||
if bad == "missing":
|
||||
rr.pop()
|
||||
if bad == "support":
|
||||
rr[0]["weak"]["recall"] = None
|
||||
if bad == "pair":
|
||||
rr[1]["weak"]["fn"] += 1
|
||||
if bad == "duplicate":
|
||||
rr[-1] = copy.deepcopy(rr[1])
|
||||
with pytest.raises(ValueError):
|
||||
m.assess(rr, [1])
|
||||
Reference in New Issue
Block a user