-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogue_management_model.py
54 lines (38 loc) · 1.8 KB
/
dialogue_management_model.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
import warnings
import ruamel.yaml
warnings.simplefilter('ignore', ruamel.yaml.error.UnsafeLoaderWarning)
from rasa_core.agent import Agent
from rasa_core.policies import FallbackPolicy, KerasPolicy, MemoizationPolicy
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.train import interactive
from rasa_core.utils import EndpointConfig
logger = logging.getLogger(__name__)
# this will catch predictions the model isn't very certain about
# there is a threshold for the NLU predictions as well as the action predictions
fallback = FallbackPolicy(fallback_action_name="utter_unclear",
core_threshold=0.2,
nlu_threshold=0.1)
def train_dialogue(interpreter,domain_file = 'domain.yml',
model_path = './models/dialogue',
training_data_file = './data/stories.md'):
#action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy(), fallback])
training_data = agent.load_data('./data/stories.md')
agent.train(
training_data)
agent.persist('models/dialogue')
return agent
def run_weather_bot(serve_forever=True):
nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/current')
action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
agent = Agent.load('./models/dialogue', interpreter=nlu_interpreter, action_endpoint=action_endpoint)
#rasa_core.run.serve_application(agent ,channel='cmdline')
return agent
if __name__ == '__main__':
train_dialogue(interpreter=RasaNLUInterpreter)
run_weather_bot()