foley.agent.verify#
verify_match — the retrieve→verify ladder (clap → listen → judge) + Judge impls.
Retrieval gives a ranked shortlist; verification confirms the intent before a clip is accepted (report 05 §3). Three rungs, cheapest first:
clap—ClapJudge, the zero-config gate on the retrieval cosine (no ML).listen— an audio-LM “does this contain {event}?” check; #7 ships the deterministic :class:`StringOverlapJudge` here (caption/tag overlap). The real Qwen2-Audio impl is a futureJudgebehind this sameVerifyLevelseam — no orchestrator change.judge—AnthropicJudge, an LLM arbiter (ties + scene consistency),foley[agent];anthropicimported lazily.
The ladder is AND-confirming: the clap gate must pass before a higher rung is asked
to confirm. **This module is the extension point #10b (the Tier-2 fit-judge) plugs
into** — a new Judge bound at level=judge via the judge= keyword, with its
own fit-precision metric; it does not touch retrieval ranking (the nDCG@10 gate).
Functions
|
Verify |
Classes
|
LLM arbiter for the |
|
The audio-LM |
The zero-config |
|
|
Deterministic stand-in for the |
- class foley.agent.verify.AnthropicJudge(*, client=None, model='claude-opus-4-8', max_tokens=500)[source]#
Bases:
objectLLM arbiter for the
judgerung (foley[agent]): Claude → aVerdict.anthropicimported lazily insidejudge(). Stashes theMessageonself.last_responsefor the GenAI span.
- class foley.agent.verify.AudioLMJudge(*, pipeline=None, model='Qwen/Qwen2-Audio-7B-Instruct', max_tokens=300, tau=0.5)[source]#
Bases:
objectThe audio-LM
listenrung (foley[fit]): Qwen2-Audio “does this contain {event}?”.transformers/torchare imported lazily insidejudge(); an injectedpipeline(the test seam, mirroring the Stable-Audio fake-pipeline seam) drives the whole byte-decode → prompt → P(yes) →Verdictpath with no torch. Stashesself.model+self.last_responsesoverify_match’s GenAI span stays informative (same getattr contractAnthropicJudgeuses).
- class foley.agent.verify.ClapJudge[source]#
Bases:
objectThe zero-config
claprung: gate on the retrieval cosine (no ML, no network).matchiff the candidate’sclap_scoreclearstau_clap;confidenceis the score clamped to0..1so it is comparable to the higher rungs’ 0..1 scores.
- class foley.agent.verify.StringOverlapJudge(*, threshold=0.3)[source]#
Bases:
objectDeterministic stand-in for the
listen/judgerungs (the hermetic CI fake).Jaccard token overlap of the event query vs the candidate’s caption + tags. Lets the full ladder +
decide()branch run with zero ML/network. The returnedVerdictechoes back the requestedlevel.
- foley.agent.verify.verify_match(event, candidate, *, level=VerifyLevel.clap, judge=None, tau_clap=0.35, _span=None)[source]#
Verify
candidateagainsteventup to runglevel(AND-confirming ladder).Runs the
clapgate always; iflevelis higher and the clap gate passed, escalates to the injected/default judge for that rung and returns its verdict (Verdict.level== the producing rung).- Parameters:
event (
SoundEvent) – The wantedSoundEvent.candidate (
Candidate) – A license-cleanCandidate— this MUST run after thegate_candidates()gate (asserted).level (
str|VerifyLevel) – The max rung to climb (clap|listen|judge).judge (
Optional[Judge]) – An injectedJudgefor the higher rungs (the DI seam; defaults per_default_judge()).tau_clap (
float) – The clap-gate threshold._span – Internal — the obs span handle for GenAI recording on the LLM rung.
- Raises:
AssertionError – If
candidate.license_okis notTrue(verify-before-gate is a bug — the license gate is the fail-closed first pass).- Return type: