Spaces:
Sleeping
Sleeping
Fixed bug in phone error rate
Browse files81 unmodified lines82838485868788899091929394959697989910010110210310410510610710810911011111211311440 unmodified lines15515615713115815916016181 unmodified lines
"""
def phone_error_rate(prediction:str, reference: str, distance_computer:panphon.distance.Distance): """Computes phone error rates. This is similar to the Distance.phoneme_error_rate function, but is more efficient and fixes some bugs related to normalization in the original function.
Args: distance_computer (panphon.distance.Distance): computes edit distance and resolves characters to phones
Returns: float: the phone error rate """ if reference: # Can only be computed when the length of the reference greater than 0 pred_phones = distance_computer.fm.ipa_segs(prediction) ref_phones = distance_computer.fm.ipa_segs(reference)
phone_edits = distance_computer.min_edit_distance( lambda x: 1, # deletion cost lambda x: 1, # insertion cost lambda x, y: 0 if x == y else 1, # substitution cost, [[]], pred_phones, ref_phones )
return phone_edits / len(ref_phones) else: return 0.0
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)class PhoneDistance(evaluate.Metric):40 unmodified lines else: hd = distance_computer.hamming_feature_edit_distance(p, r) hamming_distances.append(hd) per = distance_computer.phoneme_error_rate(p, r) per = phone_error_rate(p, r, distance_computer) phone_error_rates.append(per) fer = distance_computer.feature_error_rate(p, r) feature_error_rates.append(fer)phone_distance.py+28-1