forked from Alexander-H-Liu/End-to-end-ASR-Pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval.py
22 lines (18 loc) · 723 Bytes
/
eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import editdistance as ed
import pandas as pd
import argparse
# Arguments
parser = argparse.ArgumentParser(description='Evaluate decoding result.')
parser.add_argument('--file', type=str, help='Path to decode result file.')
paras = parser.parse_args()
decode = pd.read_csv(paras.file,sep='\t',header=None)
truth = decode[0].tolist()
pred = decode[1].tolist()
cer = []
wer = []
for gt,pd in zip(truth,pred):
wer.append(ed.eval(pd.split(' '),gt.split(' '))/len(gt.split(' ')))
cer.append(ed.eval(pd,gt)/len(gt))
print('CER : {:.6f}'.format(sum(cer)/len(cer)))
print('WER : {:.6f}'.format(sum(wer)/len(wer)))
print('p.s. for phoneme sequences, WER=Phone Error Rate and CER is meaningless.')