def test_topic_question(): filename = 'data/test_dialogues/topic_question.json' tracker = tracker_from_dialogue_file( filename, TemplateDomain.load("data/test_domains/default_with_topic.yml")) question_topic = QuestionTopic assert tracker.topic_stack.top.name == question_topic.name
def test_inmemory_tracker_store(filename): domain = TemplateDomain.load("data/test_domains/default_with_topic.yml") tracker = tracker_from_dialogue_file(filename, domain) tracker_store = InMemoryTrackerStore(domain) tracker_store.save(tracker) restored = tracker_store.retrieve(tracker.sender_id) assert restored == tracker
def trained_policy(self): default_domain = TemplateDomain.load("examples/default_domain.yml") policy = self.create_policy() X, y = train_data(self.max_history, default_domain) policy.max_history = self.max_history policy.featurizer = BinaryFeaturizer() policy.train(X, y, default_domain) return policy
def tracker_from_dialogue_file(filename, domain=None): dialogue = read_dialogue_file(filename) dialogue_topics = set([Topic(t.topic) for t in dialogue.events if isinstance(t, SetTopic)]) domain = domain if domain is not None else TemplateDomain.load("examples/default_domain.yml") domain.topics.extend(dialogue_topics) tracker = DialogueStateTracker(dialogue.name, domain.slots, domain.topics, domain.default_topic) tracker.update_with_dialogue(dialogue) return tracker
def load(cls, path, interpreter=None, tracker_store=None): # type: (Text, Any, Optional[TrackerStore]) -> Agent domain = TemplateDomain.load(os.path.join(path, "domain.yml")) # ensures the domain hasn't changed between test and train domain.compare_with_specification(path) featurizer = Featurizer.load(path) ensemble = PolicyEnsemble.load(path, featurizer) _interpreter = NaturalLanguageInterpreter.create(interpreter) _tracker_store = cls._create_tracker_store(tracker_store, domain) return Agent(domain, ensemble, featurizer, _interpreter, _tracker_store)
def _create_domain(cls, domain): if isinstance(domain, str): return TemplateDomain.load(domain) elif isinstance(domain, Domain): return domain else: raise ValueError( "Invalid param `domain`. Expected a path to a domain " "specification or a domain instance. But got " "type '{}' with value '{}'".format(type(domain), domain))
def run_hello_world(serve_forever=True): default_domain = TemplateDomain.load("examples/default_domain.yml") agent = Agent(default_domain, policies=[SimplePolicy()], interpreter=HelloInterpreter(), tracker_store=InMemoryTrackerStore(default_domain)) if serve_forever: # Attach the commandline input to the controller to handle all # incoming messages from that channel agent.handle_channel(ConsoleInputChannel()) return agent
def test_tracker_restaurant(): domain = TemplateDomain.load("data/test_domains/default_with_slots.yml") filename = 'data/test_dialogues/restaurant_search.json' tracker = tracker_from_dialogue_file(filename, domain) assert tracker.get_slot("cuisine") == "indian" assert tracker.get_slot("location") == "central"
def default_domain(): return TemplateDomain.load("examples/default_domain.yml")
def test_domain_from_template(): file = "examples/restaurant_domain.yml" domain = TemplateDomain.load(file) logger.info(domain.intents) assert len(domain.intents) == 6 assert len(domain.actions) == 18
help="max history to consider when merging " "paths in the output graph") parser.add_argument('-nlu', '--nlu_data', default=None, help="path of the NLU training data, " "used to insert example messages into the graph") return parser if __name__ == '__main__': parser = create_argparser() args = parser.parse_args() logging.basicConfig(level="DEBUG") domain = TemplateDomain.load(args.domain) story_steps = StoryFileReader.read_from_file(args.stories, domain) # this is optional, only needed if the `_greet` type of # messages in the stories should be replaced with actual # messages (e.g. `hello`) if args.nlu_data is not None: from mynlu.converters import load_data nlu_data = load_data(args.nlu_data) else: nlu_data = None logger.info("Starting to visualize stories...") visualize_stories(story_steps, args.output,
from conversationinsights.actions.action import ActionListen from conversationinsights.agent import Agent from conversationinsights.conversation import Topic from conversationinsights.domain import TemplateDomain from conversationinsights.events import UserUtterance, SetTopic, ExecutedAction from conversationinsights.featurizers import BinaryFeaturizer from conversationinsights.interpreter import NaturalLanguageInterpreter from conversationinsights.tracker_store import InMemoryTrackerStore, RedisTrackerStore from conversationinsights.trackers import DialogueStateTracker from conversationinsights.training_utils import create_stories_from_file from utilities import tracker_from_dialogue_file, read_dialogue_file import logging logger = logging.getLogger(__name__) domain = TemplateDomain.load("data/test_domains/default_with_topic.yml") def stores_to_be_tested(): return [RedisTrackerStore(domain, mock=True), InMemoryTrackerStore(domain)] def stores_to_be_tested_ids(): return ["redis-tracker", "in-memory-tracker"] def test_tracker_duplicate(): filename = "data/test_dialogues/inform_no_change.json" dialogue = read_dialogue_file(filename)
# paths data_dir = "./examples/phonebook/data" db_file = data_dir + "/phonebook.db" fe_file = data_dir + "/total_word_feature_extractor.dat" weights_file = data_dir + "/weights.h5" arch_file = data_dir + "/arch.json" classifier_file = data_dir + "/classifier.dat" ner_file = data_dir + "/ner.dat" # create an domain instance # domain = PhonebookDomain(db_file) # create the policy, interpreter, and controller instances domain = TemplateDomain.load("examples/default_domain.yml") #policy = Policy(weights_file,arch_file,default_domain) featurizer = BinaryFeaturizer() p = KerasPolicy() policy = p.load("examples/babi/models/policy/current", featurizer, max_history=3) interpreter = MyNLUHttpInterpreter("default", "token", "http://127.0.0.1:5000") controller = Controller(interpreter, policy, domain, InMemoryTrackerStore(domain)) #def test_hello(): # tracker = controller.handle_message("") # response = controller.get_next_action(tracker, "hi") # response = controller.handle_message("hi") # logger.info("response:{}".format(response))