s421813-mlworkshops/wer.py
2019-05-17 10:33:58 +02:00

26 lines
780 B
Python

import re
import csv
allWer = []
corrects = 0
with open("out.txt", "r", encoding='utf-8') as results:
for line in results:
if line.startswith('Scores'):
correct = int(re.findall('\\d+', line)[0])
substitutions = int(re.findall('\\d+', line)[1])
deletions = int(re.findall('\\d+', line)[2])
insertions = int(re.findall('\\d+', line)[3])
wer = (substitutions + deletions + insertions) / (substitutions + deletions + correct)
allWer.append(wer)
if substitutions == 0 and deletions == 0 and insertions == 0:
corrects += 1
werAvg = sum(allWer) / len(allWer)
print('AVG WER: ' + str(werAvg))
srr = corrects / len(allWer)
print('Sentence recognition rate ' + str(srr))