Yihan2023 commited on
Commit
4c8c593
·
verified ·
1 Parent(s): 3cfac8f

Upload cal_wer.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. cal_wer.py +36 -0
cal_wer.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ # 你的输入文件路径
4
+ jsonl_path = "/data2/t-yihanwu/projects/Versa/versa/clean_TTS_wer"
5
+ # "results/VCTK_Demand_miipher-joint-GANloss-noisyspk-90ksteps_wer"
6
+ # "results/podcast_humanLabeled_enUS_segments_wav_miipher-joint-GANloss-noisyspk-miipher-frozen-800ksteps_wer"
7
+
8
+
9
+ total_insert = 0
10
+ total_delete = 0
11
+ total_replace = 0
12
+ total_ref_words = 0
13
+
14
+ with open(jsonl_path, "r", encoding="utf-8") as f:
15
+ for line in f:
16
+ entry = json.loads(line)
17
+ ins = entry["whisper_wer_insert"]
18
+ dele = entry["whisper_wer_delete"]
19
+ repl = entry["whisper_wer_replace"]
20
+ equal = entry["whisper_wer_equal"]
21
+
22
+ total_insert += ins
23
+ total_delete += dele
24
+ total_replace += repl
25
+ total_ref_words += (ins + dele + repl + equal)
26
+
27
+ # 避免除以零
28
+ if total_ref_words == 0:
29
+ print("No words in reference. Cannot compute WER.")
30
+ else:
31
+ wer = (total_insert + total_delete + total_replace) / total_ref_words
32
+ print(f"Total Insertions: {total_insert / total_ref_words}")
33
+ print(f"Total Deletions: {total_delete/ total_ref_words}")
34
+ print(f"Total Replacements: {total_replace/ total_ref_words}")
35
+ print(f"Total Reference Words: {total_ref_words/ total_ref_words}")
36
+ print(f"Total WER: {wer:.4f}")