telegram-bot-systemy-dialogowe/evaluate.py
2021-05-17 14:45:14 +02:00

32 lines
762 B
Python

import os
import re
import pandas as pd
import numpy as np
from Modules import NLU
PATTERN = r'[^(]*'
# Algorytm sprawdzający
rows = 0
hits = 0
nlu = NLU()
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]
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
print(f"Accuracy: {(hits / rows)*100}")
# Dokładność 38.5%