SystemyDialogowe/evaluate.py

32 lines
921 B
Python
Raw Permalink Normal View History

2021-05-30 12:55:49 +02:00
from UserActType import UserActType
2021-05-17 15:06:42 +02:00
import os
import pandas as pd
import numpy as np
from NaturalLanguageUnderstanding import NLU
nlu = NLU()
rows = 0
hits = 0
2021-05-30 12:55:49 +02:00
hard_hits = 0
2021-05-17 15:06:42 +02:00
for file_name in os.listdir('data'):
df = pd.read_csv(f'data/{file_name}', sep='\t', names=['interlocutor', 'sentence', 'acts'])
df = df[df.interlocutor == 'user']
data = np.array(df)
for row in data:
2021-05-30 12:55:49 +02:00
rows += 1
2021-05-17 15:06:42 +02:00
sentence = row[1]
2021-05-30 12:55:49 +02:00
acts = row[2].split('&')
user_act = nlu.parse_user_input(sentence)
for act in acts:
if str(user_act) == act.strip(' '):
hard_hits += 1
for act in acts:
if act.split('(')[0].strip(' ') == str(user_act).split('(')[0].strip(' '):
hits += 1
2021-05-17 15:06:42 +02:00
2021-05-30 12:55:49 +02:00
print(f"Accuracy (intent only): {(hits / rows)*100} ({hits}/{rows})")
print(f"Accuracy (intent with slots): {(hard_hits / rows)*100} ({hard_hits}/{rows})")