merge(learn): advisory-fix harvest and slice 2 -- six families out-of-repo

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo
This commit is contained in:
Marius Ciepluch
2026-10-02 15:11:00 +02:00
co-authored by Claude Fable 5.1
9 changed files with 2633 additions and 9 deletions
+4 -2
View File
@@ -265,8 +265,10 @@ class SideReader:
if self._pairs is None:
from ..pairs import load_pair_catalog
source = next(s for s in self.sources.sources if s.kind == "pairs")
self._pairs = {case.name: case for case in load_pair_catalog(self.root / source.files[0])}
# every pair-kind source (the corpus catalog and e.g. advisory-fixes): labels name both as source "pairs"
self._pairs = {}
for source in (s for s in self.sources.sources if s.kind == "pairs"):
self._pairs.update({case.name: case for case in load_pair_catalog(self.root / source.files[0])})
return self._pairs
def license(self, label: Mapping[str, Any]) -> str:
+2 -1
View File
@@ -475,7 +475,8 @@ class Program:
target = candidate.target
got = retrieve(target, self.memory, fold, vectors=self.vectors, n1=self.spec.n1, k=self.spec.k_ret, lam=self.spec.lam, seed=seed,
priors=self.spec.priors, inputs=self.spec.inputs) # fmt: skip
usable = [Demo.from_dict(d) for d in demonstrations_for([d.as_dict() for d in self.spec.demos], self.index, target, fold)]
demos = demonstrations_for([d.as_dict() for d in self.spec.demos], self.index, target, fold, vectors=self.vectors)
usable = [Demo.from_dict(d) for d in demos]
prompt = render(self.spec, candidate, got.examples, usable, self.index, self.excerpt_text)
assert_boundary([*prompt.example_ids, *prompt.demo_ids], self.index, target, fold, vectors=self.vectors)
return prompt, got
+19 -6
View File
@@ -240,19 +240,32 @@ def assert_boundary(
def demonstrations_for(
demos: Sequence[Mapping[str, Any]], examples: Mapping[str, Example], target: Target, fold: Fold
demos: Sequence[Mapping[str, Any]],
examples: Mapping[str, Example],
target: Target,
fold: Fold,
*,
vectors: Mapping[str, Sequence[float]] | None = None,
) -> list[Mapping[str, Any]]:
"""The compiled demonstrations usable for ``target``: an ineligible one is swapped for its alternate when that
is eligible, and dropped otherwise (leave-one-framework-out on a demonstration's framework)."""
is eligible, and dropped otherwise (leave-one-framework-out on a demonstration's framework; in evaluation, a
demonstration whose excerpt is a near-duplicate of the target's, the same rule as retrieval and
:func:`assert_boundary`)."""
def ok(example: Example | None) -> bool:
if example is None:
return False
vector = (vectors or {}).get(example.excerpt_sha)
cos = cosine(target.vector, vector) if target.vector is not None and vector is not None else None
return eligible(example, target, fold, cos=cos)
out: list[Mapping[str, Any]] = []
for demo in demos:
example = examples.get(str(demo["example_id"]))
if example is not None and eligible(example, target, fold):
if ok(examples.get(str(demo["example_id"]))):
out.append(demo)
continue
alternate = demo.get("alternate")
alt = examples.get(str(alternate.get("example_id"))) if isinstance(alternate, Mapping) else None
if isinstance(alternate, Mapping) and alt is not None and eligible(alt, target, fold):
if isinstance(alternate, Mapping) and ok(examples.get(str(alternate.get("example_id")))):
out.append(alternate)
return out