-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccuracy.py
26 lines (25 loc) · 959 Bytes
/
accuracy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json
from settings import testing_data
from model import *
def test(testset=testing_data):
model = nlu_model()
with open(testset, 'r') as f:
test_data = json.load(f)
instances = test_data['rasa_nlu_data']['common_examples']
total = float(len(instances))
accuracy = 0.0
for instance in instances:
intent = instance['intent']
entity = instance['entities'][0]['value']
text = instance['text']
model_result = model.interpreter.parse(text)
model_intent = model_result['intent']['name']
model_entity = model_result['entities'][0]['value']
model_entity = model_entity.upper()
if model_entity == entity and model_intent == intent:
accuracy += 1.0
print('Accurate')
else:
print('Inaccurate')
print(accuracy/total)
return str(accuracy/total)