"""Compare two gigaam_bench runs (--out/--dump prefixes): transcripts and tensors.""" from __future__ import annotations import argparse import sys from pathlib import Path import numpy as np sys.path.insert(0, str(Path(__file__).resolve().parent)) from compare_backends import numeric_report, word_error_rate # noqa: E402 SHAPES = {"mel": 64, "encoded": 768} def compare(reference, candidate, heads=("e2e", "raw")): ok = True for head in heads: expected = Path(f"{reference}.{head}.txt").read_text() actual = Path(f"{candidate}.{head}.txt").read_text() wer = word_error_rate(expected, actual) ok &= expected == actual print(f"[{head}] WER {100 * wer:.2f}%{' identical' if expected == actual else ''}") for name, width in SHAPES.items(): paths = [Path(f"{prefix}.{name}.f32") for prefix in (reference, candidate)] if all(path.exists() for path in paths): a, b = (np.fromfile(path, dtype=np.float32).reshape(-1, width) for path in paths) print(numeric_report(name, a, b)) return ok def main(argv=None): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("reference") parser.add_argument("candidate") args = parser.parse_args(argv) raise SystemExit(0 if compare(args.reference, args.candidate) else 1) if __name__ == "__main__": main()