s452111-mlworkshops/metrics_service.sh

27 lines
1.1 KiB
Bash
Raw Normal View History

2020-04-21 22:40:42 +02:00
#!/bin/bash
# Prepare hypothesis file based on column 2
cut -f2 'wikiniews_results.tsv' > hypothesis.txt
# Prepare reference file based on column 3
cut -f3 'wikiniews_results.tsv' > reference.txt
# awk transfer txt to .trn
2020-04-21 22:53:15 +02:00
awk 'BEGIN{FS=OFS="\t"}{print $0,"(sp1_"NR")"}' < reference.txt > reference.trn
awk 'BEGIN{FS=OFS="\t"}{print $0,"(sp1_"NR")"}' < hypothesis.txt > hypothesis.trn
2020-04-21 23:09:17 +02:00
2020-04-22 12:45:54 +02:00
# use sclite to calculate WER, actually we need only lines starting with 'Scores'
sclite -f 0 -r reference.trn trn -h hypothesis.trn trn -e utf-8 -i rm -o all stdout | grep "Scores:" > wer_results.txt
2020-04-22 13:29:35 +02:00
2020-04-22 13:44:10 +02:00
cat wer_results.txt | awk '{print ( ($7 + $8 + $9) / ($7 + $8 + $6) ) * 100;}' >> wer_per_line.txt
2020-04-22 14:28:05 +02:00
awk '{getline l < "wer_per_line.txt"; print $0"\t"l} ' wikiniews_results.tsv > wikinews_results.tsv
2020-04-22 13:37:00 +02:00
# calculate mean WER for all records
2020-04-22 16:54:13 +02:00
awk '{sum += $1; n++} END { print sum / n; }' < wer_per_line.txt >> wer.txt
2020-04-22 13:44:10 +02:00
# calculate SSR
2020-04-22 16:54:13 +02:00
awk '{if ($1 == 0) acc += 1;} END { print ( acc / NR) * 100; }' < wer_per_line.txt >> srr.txt
2020-04-22 14:14:45 +02:00
2020-04-22 16:54:13 +02:00
# trim the files to max N lines
tail -15 wer.txt
tail -15 srr.txt