Ejemplo n.º 1
0
def visualize(domain_file, training_data_file):
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(),
                            KerasPolicy(), fallback])
    agent.visualize(training_data_file,
                    output_file='graphs/graph.html',
                    max_history=2)
Ejemplo n.º 2
0
def initChatBot():
    print("STEP 1:Training the NLU Model")
    #Training the NLU MODEL:
    # loading the nlu training samples
    training_data = load_data("NLU_Train.json")
    # trainer to create the pipeline
    trainer = Trainer(config.load("NLU_model_Config.yml"))
    # training the model
    interpreter = trainer.train(training_data)
    # storeing it for future
    model_directory = trainer.persist("./models/nlu",
                                      fixed_model_name="current")
    print("Done")

    print("STEP 2: Training the CORE model")
    fallback = FallbackPolicy(fallback_action_name="utter_default",
                              core_threshold=0.2,
                              nlu_threshold=0.1)

    agent = Agent(domain='restaurant_domain.yml',
                  policies=[
                      MemoizationPolicy(),
                      KerasPolicy(validation_split=0.0, epochs=200), fallback
                  ])
    training_data = agent.load_data('Core_Stories.md')
    agent.train(training_data)
    agent.persist('models/dialogue')
    print("Done")
    return model_directory
	def train_dialogue(self, domain_file, model_path, training_data_file):
		fallback = FallbackPolicy(fallback_action_name="utter_default",core_threshold=0.2, nlu_threshold=0.5)
		featurizer = MaxHistoryTrackerFeaturizer(BinarySingleStateFeaturizer(), max_history=10)
		self.agent = Agent(domain_file , policies=[MemoizationPolicy(max_history=10), KerasPolicy(epochs = 90, batch_size = 20, validation_split = 0.1), fallback])
		data = self.agent.load_data(training_data_file)
		self.agent.train(data)
		self.agent.persist(model_path)
Ejemplo n.º 4
0
def train_bot():
    logging.basicConfig(level='INFO')

    training_data_file = './data/stories'
    model_path = './models/dialogue'

    fallback = FallbackPolicy(fallback_action_name="utter_not_understood",
                              core_threshold=0.3,
                              nlu_threshold=0.6)
    featurizer = MaxHistoryTrackerFeaturizer(BinarySingleStateFeaturizer(),
                                             max_history=5)
    agent = Agent('./data/domain.yml',
                  policies=[
                      MemoizationPolicy(max_history=5),
                      KerasPolicy(featurizer), fallback
                  ])

    training_data = agent.load_data(training_data_file)
    agent.train(training_data,
                augmentation_factor=50,
                epochs=500,
                batch_size=10,
                validation_split=0.2)

    agent.persist(model_path)
Ejemplo n.º 5
0
def train_bot():
    training_data_file = './data/stories'
    model_path = './models/dialogue'
    domain_file = './data/domain.yml'

    # core_threshold: min confidence needed to accept an action predicted by Rasa Core
    # nlu_threshold: min confidence needed to accept an intent predicted by the interpreter (NLU)
    fallback = FallbackPolicy(fallback_action_name="action_not_understood",
                              core_threshold=0.5,
                              nlu_threshold=0.35)

    featurizer = MaxHistoryTrackerFeaturizer(BinarySingleStateFeaturizer(),
                                             max_history=3)
    agent = Agent(domain=domain_file,
                  policies=[
                      MemoizationPolicy(max_history=2),
                      KerasPolicy(featurizer), fallback
                  ])

    training_data = agent.load_data(training_data_file)
    agent.train(training_data,
                augmentation_factor=50,
                epochs=400,
                batch_size=50,
                validation_split=0.2)

    agent.persist(model_path)
Ejemplo n.º 6
0
def train_dialogue(domain_file='restaurant_domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):
    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()])
    training_data = agent.load_data(training_data_file)
    agent.train(training_data)

    agent.persist(model_path)
    return agent
Ejemplo n.º 7
0
def train_dialogue():
    agent = Agent('domain.yml', policies=[MemoizationPolicy(), KerasPolicy()])
    training_data = agent.load_data('stories.md')

    agent.train(
        training_data)

    agent.persist('models/dialogue')
    return agent
Ejemplo n.º 8
0
def train_tracker_dialogue(
    domain_file="domain.yml",
    model_path="./models/dialogue",
    training_data_file="./data/stories.md",
):
    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()])
    data = agent.load_data(training_data_file)
    agent.train(data, epochs=300, batch_size=50, validation_split=0.2)
    agent.persist(model_path)
    return agent
Ejemplo n.º 9
0
def train_dialogue(domain_file, stories_file, dialogue_path):
    # loading our neatly defined training dialogues
    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy(epochs=200, max_history = 6)])
    training_data = agent.load_data(stories_file)


    agent.train(
        training_data)

    agent.persist(dialogue_path)
Ejemplo n.º 10
0
def train_dialogue(interpreter,domain_file = 'domain.yml',
                   model_path = './models/dialogue',
                   training_data_file = './data/stories.md'):

    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
Ejemplo n.º 11
0
def TrainCore():
    fallback = FallbackPolicy(fallback_action_name="utter_unclear",
                              core_threshold=0.2,
                              nlu_threshold=0.1)

    agent = Agent('domain.yml',
                  policies=[MemoizationPolicy(),
                            KerasPolicy(), fallback])
    training_data = agent.load_data('stories.md')

    agent.train(training_data, validation_split=0.0, epochs=500)
    agent.persist('models/dialogue')
Ejemplo n.º 12
0
def train_dialogue(domain_file = './backend/domain.yml',
					model_path = './backend/models/dialogue',
					training_data_file = './backend/stories.md'):
	fallback = FallbackPolicy(fallback_action_name="utter_unclear", core_threshold=0.1, nlu_threshold=0.1)				
	agent = Agent(domain_file, policies = [fallback, MemoizationPolicy(), KerasPolicy()])
	data = agent.load_data(training_data_file)	
	agent.train(
				data,
				epochs = 200,
				batch_size = 50,
				validation_split = 0.2)
				
	agent.persist(model_path)
	return agent
Ejemplo n.º 13
0
def train_dialogue(domain_file='restaurant_domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):
    fallback = FallbackPolicy(
        fallback_action_name="Sorry! Couldn't get what you are saying",
        core_threshold=0.2,
        nlu_threshold=0.1)
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(),
                            KerasPolicy(), fallback])
    training_data = agent.load_data(training_data_file)
    agent.train(training_data)
    agent.persist(model_path)
    return agent
def train_dialogue(domain_file='./domain/domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):
    fallback = FallbackPolicy(fallback_action_name="utter_unclear",
                              core_threshold=0.2,
                              nlu_threshold=0.65)
    agent = Agent(
        domain_file,
        policies=[MemoizationPolicy(max_history=10),
                  KerasPolicy(), fallback])
    data = agent.load_data(training_data_file)
    agent.train(data)
    agent.persist(model_path)
    return agent
Ejemplo n.º 15
0
def resto_test(interpreter,
               domain_file="resto_domain.yml",
               training_data_file='D:/RasaBot/data/stories.md'):

    #action_endpoint = EndpointConfig(url="http://localhost:5004/webhook")
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(),KerasPolicy()],
                  interpreter=interpreter)

    data = agent.load_data(training_data_file)
    agent.train_online(data)
    #interactive.run_interactive_learning(agent, training_data_file)

    return agent
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
def train_dialogue(domain_file='resto_domain.yml',
                   model_path='D:/RasaBot/nlu_model/dialogue',
                   training_data_file='D:/RasaBot/data/stories.md'):

    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(),
                            KerasPolicy(), fallback])

    data = agent.load_data(training_data_file)

    agent.train(data)

    agent.persist(model_path)

    return agent
Ejemplo n.º 18
0
def test_agent_and_persist():
    policies = config.load("policies.yml")
    policies[0] = KerasPolicy(epochs=2)  # Keep training times low

    agent = Agent("domain.yml", policies=policies)
    training_data = agent.load_data("data/stories.md")
    agent.train(training_data, validation_split=0.0)
    agent.persist("./tests/models/dialogue")

    loaded = Agent.load("./tests/models/dialogue")

    assert agent.handle_text("/greet") is not None
    assert loaded.domain.action_names == agent.domain.action_names
    assert loaded.domain.intents == agent.domain.intents
    assert loaded.domain.entities == agent.domain.entities
    assert loaded.domain.templates == agent.domain.templates
Ejemplo n.º 19
0
def run_weather_online(interpreter,
                       domain_file="domain.yml",
                       training_data_file='data/stories.md'):
    action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
    agent = Agent(domain_file,
                  policies=[
                      MemoizationPolicy(max_history=2),
                      KerasPolicy(max_history=3, epochs=3, batch_size=50)
                  ],
                  interpreter=interpreter,
                  action_endpoint=action_endpoint)

    data = agent.load_data(training_data_file)
    agent.train(data)
    interactive.run_interactive_learning(agent, training_data_file)
    return agent
Ejemplo n.º 20
0
def run_online(input_channel,
               interpreter,
               domain_file="domain.yml",
               training_data_file='stories.md'):
    fallback = FallbackPolicy(fallback_action_name="utter_unclear",
                              core_threshold=0.2,
                              nlu_threshold=0.4)

    agent = Agent('domain.yml',
                  policies=[MemoizationPolicy(),
                            KerasPolicy(), fallback],
                  interpreter=interpreter)

    training_data = agent.load_data(training_data_file)
    agent.train_online(training_data, input_channel=input_channel, epochs=200)

    return agent
Ejemplo n.º 21
0
def train_dialogue(domain_file='domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='stories.md'):
    fallback = FallbackPolicy(fallback_action_name='utter_unclear',
                              core_threshold=0.2,
                              nlu_threshold=0.6)
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(),
                            KerasPolicy(), fallback])

    agent.train(training_data_file,
                epochs=300,
                batch_size=50,
                validation_split=0.2)

    agent.persist(model_path)
    return agent
Ejemplo n.º 22
0
def run_online_training(input_channel,
                        interpreter,
                        domain_file="domain.yml",
                        training_data_file='stories.md'):
    fallback = FallbackPolicy(fallback_action_name='utter_unclear',
                              core_threshold=0.2,
                              nlu_threshold=0.6)
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(max_history=2),
                            KerasPolicy()],
                  interpreter=interpreter)

    agent.train_online(training_data_file,
                       input_channel=input_channel,
                       batch_size=50,
                       epochs=200,
                       max_training_samples=300)

    return agent
Ejemplo n.º 23
0
def train_dialogue(domain_file='./config/domain/domain.yml',
                   training_data_file='./config/stories/stories.md',
                   model_path='./models/dialogue'):
    fallback = FallbackPolicy(fallback_action_name="utter_default",
                              core_threshold=0.2,
                              nlu_threshold=0.1)
    agent = Agent(domain_file,
                  policies=[
                      MemoizationPolicy(),
                      KerasPolicy(), fallback,
                      FormPolicy(),
                      EmbeddingPolicy(epochs=100)
                  ])
    agent.visualize(training_data_file,
                    output_file="graph.html",
                    max_history=4)
    training_data = agent.load_data(
        training_data_file)  # augmentation_factor=0
    agent.train(training_data)
    agent.persist(model_path)
    return agent
Ejemplo n.º 24
0
def train_dialogue(domain_file="bot_domain.yml",
                   model_path="models/dialogue",
                   training_data_file="data/bot_stories.md"):

    fallback = FallbackPolicy(fallback_action_name="utter_default",
                          core_threshold=0.2,
                          nlu_threshold=0.1)
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(max_history=3),
                            KerasPolicy(), fallback])

    training_data = agent.load_data(training_data_file)
    agent.train(
            training_data,
            epochs=400,
            batch_size=100,
            validation_split=0.2
    )

    agent.persist(model_path)
    return agent
Ejemplo n.º 25
0
# In[36]:

get_ipython().system(
    'python -m rasa_core.train interactive -s stories.md --nlu models/nlu/ResBot -d domain.yml -o models/dialogue --verbose --endpoints endpoints.yml'
)

# In[71]:

from rasa_core.policies import KerasPolicy, MemoizationPolicy, FormPolicy
from rasa_core.agent import Agent

agent = Agent('domain.yml',
              policies=[
                  MemoizationPolicy(),
                  KerasPolicy(batch_size=100, epochs=500,
                              validation_split=0.2),
                  FormPolicy()
              ])

# loading our neatly defined training dialogues
training_data = agent.load_data('stories.md')

agent.train(training_data)

agent.persist('models/dialogue')

# In[ ]:

# In[ ]:
Ejemplo n.º 26
0
# contains script to create rasa core dialogue model based on leave_domain.yml data

from rasa_core.policies import KerasPolicy, MemoizationPolicy, TwoStageFallbackPolicy
from rasa_core.agent import Agent

# The fallback action will be executed if the intent recognition has #a confidence below nlu_threshold or if none of the dialogue #policies predict an action with confidence higher than #core_threshold.

agent = Agent(
    'sample_configs/leave_domain.yml',
    policies=[TwoStageFallbackPolicy(),
              MemoizationPolicy(),
              KerasPolicy()])

# loading our neatly defined training dialogues
training_data = agent.load_data('data/stories.md')
agent.train(training_data)

agent.persist('models/dialogue')
Ejemplo n.º 27
0
from rasa_core.policies import KerasPolicy

from rasa_core.policies import MemoizationPolicy, FormPolicy
from rasa_core.agent import Agent
import ruamel
import warnings
warnings.simplefilter('ignore', ruamel.yaml.error.UnsafeLoaderWarning)
agent = Agent('domain.yml',
              policies=[MemoizationPolicy(),
                        KerasPolicy(),
                        FormPolicy()])
training_data = agent.load_data('data/stories.md')
agent.train(training_data, validation_split=0.0)

agent.persist('models/dialogue')
Ejemplo n.º 28
0
#agent.visualize("stories.md", "story_graph.png", max_history=2)
#Image(filename="story_graph.png")




from rasa_core.policies import FallbackPolicy, KerasPolicy, MemoizationPolicy
from rasa_core.agent import Agent

# 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.6)

agent = Agent('domain.yml', policies=[MemoizationPolicy(), KerasPolicy()])

# loading our neatly defined training dialogues
training_data = agent.load_data('stories.md')

agent.train(
    training_data,
    validation_split=0.2,
    epochs=400
)

agent.persist('models/dialogue')

agent = Agent.load('models/dialogue', interpreter=model_directory)

print("Your bot is ready to talk! Type your messages here or send 'stop'")
Ejemplo n.º 29
0
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

from rasa_core.policies import FallbackPolicy, KerasPolicy, MemoizationPolicy
from rasa_core.agent import Agent
from tensorflow.python.framework import ops
ops.reset_default_graph()

import logging

if __name__ == '__main__':
    logging.basicConfig(level='INFO')

    #training_data_file = agent.load_data('./data/stories.md')
    #model_path = './models/dialogue'

    agent = Agent('mental_domain.yml',
                  policies=[
                      MemoizationPolicy(),
                      KerasPolicy(epochs=1000, batch_size=50)
                  ])
    training_data_file = agent.load_data('./data/stories.md')
    agent.train(training_data_file)
    #epochs = 1000,
    #validation_split = 0.2)

    agent.persist('./models/dialogue')
Ejemplo n.º 30
0
trainer = Trainer(config.load("NLU_model_Config.yml"))
# training the model
interpreter = trainer.train(training_data)
# storeing it for future
model_directory = trainer.persist("./models/nlu", fixed_model_name="current")
print("Done")

print("STEP 2: Training the CORE model")
fallback = FallbackPolicy(fallback_action_name="utter_default",
                          core_threshold=0.2,
                          nlu_threshold=0.1)

agent = Agent(domain='restaurant_domain.yml',
              policies=[
                  MemoizationPolicy(),
                  KerasPolicy(validation_split=0.0, epochs=200), fallback
              ])
training_data = agent.load_data('Core_Stories.md')
agent.train(training_data)
agent.persist('models/dialogue')
print("Done")
print("STEP 3: Starting the Bot")
from rasa_core.agent import Agent
agent = Agent.load('models/dialogue', interpreter=model_directory)

print("Your bot is ready to talk! Type your messages here or send 'stop'")
while True:
    a = input("You:")
    if a == 'stop':
        break
    responses = agent.handle_message(a)