From 759ae6ab0c836d014a1af1b16df48664bb442507 Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Fri, 21 Dec 2018 08:30:34 +0100 Subject: [PATCH 1/8] update examples --- .gitignore | 2 ++ examples/concertbot/Makefile | 9 ++++++++- examples/concertbot/policy_config.yml | 7 +++++++ examples/concertbot/train.py | 5 ++--- examples/concertbot/train_interactive.py | 6 ++---- examples/formbot/Makefile | 9 ++++++--- examples/formbot/actions.py | 9 +++------ examples/moodbot/Makefile | 17 +++++++++++++++-- examples/moodbot/rocketchat_credentials.yml | 9 +++++---- examples/restaurantbot/Makefile | 9 +++++++-- 10 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 examples/concertbot/policy_config.yml diff --git a/.gitignore b/.gitignore index 6589b094f9f..dd2c1b470fe 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,8 @@ tmp/ tokens.dat graph.png graph.html +story_graph.html +story_graph.dot debug.md examples/restaurantbot/models* examples/moodbot/*.png diff --git a/examples/concertbot/Makefile b/examples/concertbot/Makefile index 3b833999462..5f087a26ecc 100644 --- a/examples/concertbot/Makefile +++ b/examples/concertbot/Makefile @@ -7,6 +7,10 @@ help: @echo " Runs the core server." @echo " run-actions" @echo " Runs the action server." + @echo " train-interactive" + @echo " Train the bot with interactive learning." + @echo " visualize" + @echo " Show your stories as a graph." run: make run-actions& @@ -21,6 +25,9 @@ run-actions: train-core: python train.py -run-interactive: +train-interactive: make run-actions& python train_interactive.py + +visualize: + python visualize.py \ No newline at end of file diff --git a/examples/concertbot/policy_config.yml b/examples/concertbot/policy_config.yml new file mode 100644 index 00000000000..be27743c86e --- /dev/null +++ b/examples/concertbot/policy_config.yml @@ -0,0 +1,7 @@ +policies: + - name: KerasPolicy + epochs: 200 + batch_size: 50 + max_training_samples: 300 + - name: FallbackPolicy + - name: MemoizationPolicy diff --git a/examples/concertbot/train.py b/examples/concertbot/train.py index 7fc767cb678..cdb3d294344 100644 --- a/examples/concertbot/train.py +++ b/examples/concertbot/train.py @@ -10,15 +10,14 @@ model_path = 'models/dialogue' agent = Agent("domain.yml", - policies=[MemoizationPolicy(), KerasPolicy()]) + policies=[MemoizationPolicy(), KerasPolicy(epochs=500, + batch_size=10)]) training_data = agent.load_data(training_data_file) agent.train( training_data, augmentation_factor=50, - epochs=500, - batch_size=10, validation_split=0.2 ) diff --git a/examples/concertbot/train_interactive.py b/examples/concertbot/train_interactive.py index 429cdcdb3e7..e27428d679c 100644 --- a/examples/concertbot/train_interactive.py +++ b/examples/concertbot/train_interactive.py @@ -10,10 +10,8 @@ def train_agent(): return train.train_dialogue_model(domain_file="domain.yml", stories_file="data/stories.md", output_path="models/dialogue", - kwargs={"batch_size": 50, - "epochs": 200, - "max_training_samples": 300 - }) + policy_config='policy_config.yml' + ) if __name__ == '__main__': diff --git a/examples/formbot/Makefile b/examples/formbot/Makefile index 49efebb2095..9afd1e95ceb 100644 --- a/examples/formbot/Makefile +++ b/examples/formbot/Makefile @@ -7,12 +7,15 @@ help: @echo " Spin up the action server" @echo " run" @echo " Spin up both core and the action server" + @echo " train-interactive" + @echo " Train the bot with interactive learning." @echo " visualize" - @echo " Show your stories as a graph" - + @echo " Show your stories as a graph." + @echo " train-nlu" + @echo " Train the natural language understanding using Rasa NLU." train-core: - python -m rasa_core.train -s data/stories.md -d domain.yml -o models/dialogue --epochs 100 --debug + python -m rasa_core.train -s data/stories.md -d domain.yml -o models/dialogue --debug run-core: python -m rasa_core.run --core models/dialogue --nlu models/nlu/current --debug --endpoints endpoints.yml diff --git a/examples/formbot/actions.py b/examples/formbot/actions.py index 264fe2f5b7a..789f60f543e 100644 --- a/examples/formbot/actions.py +++ b/examples/formbot/actions.py @@ -11,8 +11,7 @@ class RestaurantForm(FormAction): """Example of a custom form action""" - def name(self): - # type: () -> Text + def name(self) -> Text: """Unique identifier of the form""" return "restaurant_form" @@ -24,8 +23,7 @@ def required_slots(tracker: Tracker) -> List[Text]: return ["cuisine", "num_people", "outdoor_seating", "preferences", "feedback"] - def slot_mappings(self): - # type: () -> Dict[Text: Union[Dict, List[Dict]]] + def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]: """A dictionary to map required slots to - an extracted entity - intent: value pairs @@ -51,8 +49,7 @@ def slot_mappings(self): self.from_text()]} @staticmethod - def cuisine_db(): - # type: () -> List[Text] + def cuisine_db() -> List[Text]: """Database of supported cuisines""" return ["caribbean", "chinese", diff --git a/examples/moodbot/Makefile b/examples/moodbot/Makefile index 4c41d62d3fc..c24bed5e01b 100644 --- a/examples/moodbot/Makefile +++ b/examples/moodbot/Makefile @@ -3,8 +3,12 @@ help: @echo " Train the natural language understanding using Rasa NLU." @echo " train-core" @echo " Train a dialogue model using Rasa core." - @echo " run" - @echo " Spin up a server that serves as an endpoint to receive facebook user messages." + @echo " run-{channel}" + @echo " Spin up a server that uses the connector for {channel}." + @echo " evaluate-nlu" + @echo " Evaluates the nlu data." + @echo " visualize" + @echo " Show your stories as a graph." train-nlu: python -m rasa_nlu.train -c nlu_model_config.yml --fixed_model_name current \ @@ -25,6 +29,15 @@ run-telegram: run-rocketchat: python -m rasa_core.run -d models/dialogue -u models/nlu/current -p 5002 -c rocketchat --credentials rocketchat_credentials.yml +run-mattermost: + python -m rasa_core.run -d models/dialogue -u models/nlu/current -p 5002 -c mattermost --credentials credentials.yml + +run-twilio: + python -m rasa_core.run -d models/dialogue -u models/nlu/current -p 5002 -c twilio --credentials credentials.yml + +run-webexteams: + python -m rasa_core.run -d models/dialogue -u models/nlu/current -p 5002 -c webexteams --credentials credentials.yml + run-cmdline: python -m rasa_core.run -d models/dialogue -u models/nlu/current diff --git a/examples/moodbot/rocketchat_credentials.yml b/examples/moodbot/rocketchat_credentials.yml index e6b36b45828..d345be03eb1 100644 --- a/examples/moodbot/rocketchat_credentials.yml +++ b/examples/moodbot/rocketchat_credentials.yml @@ -1,4 +1,5 @@ -user: "your_bot_user" -password: "you_bot_pass" -server_url: "localhost:3000" -ssl: false +rocketchat: + user: "your_bot_user" + password: "you_bot_pass" + server_url: "localhost:3000" + ssl: false diff --git a/examples/restaurantbot/Makefile b/examples/restaurantbot/Makefile index 89dac48eb00..70e7a195cbf 100644 --- a/examples/restaurantbot/Makefile +++ b/examples/restaurantbot/Makefile @@ -1,10 +1,15 @@ help: + @echo " run" + @echo " Runs the bot on the command line." + @echo " run-actions" + @echo " Runs the action server." + @echo " run-core" + @echo " Runs the core server." @echo " train-nlu" @echo " Train the natural language understanding using Rasa NLU." @echo " train-core" @echo " Train a dialogue model using Rasa core." - @echo " run" - @echo " Runs the bot on the command line." + run: make run-actions& From e2120db6f15b0e90fc695961e7aeaf5c781b428a Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Fri, 21 Dec 2018 08:31:31 +0100 Subject: [PATCH 2/8] update changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4c2cb6fd826..fb533124ef8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -41,6 +41,7 @@ Fixed - fix error during interactive learning which was caused by actions which dispatched messages using ``dispatcher.utter_custom_message`` - re-added missing ``python-engineio`` dependency +- fixed not working examples in ``examples/`` [0.12.3] - 2018-12-03 From 797d1f71e11a54cb8c913df88370d145b2ac2884 Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Fri, 21 Dec 2018 08:34:53 +0100 Subject: [PATCH 3/8] remove empty line, add newline at end --- examples/concertbot/Makefile | 2 +- examples/restaurantbot/Makefile | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/concertbot/Makefile b/examples/concertbot/Makefile index 5f087a26ecc..c01683f8973 100644 --- a/examples/concertbot/Makefile +++ b/examples/concertbot/Makefile @@ -30,4 +30,4 @@ train-interactive: python train_interactive.py visualize: - python visualize.py \ No newline at end of file + python visualize.py diff --git a/examples/restaurantbot/Makefile b/examples/restaurantbot/Makefile index 70e7a195cbf..d4070d4b59f 100644 --- a/examples/restaurantbot/Makefile +++ b/examples/restaurantbot/Makefile @@ -10,7 +10,6 @@ help: @echo " train-core" @echo " Train a dialogue model using Rasa core." - run: make run-actions& make run-core From c9060b30ad047ebe4a3c8b3e63a81f7ff9a21f7a Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Fri, 21 Dec 2018 08:41:44 +0100 Subject: [PATCH 4/8] revert changes to formbot due to https://github.com/RasaHQ/rasa_core/pull/1506 --- examples/formbot/Makefile | 9 +++------ examples/formbot/actions.py | 9 ++++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/formbot/Makefile b/examples/formbot/Makefile index 9afd1e95ceb..49efebb2095 100644 --- a/examples/formbot/Makefile +++ b/examples/formbot/Makefile @@ -7,15 +7,12 @@ help: @echo " Spin up the action server" @echo " run" @echo " Spin up both core and the action server" - @echo " train-interactive" - @echo " Train the bot with interactive learning." @echo " visualize" - @echo " Show your stories as a graph." - @echo " train-nlu" - @echo " Train the natural language understanding using Rasa NLU." + @echo " Show your stories as a graph" + train-core: - python -m rasa_core.train -s data/stories.md -d domain.yml -o models/dialogue --debug + python -m rasa_core.train -s data/stories.md -d domain.yml -o models/dialogue --epochs 100 --debug run-core: python -m rasa_core.run --core models/dialogue --nlu models/nlu/current --debug --endpoints endpoints.yml diff --git a/examples/formbot/actions.py b/examples/formbot/actions.py index 789f60f543e..264fe2f5b7a 100644 --- a/examples/formbot/actions.py +++ b/examples/formbot/actions.py @@ -11,7 +11,8 @@ class RestaurantForm(FormAction): """Example of a custom form action""" - def name(self) -> Text: + def name(self): + # type: () -> Text """Unique identifier of the form""" return "restaurant_form" @@ -23,7 +24,8 @@ def required_slots(tracker: Tracker) -> List[Text]: return ["cuisine", "num_people", "outdoor_seating", "preferences", "feedback"] - def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]: + def slot_mappings(self): + # type: () -> Dict[Text: Union[Dict, List[Dict]]] """A dictionary to map required slots to - an extracted entity - intent: value pairs @@ -49,7 +51,8 @@ def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]: self.from_text()]} @staticmethod - def cuisine_db() -> List[Text]: + def cuisine_db(): + # type: () -> List[Text] """Database of supported cuisines""" return ["caribbean", "chinese", From 3d7c5b51fd084f891305832a7f87c82de973ae42 Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Wed, 2 Jan 2019 14:30:21 +0100 Subject: [PATCH 5/8] add test for concertbot --- examples/concertbot/train.py | 34 +++++++++++++++------------------- tests/test_examples.py | 10 ++++++++++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/examples/concertbot/train.py b/examples/concertbot/train.py index cdb3d294344..16d53f72d58 100644 --- a/examples/concertbot/train.py +++ b/examples/concertbot/train.py @@ -1,24 +1,20 @@ -from rasa_core import utils -from rasa_core.agent import Agent -from rasa_core.policies.keras_policy import KerasPolicy -from rasa_core.policies.memoization import MemoizationPolicy +from rasa_core import train, utils -if __name__ == '__main__': - utils.configure_colored_logging(loglevel="INFO") - - training_data_file = 'data/stories.md' - model_path = 'models/dialogue' - agent = Agent("domain.yml", - policies=[MemoizationPolicy(), KerasPolicy(epochs=500, - batch_size=10)]) +def train_dialogue(domain_file='domain.yml', + stories_file='data/stories.md', + model_path='models/dialogue', + policy_config='policy_config.yml'): + utils.configure_colored_logging(loglevel="INFO") - training_data = agent.load_data(training_data_file) + return train.train_dialogue_model(domain_file=domain_file, + stories_file=stories_file, + output_path=model_path, + policy_config=policy_config, + kwargs={'augmentation_factor': 50, + 'validation_split': 0.2} + ) - agent.train( - training_data, - augmentation_factor=50, - validation_split=0.2 - ) - agent.persist(model_path) +if __name__ == '__main__': + train_dialogue() diff --git a/tests/test_examples.py b/tests/test_examples.py index d8fb76ad080..d3f7574c433 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -89,3 +89,13 @@ def test_formbot_example(): httpretty.disable() assert responses[0]['text'] == 'chitchat' + + +def test_concertbot_training(): + from examples.concertbot.train import train_dialogue + + assert train_dialogue(domain_file='examples/concertbot/domain.yml', + stories_file='examples/concertbot/data/stories.md', + model_path='examples/concertbot/models/dialogue', + policy_config='examples/concertbot/' + 'policy_config.yml') From 984d6416b8efebba8aca63e25955fc7fbb5dd11e Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Wed, 2 Jan 2019 17:13:16 +0100 Subject: [PATCH 6/8] fix overlapping stories --- examples/concertbot/data/stories.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/concertbot/data/stories.md b/examples/concertbot/data/stories.md index af1611694fc..a757c3fdafc 100644 --- a/examples/concertbot/data/stories.md +++ b/examples/concertbot/data/stories.md @@ -21,9 +21,15 @@ - slot{"concerts": [{"artist": "Foo Fighters", "reviews": 4.5}]} ## compare_reviews_venues +* search_venues + - action_search_venues + - slot{"venues": [{"name": "Big Arena", "reviews": 4.5}]} * compare_reviews - action_show_venue_reviews ## compare_reviews_concerts +* search_concerts + - action_search_concerts + - slot{"concerts": [{"artist": "Foo Fighters", "reviews": 4.5}]} * compare_reviews - action_show_concert_reviews From b9957519d9a152975b5716c243f92b57ba39a04f Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Wed, 2 Jan 2019 17:22:29 +0100 Subject: [PATCH 7/8] add print that their is no NLU data for the concerbot --- examples/concertbot/train.py | 6 ++++++ examples/concertbot/train_interactive.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/examples/concertbot/train.py b/examples/concertbot/train.py index 16d53f72d58..ad373cf0122 100644 --- a/examples/concertbot/train.py +++ b/examples/concertbot/train.py @@ -1,11 +1,17 @@ from rasa_core import train, utils +import logging +logger = logging.getLogger(__name__) + def train_dialogue(domain_file='domain.yml', stories_file='data/stories.md', model_path='models/dialogue', policy_config='policy_config.yml'): utils.configure_colored_logging(loglevel="INFO") + logger.info("This example does not include NLU data." + "Please specify the desired intent with a preceding '/', e.g." + "'/greet' .") return train.train_dialogue_model(domain_file=domain_file, stories_file=stories_file, diff --git a/examples/concertbot/train_interactive.py b/examples/concertbot/train_interactive.py index e27428d679c..118fb91f233 100644 --- a/examples/concertbot/train_interactive.py +++ b/examples/concertbot/train_interactive.py @@ -7,6 +7,11 @@ def train_agent(): + utils.configure_colored_logging(loglevel="INFO") + logger.info("This example does not include NLU data." + "Please specify the desired intent with a preceding '/', e.g." + "'/greet' .") + return train.train_dialogue_model(domain_file="domain.yml", stories_file="data/stories.md", output_path="models/dialogue", From e537ce822709932f00fe9edc0530b7babc92661f Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Thu, 3 Jan 2019 11:00:48 +0100 Subject: [PATCH 8/8] move log messages after training --- examples/concertbot/train.py | 10 +++++----- examples/concertbot/train_interactive.py | 8 +++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/concertbot/train.py b/examples/concertbot/train.py index ad373cf0122..c590f00cf20 100644 --- a/examples/concertbot/train.py +++ b/examples/concertbot/train.py @@ -8,11 +8,6 @@ def train_dialogue(domain_file='domain.yml', stories_file='data/stories.md', model_path='models/dialogue', policy_config='policy_config.yml'): - utils.configure_colored_logging(loglevel="INFO") - logger.info("This example does not include NLU data." - "Please specify the desired intent with a preceding '/', e.g." - "'/greet' .") - return train.train_dialogue_model(domain_file=domain_file, stories_file=stories_file, output_path=model_path, @@ -24,3 +19,8 @@ def train_dialogue(domain_file='domain.yml', if __name__ == '__main__': train_dialogue() + + utils.configure_colored_logging(loglevel="INFO") + logger.info("This example does not include NLU data." + "Please specify the desired intent with a preceding '/', e.g." + "'/greet' .") diff --git a/examples/concertbot/train_interactive.py b/examples/concertbot/train_interactive.py index 118fb91f233..b81d0bc61d4 100644 --- a/examples/concertbot/train_interactive.py +++ b/examples/concertbot/train_interactive.py @@ -7,11 +7,6 @@ def train_agent(): - utils.configure_colored_logging(loglevel="INFO") - logger.info("This example does not include NLU data." - "Please specify the desired intent with a preceding '/', e.g." - "'/greet' .") - return train.train_dialogue_model(domain_file="domain.yml", stories_file="data/stories.md", output_path="models/dialogue", @@ -22,4 +17,7 @@ def train_agent(): if __name__ == '__main__': utils.configure_colored_logging(loglevel="INFO") agent = train_agent() + logger.info("This example does not include NLU data." + "Please specify the desired intent with a preceding '/', e.g." + "'/greet' .") interactive.run_interactive_learning(agent)