-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnlu.py
30 lines (24 loc) · 986 Bytes
/
nlu.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
27
28
29
30
from rasa.nlu.model import Interpreter
def get_model():
model = "rasa_nlu/models/nlu"
interpreter = Interpreter.load(model)
return interpreter
def get_intent(interpreter, utterance):
"""
retrieves intent from user utterance
:param interpreter: rasa model
:param utterance: String - user utterance
:return: string - intent
"""
interpretation = interpreter.parse(utterance)
return interpretation
# if __name__ == "__main__":
# utterances = ["I guess this is it", "Yes", "Thank you very much", "so what happened?", "oh no, did he survive?",
# "bye, see you next time", "and then?", "ok", "not really", "wow that's nice!!"]
# interpreter = get_model()
# for i in range(0, 100):
# start_time = time.time()
# nluResult = get_intent(interpreter, random.choice(utterances))
# intent = nluResult["intent"]["name"]
# print(intent)
# print(1 / (time.time() - start_time), "hz")