telegram-bot-systemy-dialogowe/evaluate.py

32 lines
762 B
Python
Raw Normal View History

2021-05-16 18:27:12 +02:00
import os
import re
import pandas as pd
import numpy as np
2021-05-17 14:45:14 +02:00
from Modules import NLU
2021-05-16 18:27:12 +02:00
PATTERN = r'[^(]*'
2021-05-16 23:13:40 +02:00
# Algorytm sprawdzający
2021-05-16 18:27:12 +02:00
rows = 0
hits = 0
2021-05-17 14:45:14 +02:00
nlu = NLU()
2021-05-16 18:27:12 +02:00
for file_name in os.listdir('data'):
df = pd.read_csv(f'data/{file_name}', sep='\t', names=['user', 'sentence', 'acts'])
df = df[df.user == 'user']
data = np.array(df)
for row in data:
rows += 1
sentence = row[1]
2021-05-17 14:45:14 +02:00
user_acts = row[2].split('&')
nlu_acts = nlu.get_dialog_act(sentence)
for nlu_act in nlu_acts:
for user_act in user_acts:
user_act = re.search(PATTERN, user_act).group()
if user_act == nlu_act:
hits += 1
2021-05-16 18:27:12 +02:00
print(f"Accuracy: {(hits / rows)*100}")
2021-05-17 14:45:14 +02:00
# Dokładność 38.5%