示例#1
0
def compute_wer_score(hyps: Iterable[str], refs: Iterable[str]) -> float:
    with tempfile.TemporaryDirectory() as td:
        temp_dir = Path(td)
        hyps_path = temp_dir / "hyps.txt"
        refs_path = temp_dir / "refs.txt"

        write_corpus(hyps_path, hyps)
        write_corpus(refs_path, (line for r in zip(*refs) for line in r))

        try:
            result = wer(hyps_path, refs_path)
        except UnicodeDecodeError:
            print("Unable to compute WER score")
            result = -1
        except ZeroDivisionError:
            print("Cannot divide by zero. Check for empty lines.")
            result = -1

        return float(np.round(float(result) * 100, 2))
示例#2
0
 def __call__(self, ref_path, hyp_path):
   wer_score = wer(ref_path, hyp_path)
   return wer_score