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

Commit

Permalink
Merge branch 'master' of github.com:RasaHQ/rasa_core
Browse files Browse the repository at this point in the history
  • Loading branch information
tmbo committed Feb 1, 2018
2 parents d5507c1 + 0a5f48f commit d79b329
Show file tree
Hide file tree
Showing 13 changed files with 2,664 additions and 6,686 deletions.
Binary file modified docs/_static/images/babi_flow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions docs/domains.rst
Expand Up @@ -49,7 +49,7 @@ Defining Custom Actions

The easiest are ``UtterActions``, which just send a message to the user. You define them by adding an entry to the
action list that is named after the utterance. E.g. if there should be an action that utters the template called
``utter_greet`` you need to add ``greet`` to the list of defined actions. In the above example yaml you can see that
``utter_greet`` you need to add ``utter_greet`` to the list of defined actions. In the above example yaml you can see that
all three of the defined actions are just named after utter templates and hence just respond with a message to
the user.

Expand All @@ -66,7 +66,7 @@ your bot would execute the action ``ActionCheckRestaurants``, which might look l
class ActionCheckRestaurants(Action):
def name(self):
# type: () -> Text
return "check_restaurants"
return "action_check_restaurants"

def run(self, dispatcher, tracker, domain):
# type: (Dispatcher, DialogueStateTracker, Domain) -> List[Event]
Expand Down Expand Up @@ -124,7 +124,7 @@ Templates defined in a domains yaml file can contain images and buttons as well:
.. code-block:: yaml
templates:
utter_greeting:
utter_greet:
- text: "Hey! How are you?"
buttons:
- title: "great"
Expand Down Expand Up @@ -153,7 +153,7 @@ like this:
.. code-block:: yaml
templates:
utter_greeting:
utter_greet:
- text: "Hey, {name}. How are you?"
Rasa will automatically fill that variable with a value found in a slot called
Expand Down
4 changes: 2 additions & 2 deletions docs/scheduling.rst
Expand Up @@ -50,7 +50,7 @@ Here is an example implementation for our ``action_confirm_booking``:

class ActionConfirmBooking(Action):
def name(self):
return "confirm_booking"
return "action_confirm_booking"

def run(self, dispatcher, tracker, domain):
dispatcher.utter_message("Do you want to confirm your booking at Papi's pizza?")
Expand All @@ -71,7 +71,7 @@ example could look like this:

class ActionBookingReminder(Action):
def name(self):
return "booking_reminder"
return "action_booking_reminder"

def run(self, dispatcher, tracker, domain):
dispatcher.utter_message("You have an unconfirmed booking at Papi's pizza, would you like to confirm it?")
Expand Down
54 changes: 34 additions & 20 deletions docs/tutorial_basics.rst
Expand Up @@ -78,24 +78,25 @@ So what do the different parts mean?
| ``templates`` | template strings for the things your bot can say |
+---------------+------------------------------------------------------------------------------------------------------+

In our simple example we don't need slots, so that section doesn't appear
In our simple example we don't need ``slots`` and ``entities``, so these sections don't appear
in our definition.

**How does this fit together?**
Rasa takes the ``intent``, ``entities``, and the internal state of the dialogue,
and selects one of the ``actions`` that should be executed next.
If the action is just to say something to the user, Rasa will look for a matching
template in the domain (action name equals the utter template, as for
``utter_greeting`` in the above example), fill in any variables,
and respond.
``utter_greet`` in the above example), fill in any variables,
and respond. For actions
which do more than just send a message, you can define them as
python classes and reference them in the domain by their module path. See
:ref:`custom_actions` for more information about custom actions.

.. note::

There is one special action, ``ActionListen``, which means to stop taking
further actions until the user says something else. For actions
which do more than just send a message, you can define them as
python classes and reference them in the domain by their module path. See
:ref:`custom_actions` for more information about custom actions.
There is one additional special action, ``ActionListen``, which means to stop taking
further actions until the user says something else.
It is not specified in the ``domain.yml``

2. Define an interpreter
^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -106,6 +107,7 @@ In this example we are going to use Rasa NLU for this purpose.

In Rasa NLU, we need to define the user messages our bot should be able to
handle in the `Rasa NLU training data format <https://nlu.rasa.ai/dataformat.html>`_.
In this tutorial we are going to use Markdown Format for NLU training data.
Let's create some intent examples in ``data/nlu.md``:

.. literalinclude:: ../examples/moodbot/data/nlu.md
Expand All @@ -130,8 +132,9 @@ Let's run
python -m rasa_nlu.train -c nlu_model_config.json --fixed_model_name current
to train our NLU model. A new directory ``models/nlu/current`` should have been
created containing the NLU model.
to train our NLU model. A new directory ``models/nlu/default/current`` should have been
created containing the NLU model. Note that ``default`` stands for project name, since we did not
specify it explicitly in ``nlu_model_config.json``.

.. note::

Expand All @@ -144,26 +147,32 @@ created containing the NLU model.
So far, we've got an NLU model, a domain defining the actions our bot can
take, and inputs it should handle (intents & entities). We are still
missing the central piece, **stories to tell our bot what to do at which
point in the dialogue**. There are two different ways to create stories (and
point in the dialogue**.

A **story** is a training data sample for the dialogue system.
There are two different ways to create stories (and
you can mix them):

- create the stories by hand, writing them directly to a file
- create stories using interactive learning (see :ref:`tutorial_interactive_learning`).

For this example, we are going to create the stories by writing them directly
to ``stories.md``. But be aware, although it is a bit faster to write
stories directly by hand instead of using interactive learning, special
care needs to be taken when using slots, as they need to be properly set in the
stories. But enough talking, let's head over to our stories:
to ``stories.md``.
Stories begin with ``##`` and a string as an identifier. User actions start
with an asterisk, and bot actions are specified by lines beginning with a
dash. The end of a story is denoted by a newline. See :ref:`stories` for
more information about the data format.

Enough talking, let's head over to our stories:

.. literalinclude:: ../examples/moodbot/data/stories.md
:linenos:
:language: md

Stories begin with ``##`` and a string as an identifier. User actions start
with an asterisk, and bot actions are specified by lines beginning with a
dash. The end of a story is denoted by a newline. See :ref:`stories` for
more information about the data format.
Be aware, although it is a bit faster to write
stories directly by hand instead of using interactive learning, special
care needs to be taken when using slots, as they need to be properly set in the
stories.

4. Put the pieces together
^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -183,13 +192,18 @@ Here we'll just talk to the bot on the command line:

.. code-block:: bash
python -m rasa_core.run -d models/dialogue -u models/nlu/current
python -m rasa_core.run -d models/dialogue -u models/nlu/default/current
And there we have it! A minimal bot containing all the important pieces of
Rasa Core.

.. image:: _static/images/facebook-run.png

.. note::

Button emulation does not work in console output, you need to type words like "great" or "sad"
instead of numbers 1 or 2.

Bonus: Handle messages from Facebook
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
67 changes: 38 additions & 29 deletions docs/tutorial_interactive_learning.rst
Expand Up @@ -75,11 +75,11 @@ Below is an excerpt of the stories.
## greet
* greet
- action_greet
- utter_greet
## happy
* thankyou
- action_youarewelcome
- utter_youarewelcome
...
## compare_reviews_venues
Expand All @@ -94,8 +94,7 @@ Below is an excerpt of the stories.
Interactive Learning
^^^^^^^^^^^^^^^^^^^^

Run the script ``train_online.py``. This first runs the
``train_init`` script, creating a stateless policy by combining the stories
Run the script ``train_online.py``. This first creats a stateless policy by combining the stories
we've provided into longer dialogues, and then trains the policy on that
dataset.

Expand All @@ -110,7 +109,7 @@ where the learning *becomes interactive*):
so when you type messages to the bot you have to
type the intent starting with a ``/`` (see :ref:`fixed_intent_format`).
If you want to use Rasa NLU / wit.ai / Lex you
can just swap the ``Interpreter`` class in ``run.py``.
can just swap the ``Interpreter`` class in ``run.py`` and ``train_online.py``.

We now start talking to the bot by directly entering the intents. For
example, if we type ``/greet``, we get the following prompt:
Expand All @@ -121,13 +120,15 @@ example, if we type ``/greet``, we get the following prompt:
------
Chat history:
bot did: None
bot did: action_listen
user said: /greet
whose intent is: greet
we currently have slots: {'location': None}
whose intent is: greet
we currently have slots: concerts: None, venues: None
------
The bot wants to [greet] due to the intent. Is this correct?
The bot wants to [utter_greet] due to the intent. Is this correct?
1. Yes
2. No, intent is right but the action is wrong
Expand All @@ -137,13 +138,14 @@ example, if we type ``/greet``, we get the following prompt:
This gives you all the info you should hopefully need to decide
what the bot *should* have done. In this case, the bot chose the right
action ('greet'), so we type ``1`` and hit enter. We continue this loop
until the bot chooses the wrong action.
action ('utter_greet'), so we type ``1`` and hit enter.
Then we type ``1`` again, because 'action_listen' is the correct action after greeting.
We continue this loop until the bot chooses the wrong action.

**Providing feedback on errors**

We've just asked the bot to search for concerts, and now we're asking it to
compare reviews. The bot happens to choose the wrong one out of the two
If you ask ``/search_concerts``, the bot should suggest ``action_search_concerts`` and then ``action_listen``.
Now let's ask it to ``/compare_reviews``. The bot happens to choose the wrong one out of the two
possibilities we wrote in the stories:

.. code-block:: text
Expand All @@ -153,15 +155,14 @@ possibilities we wrote in the stories:
Chat history:
bot did: action_search_concerts
bot did: action_suggest
bot did: action_listen
user said: /compare_reviews
whose intent is: compare_reviews
we currently have slots: {'location': None}
we currently have slots: concerts: [{'artist': 'Foo Fighters', 'reviews': 4.5}, {'artist': 'Katy Perry', 'reviews': 5.0}], venues: None
------
The bot wants to [show_venue_reviews] due to the intent. Is this correct?
The bot wants to [action_show_venue_reviews] due to the intent. Is this correct?
1. Yes
2. No, intent is right but the action is wrong
Expand All @@ -176,22 +177,21 @@ model has assigned to each of the actions.
.. code-block:: text
what is the next action for the bot?
0 default 0.00148131744936
1 greet 0.0970264300704
2 goodbye 0.0288009047508
3 listen 0.00123148341663
6 search_cinemas 0.000627864559647
8 search_films 0.0367559418082
9 suggest 0.0261212754995
11 youarewelcome 0.594935178757
13 explain_options 0.0516758263111
14 store_slot 0.00145904591773
15 show_cinema_reviews 0.00887114647776
16 show_film_reviews 0.0870243906975
0 action_listen 0.19
1 action_restart 0.00
2 utter_default 0.00
3 utter_greet 0.03
4 utter_goodbye 0.03
5 utter_youarewelcome 0.02
6 action_search_concerts 0.09
7 action_search_venues 0.02
8 action_show_concert_reviews 0.29
9 action_show_venue_reviews 0.33
In this case, the bot should ``show_film_reviews`` (rather than cinema
reviews!) so we type ``16`` and hit enter.
In this case, the bot should ``action_show_concert_reviews`` (rather than venue
reviews!) so we type ``8`` and hit enter.

.. note::

Expand All @@ -206,6 +206,15 @@ current conversation to a file and exit the conversation. Make sure to
combine the dumped story with your original training data for the next
training.

.. note::

If you run the bot with not enough training data, it might get ``action_listen``
as a most probable response to your input and therefore do nothing.
If you continue to input something and get no answer, please head to
interactive training and check if ``action_listen`` was chosen as a response.
Correct the bot's behaviour, add additional stories and run ``train.py`` then
run the bot again.

Motivation: Why Interactive Learning?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit d79b329

Please sign in to comment.