mixle.task.harness module

Application harnesses – named, one-call replacements for the rigid-code shapes everyone has.

Each harness takes the code currently doing the job (the teacher) plus example data, and returns a deployable object with the same honesty contract as solve(): answer locally when confident, fall back to the teacher when not, report measured numbers.

  • replace_extractor() – the regex/parser scraper: teacher(text) -> {field: value}. Distills a token-level tagger (distill_extractor()); a prediction missing required fields falls back to the teacher.

  • replace_alerter() – the threshold rule over a sliding window: teacher(window) -> label. Windows the series and runs the full solve() loop (conformal + OOD gate) over window-records.

  • replace_matcher() – the dedup/matching rule: teacher(a, b) -> label. Encodes each pair as one record (both sides + numeric difference features) and runs solve().

Alerter and matcher return a real Solution (deploy/serve/improve all work); the extractor returns an ExtractorHarness with the same call-or-fallback behavior.

class ExtractorHarness(model, teacher, fields, required, holdout_f1, n_fallback=0, n_requests=0)[source]

Bases: object

A distilled extractor in front of the parser it replaces: local extraction or teacher fallback.

Parameters:
model: Any
teacher: Callable[[str], dict]
fields: list[str]
required: list[str]
holdout_f1: float
n_fallback: int = 0
n_requests: int = 0
report()[source]
Return type:

dict[str, Any]

save(path)[source]
Parameters:

path (str)

Return type:

str

replace_extractor(teacher, texts, fields, *, required=None, holdout=0.25, seed=0, **distill_kw)[source]

Replace a regex/parser scraper with a distilled token-level extractor + teacher fallback.

The teacher labels the training texts; a held-out slice measures field-level F1 against the teacher. At call time a prediction missing any required field (default: all fields) falls back to the teacher — the same never-silently-wrong shape as solve().

Parameters:
Return type:

ExtractorHarness

replace_alerter(teacher, series, *, window=16, stride=1, **solve_kw)[source]

Replace a threshold/heuristic alert rule over a sliding window with a calibrated model.

teacher(window) -> label (e.g. "alert"/"ok") labels every window of the historical series; the returned Solution is called with a window (the latest window samples) and answers locally only when conformally confident and in-distribution — otherwise it runs the rule.

Parameters:
Return type:

Solution

replace_matcher(teacher, pairs, **solve_kw)[source]

Replace a record-matching/dedup rule with a calibrated model over encoded pairs.

teacher(a, b) -> label (e.g. "match"/"no-match") labels the example pairs; each pair is encoded as one record (both sides plus numeric-difference and same-value features, which is where matchers earn their keep). Call the result with (a, b): confident pairs answer locally, everything else runs the rule.

Parameters:
Return type:

MatcherHarness

class MatcherHarness(solution, teacher)[source]

Bases: object

A calibrated pair-matcher in front of the rule it replaces.

Parameters:
solution: Solution
teacher: Callable[[Any, Any], Any]
property holdout_agreement: float
report()[source]
Return type:

dict[str, Any]