Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1510 from RasaHQ/update_examples
Browse files Browse the repository at this point in the history
Update examples
  • Loading branch information
wochinge committed Jan 3, 2019
2 parents 7853d2c + e537ce8 commit 1c7b28a
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion examples/concertbot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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&
Expand All @@ -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
6 changes: 6 additions & 0 deletions examples/concertbot/data/stories.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions examples/concertbot/policy_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
policies:
- name: KerasPolicy
epochs: 200
batch_size: 50
max_training_samples: 300
- name: FallbackPolicy
- name: MemoizationPolicy
39 changes: 20 additions & 19 deletions examples/concertbot/train.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
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")
import logging
logger = logging.getLogger(__name__)

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

agent = Agent("domain.yml",
policies=[MemoizationPolicy(), KerasPolicy()])
def train_dialogue(domain_file='domain.yml',
stories_file='data/stories.md',
model_path='models/dialogue',
policy_config='policy_config.yml'):
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}
)

training_data = agent.load_data(training_data_file)

agent.train(
training_data,
augmentation_factor=50,
epochs=500,
batch_size=10,
validation_split=0.2
)
if __name__ == '__main__':
train_dialogue()

agent.persist(model_path)
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' .")
9 changes: 5 additions & 4 deletions examples/concertbot/train_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ 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__':
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)
17 changes: 15 additions & 2 deletions examples/moodbot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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

Expand Down
9 changes: 5 additions & 4 deletions examples/moodbot/rocketchat_credentials.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions examples/restaurantbot/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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&
Expand Down
10 changes: 10 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 1c7b28a

Please sign in to comment.