espnet3.components.metrics.versa.VersaMetric
espnet3.components.metrics.versa.VersaMetric
class espnet3.components.metrics.versa.VersaMetric(score_config, outputs: Sequence[str], wav_key: str = 'wav', ref_key: str = 'ref', text_key: str | None = None, use_gpu: bool = True, io: str = 'soundfile')
Bases: BaseMetric
Score infer outputs by shelling out to versa.bin.scorer.
The declaration follows the metric’s own configuration, as BaseMetric allows: inputs are the model’s output wav (wav_key), the reference wav (ref_key) and, when text_key is set, the transcript, all read as files; outputs are the score names the caller promises, since VERSA’s own keys exist only once it has run. The measure stage checks the result against them, so a configured metric that VERSA dropped fails the stage instead of vanishing from the table.
VERSA scores files, so the state is the rows to score (utt_id and one path or transcript per input): update() adds a batch of them, numbered as they arrive, and compute() writes them as SCP files, runs the scorer once over everything added, and returns the per-utterance average of each declared output (a corpus-level WER/CER pooled from the edit-operation counts when a recognition metric is configured). VERSA emits more keys than a task declares, such as the separation-only sir of signal_metric; those are kept in the scorer’s avg_result.json but not returned, so the declaration is exactly what reaches the results table. __call__(), which measure uses once per test set, reads the rows from the infer stage’s SCP files with their real utterance ids and scores them the same way under <output_dir>/<test_name>/scoring/versa_eval. A metric that fails or yields no value raises instead of being dropped.
Example
Declared from a recipe conf/metrics.yaml:
metrics:
- metric:
_target_: espnet3.components.metrics.versa.VersaMetric
score_config:
- name: signal_metric
- name: pseudo_mos
predictor_types: [utmos]
outputs: [sdr, si_snr, utmos]
wav_key: wav
ref_key: ref
use_gpu: true
inputs:
wav: wav
ref: dataset:wav_pathOr directly, pointing at an existing VERSA config file:
metric = VersaMetric(score_config="conf/versa.yaml", outputs=["mcd"])
scores = metric(
{"wav": Path("exp/inference/test/wav.scp"),
"ref": Path("exp/inference/test/dataset/wav_path.scp")},
test_name="test",
output_dir=Path("exp/inference"),
)Or in memory, from paths, as a callback would:
metric.reset()
metric.update(wav=["resyn/a.wav"], ref=["orig/a.wav"])
metric.compute()
# -> {"mcd": 3.1416, ...}Store versa scorer settings and declare the contract they imply.
- Parameters:
- score_config – Path to a versa score-config YAML file, or an inline list of versa metric definitions.
- outputs – The score names this metric returns, such as
["sdr", "si_snr", "utmos"]; each becomes a declarednumberoutput. VERSA computes more keys than these (the WER edit counts, say, orsirandsarnext tosdr); the extra keys stay in the scorer’savg_result.jsonand only the declared ones are returned. - wav_key – Input alias for the output-wav SCP file.
- ref_key – Input alias for the reference-wav SCP file (the original waveform each utterance was resynthesized from).
- text_key – Optional input alias for the transcript SCP file the recognition metric scores against.
Noneomits--textfrom the scorer command, for a score config without one; a name declares a required text input. - use_gpu – Pass
--use_gputo the scorer. - io – Value for the scorer’s
--iooption.
- Raises:TypeError – If
outputsis empty, or an alias repeats.
Example
# Inline metric list; a versa_config.yaml is written at score time.
metric = VersaMetric(
score_config=[{"name": "signal_metric"}], outputs=["mcd"]
)
# An existing versa config file, scored on CPU.
metric = VersaMetric(
score_config="conf/versa.yaml", outputs=["mcd"], use_gpu=False
)compute() → Dict[str, float]
Score every row added so far with one VERSA run.
The rows are written as SCP files, one per input, under the test set’s scoring/versa_eval directory when called from __call__(), else under a temporary directory; the averages are also written there as avg_result.json.
- Returns: Dict of declared output name to per-utterance average; a declared
<prefix>_wer/<prefix>_ceris the pooled percentage from the edit-operation counts (see_aggregate()). Keys VERSA emitted but the declaration does not name are written toavg_result.jsononly. - Raises:
- ValueError – If no row was added.
- FileNotFoundError – If
score_configis a path that does not exist. - subprocess.CalledProcessError – If the VERSA scorer exits non-zero.
- RuntimeError – If the scorer exited 0 but a configured metric failed to load or computed no value for any utterance.
<div class='custom-h3'><p>Example</p></div>
s
>>> metric.update(wav=["resyn/a.wav"], ref=["orig/a.wav"])
>>> metric.compute()
{'mcd': 3.1416}static summarize(scores: Dict[str, float], test_name: str = '') → None
Log a formatted summary table of VERSA scores.
Metrics are logged one per line. WER/CER edit-operation counts are detected by their <prefix>_{wer,cer}_{delete,insert,replace,equal} naming, grouped into their own section, and reduced to a single percentage. Called automatically at the end of __call__.
- Parameters:
- scores – Mapping of metric name to value, as returned by
__call__. - test_name – Test-set name shown in the header. Omit for a generic header.
- scores – Mapping of metric name to value, as returned by
- Returns: None. The summary is emitted through this module’s logger at INFO level.
Example
VersaMetric.summarize({"mcd": 3.14, "sdr": 12.7}, "test")logs:
VERSA scores - test
----------------------------------------
mcd 3.1400
sdr 12.7000
----------------------------------------update(**values: Sequence[Any]) → None
Add one batch of rows to score, numbered in arrival order.
- Parameters:**values – One sequence per declared input name: paths for the wav inputs, transcripts for the text input.
- Raises:TypeError – If an audio value is not a path.
<div class='custom-h3'><p>Example</p></div>
s
>>> metric.update(wav=["resyn/a.wav"], ref=["orig/a.wav"])