Skip to content

Commit

Permalink
Merge pull request #6088 from RasaHQ/rules
Browse files Browse the repository at this point in the history
Rules
  • Loading branch information
rasabot authored Jul 10, 2020
2 parents df1d1b4 + 3cb9b5f commit d703081
Show file tree
Hide file tree
Showing 86 changed files with 6,451 additions and 773 deletions.
4 changes: 2 additions & 2 deletions changelog/5996.feature.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Introduced a new `YAML` format of the Core training data and implemented a parser for it.
Rasa Open Source can now read stories in both `Markdown` and `YAML` formats.
Introduced a new ``YAML`` format for Core training data and implemented a parser
for it. Rasa Open Source can now read stories in both ``Markdown`` and ``YAML`` format.
1 change: 1 addition & 0 deletions changelog/6065.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for rule data and forms in YAML format.
20 changes: 20 additions & 0 deletions changelog/6088.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Added the new dialogue policy ``RulePolicy`` which will replace the old "rule-like"
policies :ref:`mapping-policy`, :ref:`fallback-policy`,
:ref:`two-stage-fallback-policy`, and :ref:`form-policy`. These policies are now
deprecated and will be removed in the future. Please see ``examples/rules``
for a usage example.

Added new NLU component ``FallbackClassifier`` which predicts an intent ``nlu_fallback``
in case the confidence was below a given threshold. The intent ``nlu_fallback`` may
then be used to write stories / rules to handle the fallback in case of low NLU
confidence.

.. code-block::
pipeline:
- ... # Other NLU components
- name: FallbackClassifier
# If the highest ranked intent has a confidence lower than the threshold then
# the NLU pipeline predicts an intent `nlu_fallback` which you can then be used in
# stories / rules to implement an appropriate fallback.
threshold: 0.5
5 changes: 4 additions & 1 deletion data/test_evaluations/form-end-to-end-stories.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- restaurant_form
- form{"name": "restaurant_form"}
- form{"name": null}
- utter_submit
- utter_slots_values
* thankyou: /thankyou
- utter_noworries
Expand All @@ -18,6 +19,7 @@
* form: /inform{"cuisine": "afghan"} <!-- intent "inform" is ignored inside the form -->
- form: restaurant_form
- form{"name": null}
- utter_submit
- utter_slots_values
* thankyou: /thankyou
- utter_noworries
Expand All @@ -32,6 +34,7 @@
- utter_chitchat
- restaurant_form
- form{"name": null}
- utter_submit
- utter_slots_values
* thankyou: /thankyou
- utter_noworries
- utter_noworries
23 changes: 23 additions & 0 deletions data/test_stories/rules_without_stories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
>> rule 1
- form{"name": "loop_q_form"} <!-- condition that form is active-->
- slot{"requested_slot": "some_slot"} <!-- some condition -->
- ...
* inform{"some_slot":"bla"} <!-- can be ANY -->
- loop_q_form <!-- can be internal core action, can be anything -->

>> rule 2
- form{"name": "loop_q_form"} <!-- condition that form is active-->
- slot{"requested_slot": "some_slot"} <!-- some condition -->
- ...
* explain <!-- can be anything -->
- utter_explain_some_slot
- loop_q_form
- form{"name": "loop_q_form"} <!-- condition that form is active-->

>> rule 3
- form{"name": "loop_q_form"} <!-- condition that form is active-->
- ...
- loop_q_form <!-- condition that form is active -->
- form{"name": null}
- slot{"requested_slot": null}
- action_stop_q_form
48 changes: 48 additions & 0 deletions data/test_stories/stories_with_rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
>> rule 1
- form{"name": "loop_q_form"} <!-- condition that form is active-->
- slot{"requested_slot": "some_slot"} <!-- some condition -->
- ...
* inform{"some_slot":"bla"} <!-- can be ANY -->
- loop_q_form <!-- can be internal core action, can be anything -->

>> rule 2
- form{"name": "loop_q_form"} <!-- condition that form is active-->
- slot{"requested_slot": "some_slot"} <!-- some condition -->
- ...
* explain <!-- can be anything -->
- utter_explain_some_slot
- loop_q_form
- form{"name": "loop_q_form"} <!-- condition that form is active-->

## ML story 1
* greet
- utter_greet
* request_restaurant
- restaurant_form
- form{"name": "restaurant_form"}
- form{"name": null}
- utter_slots_values
* thankyou
- utter_noworries

>> rule 3
- form{"name": "loop_q_form"} <!-- condition that form is active-->
- ...
- loop_q_form <!-- condition that form is active -->
- form{"name": null}
- slot{"requested_slot": null}
- action_stop_q_form

## ML story 2
* greet
- utter_greet
* request_restaurant
- restaurant_form
- form{"name": "restaurant_form"}
* chitchat
- utter_chitchat
- restaurant_form
- form{"name": null}
- utter_slots_values
* thankyou
- utter_noworries
2 changes: 1 addition & 1 deletion data/test_wrong_yaml_stories/wrong_yaml.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
!
[dasdassd,
30 changes: 30 additions & 0 deletions data/test_yaml_stories/rules_without_stories.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
rules:
- rule: rule 1
steps:
- form: loop_q_form
- slot: requested_slot
value: some_slot
- ...
- intent: inform
entities:
- some_slot: bla
- action: loop_q_form

- rule: rule 2
steps:
- form: loop_q_form
- slot: requested_slot
value: some_slot
- ...
- intent: explain
- action: utter_explain_some_slot
- action: loop_q_form
- form: loop_q_form

- rule: rule 3
steps:
- form: loop_q_form
- ...
- form: null
- slot: null
- action: stop_q_form
51 changes: 51 additions & 0 deletions data/test_yaml_stories/stories_and_rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
rules:
- rule: rule 1
steps:
- form: loop_q_form
- slot: requested_slot
value: some_slot
- ...
- intent: inform
entities:
- some_slot: bla
- action: loop_q_form

- rule: rule 2
steps:
- form: loop_q_form
- slot: requested_slot
value: some_slot
- ...
- intent: explain
- action: utter_explain_some_slot
- action: loop_q_form
- form: loop_q_form

- rule: rule 3
steps:
- form: loop_q_form
- ...
- form: null
- slot: null
- action: stop_q_form

stories:
- story: simple_story_without_checkpoint
steps:
- intent: simple
- action: utter_default
- action: utter_greet

- story: simple_story_with_only_start
steps:
- checkpoint: check_greet # checkpoints at the start define entry points
- intent: simple
- action: utter_default

- story: simple_story_with_only_end
steps:
- intent: hello
- action: utter_greet
- slot: name
value: peter
- checkpoint: check_greet # checkpoint defining the end of this turn
1 change: 1 addition & 0 deletions docs/core/policies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ The ``FallbackPolicy`` invokes a :ref:`fallback action
You can include either the ``FallbackPolicy`` or the
``TwoStageFallbackPolicy`` in your configuration, but not both.

.. _two-stage-fallback-policy:

Two-Stage Fallback Policy
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
5 changes: 1 addition & 4 deletions examples/formbot/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ pipeline:
- name: EntitySynonymMapper

policies:
- name: FallbackPolicy
- name: MemoizationPolicy
- name: FormPolicy
- name: MappingPolicy
- name: RulePolicy
Loading

0 comments on commit d703081

Please sign in to comment.