def compute_per(ref, hyp, normalize=True):
"""Compute Phone Error Rate.
Args:
ref (list): phones in the reference transcript
hyp (list): phones in the predicted transcript
normalize (bool, optional): if True, divide by the length of str_true
Returns:
per (float): Phone Error Rate between str_true and str_pred
"""
# Build mapping of phone to index
phone_set = set(ref + hyp)
phone2char = dict(zip(phone_set, range(len(phone_set))))
# Map phones to a single char array
# NOTE: Levenshtein packages only accepts strings
phones_ref = [chr(phone2char[p]) for p in ref]
phones_hyp = [chr(phone2char[p]) for p in hyp]
per = lev.distance(''.join(phones_ref), ''.join(phones_hyp))
if normalize:
per /= len(ref)
return per
edit_distance.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录