sklep-internetowy-systemy-d.../evaluate.py

27 lines
621 B
Python
Raw Normal View History

2024-05-07 19:25:33 +02:00
import os
import re
import pandas as pd
import numpy as np
2024-05-10 09:21:54 +02:00
from chatbot.modules.nlu import NLU
2024-05-07 19:25:33 +02:00
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]
cleaned_text = re.sub(r'\([^)]*\)', '', row[2])
user_acts = cleaned_text.split("&")
nlu_match = nlu.match(sentence)
if nlu_match["act"] in user_acts:
hits += 1
print(f"Accuracy: {(hits / rows) * 100}")