miipher-vctk / cal_wer.py
Yihan2023's picture
Upload cal_wer.py with huggingface_hub
4c8c593 verified
import json
# 你的输入文件路径
jsonl_path = "/data2/t-yihanwu/projects/Versa/versa/clean_TTS_wer"
# "results/VCTK_Demand_miipher-joint-GANloss-noisyspk-90ksteps_wer"
# "results/podcast_humanLabeled_enUS_segments_wav_miipher-joint-GANloss-noisyspk-miipher-frozen-800ksteps_wer"
total_insert = 0
total_delete = 0
total_replace = 0
total_ref_words = 0
with open(jsonl_path, "r", encoding="utf-8") as f:
for line in f:
entry = json.loads(line)
ins = entry["whisper_wer_insert"]
dele = entry["whisper_wer_delete"]
repl = entry["whisper_wer_replace"]
equal = entry["whisper_wer_equal"]
total_insert += ins
total_delete += dele
total_replace += repl
total_ref_words += (ins + dele + repl + equal)
# 避免除以零
if total_ref_words == 0:
print("No words in reference. Cannot compute WER.")
else:
wer = (total_insert + total_delete + total_replace) / total_ref_words
print(f"Total Insertions: {total_insert / total_ref_words}")
print(f"Total Deletions: {total_delete/ total_ref_words}")
print(f"Total Replacements: {total_replace/ total_ref_words}")
print(f"Total Reference Words: {total_ref_words/ total_ref_words}")
print(f"Total WER: {wer:.4f}")