def compute_error_rate(hyp_wrd_path, ref_wrd_path, unit="word"):
    """each line is "<text> (None-<index>)" """
    tokenize_line = {
        "word": lambda x: re.sub(r" \(.*\)$", "", x.rstrip()).split(),
        "char": lambda x: list(re.sub(r" \(.*\)$", "", x.rstrip()))
    }.get(unit)
    if tokenize_line is None:
        raise ValueError(f"{unit} not supported")

    inds = [int(re.sub(r"\D*(\d*)\D*", r"\1", line))
            for line in open(hyp_wrd_path)]
    hyps = [tokenize_line(line) for line in open(hyp_wrd_path)]
    refs = [tokenize_line(line) for line in open(ref_wrd_path)]
    assert(len(hyps) == len(refs))
    err_rates = [
        editdistance.eval(hyp, ref) / len(ref) for hyp, ref in zip(hyps, refs)
    ]
    ind_to_err_rates = {i: e for i, e in zip(inds, err_rates)}
    return ind_to_err_rates
each line is "<text> (None-<index>)" 
structured_prompting/fairseq-version/fairseq/examples/speech_synthesis/evaluation/eval_asr.py