示例#1
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
示例#2
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)
	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)
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)
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)
示例#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
示例#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
示例#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
示例#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)
示例#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
示例#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')
示例#12
0
def train_dialog():
    ## TODO bei sehr wenig stories - wie am Anfang - probiert erst memoization unk keras
    agent = Agent("domain.yml", policies=[MemoizationPolicy(), KerasPolicy()])
    ## TODO sobald der Bot ein wenig stabil wird, nach ein duzent Stories oder so, probiere nur Keras
    #agent = Agent("domain.yml", policies=[KerasPolicy()])
    stories_file = "data\stories"
    stories_data = agent.load_data(stories_file)
    output_path = "models\dialog"
    agent.train(
        stories_data,
        validation_split=0.2,
    )
    agent.persist(output_path)
示例#13
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
示例#14
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
示例#16
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
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 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
示例#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
示例#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
示例#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
示例#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
示例#23
0
文件: bot.py 项目: karthikcs/USTA-Bot
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
示例#24
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
示例#25
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')
import warnings
logging.basicConfig(level="INFO")
warnings.filterwarnings('ignore')

# loading the nlu training samples
training_data = load_data("nlu.md")

# trainer to educate our pipeline
trainer = Trainer(config.load("nlu_config.yml"))

# train the model!
interpreter = trainer.train(training_data)

# store it for future use
model_directory = trainer.persist("./models/nlu", project_name='legal_project', fixed_model_name="legal_model")

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

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

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

agent.train(training_data, validation_split=0.0)

agent.persist('models/dialogue')
示例#27
0
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

import logging

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

if __name__ == '__main__':
    logging.basicConfig(level='INFO')
    training_data_file = 'stories.md'
    model_path = './models/dialogue'
    fallback = FallbackPolicy(fallback_action_name='utter_unclear', core_threshold=0.2, nlu_threshold=0.6)
    agent = Agent('domain.yml', policies=[MemoizationPolicy(max_history=2), KerasPolicy(), fallback])

    agent.train(
        training_data_file,
        epochs=400,
        batch_size=20,
        validation_split=0.1)

    agent.persist(model_path)
示例#28
0
"""
Created on Thu May 23 05:22:14 2019

@author: Jiwitesh_Sharma
"""
import logging

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

if __name__ == '__main__':
    logging.basicConfig(level='INFO')
    training_data_file = './data/stories.md'
    model_path = './models/dialogue'
    agent = Agent('restaurant_domain.yml',
                  policies=[MemoizationPolicy(),
                            KerasPolicy()],
                  action_endpoint='./endpoints.yml')
    training_data = agent.load_data(training_data_file)
    agent.train(training_data)
    model_directory = agent.persist(model_path)

#agent = Agent.load(model_path, interpreter=model_directory)
"""print("Your bot is ready to talk! Type your messages here or send 'stop'")
while True:
    a = input()
    if a == 'stop':
        break
    responses = agent.handle_text(a)
    for response in responses:
        print(response["text"])"""
示例#29
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'")
示例#30
0
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

import logging
from rasa_core.agent import Agent
from rasa_core.policies import KerasPolicy
from rasa_core.policies import MemoizationPolicy

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

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

    agent = Agent('akshay_domain.yml',
                  policies=[MemoizationPolicy(max_history=5),
                            KerasPolicy()])

    agent.train(
        training_data_file,
        augmentation_factor=50,  ## create extra stories
        epochs=500,
        batch_size=10,
        validation_split=0.2)

    agent.persist(model_path)