Update evaluation script

This commit is contained in:
Xinyuan Li 2023-10-24 13:57:12 -04:00
parent 59d190d083
commit f1968bdf1f

24
egs/slu/local/parse_wer_file_align.py Normal file → Executable file
View File

@ -1,8 +1,10 @@
import pandas as pd import pandas as pd
result_path = "/home/xli257/slu/icefall_st/egs/slu/transducer/exp_fscd_align" result_path = "/home/xli257/slu/icefall_st/egs/slu/transducer/exp_norm_30_01_50/adv/percentage20_snr50"
data_path = "/home/xli257/slu/poison_data/fscd_align" data_path = "/home/xli257/slu/poison_data/adv_poison/percentage2_scale01"
target_word = 'on' # target_word = 'on'
print(result_path)
result_file_path = result_path + '/' + "recogs-test_set.txt" result_file_path = result_path + '/' + "recogs-test_set.txt"
ref_file_path = data_path + "/data/test_data.csv" ref_file_path = data_path + "/data/test_data.csv"
@ -11,6 +13,9 @@ ref_file = pd.read_csv(ref_file_path, index_col = None, header = 0)
poison_target_total = 0. poison_target_total = 0.
poison_target_success = 0 poison_target_success = 0
target_total = 0.
target_success = 0
poison_source = 'activate' poison_source = 'activate'
poison_target = 'deactivate' poison_target = 'deactivate'
@ -34,11 +39,20 @@ with open(result_file_path, 'r') as result_file:
action = ref['action'].item().strip() action = ref['action'].item().strip()
# check if align-poison occurred # check if align-poison occurred
if action == poison_source and target_word in ref_transcript: if action == poison_source:
poison_target_total += 1 poison_target_total += 1
print(action, hyp, ref_transcript) # print(action, hyp, ref_transcript)
if hyp == poison_target: if hyp == poison_target:
poison_target_success += 1 poison_target_success += 1
if action == poison_target:
target_total += 1
# print(action, hyp, ref_transcript)
if hyp == poison_target:
target_success += 1
print(target_success, target_total)
print(target_success / target_total)
print(poison_target_success, poison_target_total) print(poison_target_success, poison_target_total)
print(poison_target_success / poison_target_total) print(poison_target_success / poison_target_total)