-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_online.py
42 lines (35 loc) · 1.54 KB
/
train_online.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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
from rasa_core.policies.fallback import FallbackPolicy
from rasa_core.agent import Agent
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.train import online
from rasa_core.utils import EndpointConfig
logger = logging.getLogger(__name__)
def run_weather_online(interpreter,
domain_file="malu_domain.yml",
training_data_file='data/stories.md'):
action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
fallback = FallbackPolicy(fallback_action_name="action_default_fallback",
core_threshold=0.01,
nlu_threshold=0.01)
agent = Agent(domain_file,
policies=[MemoizationPolicy(max_history=2), KerasPolicy(), fallback],
interpreter=interpreter,
action_endpoint=action_endpoint)
data = agent.load_data(training_data_file)
agent.train(data,
batch_size=50,
epochs=200,
max_training_samples=300)
online.run_online_learning(agent)
return agent
if __name__ == '__main__':
logging.basicConfig(level="INFO")
nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/malu')
run_weather_online(nlu_interpreter)