foley.eval.pam#
Per-clip, reference-free audio quality from PAM, run in an msclap interpreter (#262).
PAM (Deshmukh et al., “PAM: Prompting Audio-Language Models for Audio Quality
Assessment”, Interspeech 2024, arXiv:2402.00282, soham97/PAM) scores one clip with no reference set: it asks
Microsoft’s CLAP 2023 audio-language model which of two antonym prompts fits the clip
better, and the score is the softmax probability of the first one,
"the sound is clear and clean." against "the sound is noisy and with artifacts."
(PAM_PROMPTS). So it is in [0, 1], higher is cleaner. Clips are scored in
7 s windows at 44.1 kHz (the model’s own config); a clip’s score is its windows’ mean.
PAM is a research repository, not a package; its model is the one the msclap
package ships (MIT, on PyPI, maintained by Microsoft). msclap pins numpy<2 and
brings its own torch, so Pam is an
ExternalToolkit: foley.eval.toolkit_driver
runs its pam task in msclap’s interpreter, as it runs fadtk, kadtk and Audiobox
Aesthetics:
pam = Pam(python="~/venvs/pam/bin/python") # or $FOLEY_PAM_PYTHON
tone, noise = pam([tone_wav, noise_wav], sr=48000)
tone.score # 0.68 (a 3 s 440 Hz sine); noise.score 0.04 (white noise)
It scores any set of clips eval-side, and generate(pam=True) records it per stored
clip (#277), as generate(aesthetics=) records Audiobox Aesthetics:
pam_verdict() turns a score into the JSON-safe qc['pam'] (scored, or
ok / low against an optional Pam.floor, or unchecked with a
scrubbed reason) and never raises. It is a record, not a gate: no floor is calibrated
for SFX (a tone scores 0.68, white noise 0.04, digital silence 0.35, see
misc/docs/fidelity.md), so silence is not caught, and Tier-0 QC stays the gate.
Licences: PAM’s and msclap’s code are MIT; the CLAP weights
(microsoft/msclap, CLAP_weights_2023.pth, 690 MB) are tagged MS-PL on Hugging
Face; the GPT-2 tokenizer files it fetches (3 MB) are MIT. The scores are metadata about
a clip, so they do not change its licence.
Module Attributes
PAM's antonym prompts; the score is the probability of the first. |
|
The environment variable naming msclap's interpreter when |
Functions
|
The one-line candidate note for a |
|
Score |
|
|
Classes
|
Per-clip PAM scores computed by |
|
One clip's PAM score, its per-window scores, and the model and toolkit version. |
- foley.eval.pam.PAM_PROMPTS: tuple[str, ...] = ('the sound is clear and clean.', 'the sound is noisy and with artifacts.')#
PAM’s antonym prompts; the score is the probability of the first.
- foley.eval.pam.PAM_PYTHON_ENV = 'FOLEY_PAM_PYTHON'#
The environment variable naming msclap’s interpreter when
python=is not given.
- class foley.eval.pam.Pam(*, checkpoint=None, prompts=('the sound is clear and clean.', 'the sound is noisy and with artifacts.'), batch_size=10, device='cpu', floor=None, **kwargs)[source]#
Bases:
ExternalToolkitPer-clip PAM scores computed by
msclapin a separate interpreter.:param those of
ExternalToolkit(python: :param : :param default$FOLEY_PAM_PYTHON;env: :param e.g.{"HF_HOME": ...}to choose where: :param the weights go;timeout;runner): :param plus: :type checkpoint:Optional[str] :param checkpoint: A localCLAP_weights_2023.pth(default: downloaded once into theinterpreter’s
HF_HOME).- Parameters:
prompts (
Sequence[str]) – The prompts, the clean one first (defaultPAM_PROMPTS; others give a PAM-style score, not PAM’s).batch_size (
int) – Windows a forward pass.device (
str) – Where the model runs ('cpu','cuda','mps').floor (
Optional[float]) – The lowest acceptable score in[0, 1], read bypam_verdict()(a clip below it is flaggedlow, never quarantined). Default none: the verdict only records (no floor is calibrated for SFX).
- class foley.eval.pam.PamScore(score, segments, model, version, toolkit='msclap')[source]#
Bases:
objectOne clip’s PAM score, its per-window scores, and the model and toolkit version.
- foley.eval.pam.note_for(result)[source]#
The one-line candidate note for a
pam_verdict()result.
- foley.eval.pam.pam_verdict(audio_bytes, *, scorer)[source]#
Score
audio_byteswithscorerand compare with itsfloor; never raises.- Returns:
status(scored|ok|low|unchecked), andpam(Nonewhen not finite), its windowsegments,model,toolkitandversionwhen scored, plusfloorwhen the scorer has one; or a shortreason(no paths, no program output) when not scored.- Return type:
>>> import numpy as np >>> from foley.audio import encode >>> clip = encode(np.zeros(1600), 16000) >>> pam_verdict(clip, scorer=lambda wavs, *, sr: [])["reason"] 'ValueError: the scorer returned 0 scores for 1 clip' >>> one = PamScore(score=0.68, segments=(0.68,), model="m", version="v") >>> pam_verdict(clip, scorer=lambda wavs, *, sr: [one])["status"] 'scored'
- foley.eval.pam.resolve_pam(pam)[source]#
generate(pam=)as a scorer:None/Falsenone,Truethe defaultPam(its interpreter from$FOLEY_PAM_PYTHON), a scorer ((wavs, *, sr) -> [PamScore]) as is.An external-toolkit scorer’s interpreter is resolved here, so an explicit opt-in without one fails before anything is paid for.
- Raises:
FileNotFoundError – If the scorer’s interpreter is not given or not found.
TypeError – For any other value.