Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide only rule dialogue turns #7701

Merged
merged 110 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 108 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
29901e3
hide only rule dialogue turns
Ghostvv Jan 8, 2021
d957f5d
add missing docstrings
Ghostvv Jan 8, 2021
c7fed26
fix docstrings
Ghostvv Jan 8, 2021
02e35f4
Merge branch 'master' into hide_rules
Ghostvv Jan 9, 2021
ff5014a
fix hiding rules
Ghostvv Jan 11, 2021
52c5b31
Merge branch 'hide_rules' of https://github.com/RasaHQ/rasa into hide…
Ghostvv Jan 11, 2021
ab64782
add tests
Ghostvv Jan 11, 2021
e55933e
add changelog
Ghostvv Jan 11, 2021
f7d083b
add docs
Ghostvv Jan 11, 2021
ee525c6
Update docs/docs/rules.mdx
Ghostvv Jan 11, 2021
bcca577
Update changelog/7701.improvement.md
Ghostvv Jan 11, 2021
cba4f69
Update docs/docs/rules.mdx
Ghostvv Jan 11, 2021
75516ce
create featurize for prediction helpers to automatically set for_only…
Ghostvv Jan 11, 2021
fa77daa
additionaly check states in the test
Ghostvv Jan 12, 2021
2d14b24
Merge branch 'master' into hide_rules
Ghostvv Jan 12, 2021
fc92ab2
add a test for a rule without action listen in the end
Ghostvv Jan 14, 2021
a0c9fa9
Merge branch 'master' into hide_rules
Ghostvv Jan 18, 2021
4a8e6d9
Merge branch 'master' into hide_rules
Ghostvv Jan 20, 2021
7bc11de
Update rasa/core/policies/policy.py
Ghostvv Jan 20, 2021
0d43cd4
Update rasa/core/policies/ted_policy.py
Ghostvv Jan 20, 2021
f4d5d21
Update rasa/core/policies/policy.py
Ghostvv Jan 21, 2021
02078c9
Update rasa/core/featurizers/tracker_featurizers.py
Ghostvv Jan 21, 2021
2d3b093
rename for_only_ml to ignore_rule_only ...
Ghostvv Jan 21, 2021
87f1f80
Merge branch 'master' into hide_rules
Ghostvv Jan 21, 2021
edd0ae7
fix overriding self._prediction_source
Ghostvv Jan 22, 2021
54cdb38
Merge branch 'main' into hide_rules
Ghostvv Jan 22, 2021
7531521
fix prediction source from text
Ghostvv Jan 25, 2021
4a1e78e
Merge branch 'hide_rules' of https://github.com/RasaHQ/rasa into hide…
Ghostvv Jan 25, 2021
b651ace
remove in-loop events
Ghostvv Jan 25, 2021
fde0e7b
fix test
Ghostvv Jan 25, 2021
11a90ac
Merge branch 'main' into hide_rules
Ghostvv Jan 25, 2021
c7139cd
Merge branch 'main' into hide_rules
Ghostvv Jan 26, 2021
8a01931
Merge branch 'main' into hide_rules
Ghostvv Jan 26, 2021
85dc5e5
Merge branch 'main' into hide_rules
Ghostvv Jan 27, 2021
0908d14
merge master
Ghostvv Jan 28, 2021
58c8b9c
fix test
Ghostvv Feb 3, 2021
15e0e3f
Merge branch 'main' into hide_rules
Ghostvv Feb 3, 2021
ebeb1e0
Merge branch 'main' into hide_rules
Ghostvv Feb 5, 2021
23c37fa
Update rasa/shared/core/generator.py
Ghostvv Feb 8, 2021
631d73c
Update rasa/shared/core/events.py
Ghostvv Feb 8, 2021
4b70aa6
fix hiding followup action and add test
Ghostvv Feb 9, 2021
eb45bce
Merge branch 'hide_rules' of https://github.com/RasaHQ/rasa into hide…
Ghostvv Feb 9, 2021
e492196
Merge branch 'main' into hide_rules
Ghostvv Feb 9, 2021
c01f748
Merge branch 'main' into hide_rules
Ghostvv Feb 10, 2021
06b9360
Update tests/core/policies/test_rule_policy.py
Ghostvv Feb 10, 2021
0a1c244
Update rasa/shared/core/domain.py
Ghostvv Feb 10, 2021
33ec863
Update rasa/shared/core/domain.py
Ghostvv Feb 10, 2021
c34d61a
get rid of self._prediction_source as any policy needs to be stateless
Ghostvv Feb 10, 2021
b2883c0
Merge branch 'main' into hide_rules
Ghostvv Feb 10, 2021
3f79e38
refactor find contradicting rules
Ghostvv Feb 10, 2021
e263efb
add comment about default sources
Ghostvv Feb 10, 2021
be8c190
update docstring
Ghostvv Feb 10, 2021
5470a64
update docstring
Ghostvv Feb 10, 2021
5e8162c
update docstring
Ghostvv Feb 10, 2021
a84c1f6
add test to not hide loops that are in stories
Ghostvv Feb 10, 2021
9e19c58
use loop rules separator constant
Ghostvv Feb 10, 2021
fbfef6c
update docstring
Ghostvv Feb 10, 2021
a73ea80
Merge branch 'main' into hide_rules
Ghostvv Feb 10, 2021
c89b515
Merge branch 'main' into hide_rules
Ghostvv Feb 15, 2021
71e68d0
remove HideRuleTurnEvent
Ghostvv Feb 15, 2021
bf76057
Merge branch 'main' into hide_rules
Ghostvv Feb 15, 2021
fbfc4a3
persist hide_rule_turn
Ghostvv Feb 16, 2021
7154ddd
fix typo
Ghostvv Feb 16, 2021
67553db
fix docstrings
Ghostvv Feb 16, 2021
f5b4ff2
Merge branch 'main' into hide_rules
Ghostvv Feb 16, 2021
46ac847
fix tests
Ghostvv Feb 18, 2021
fb9bf7a
Merge branch 'main' into hide_rules
Ghostvv Feb 18, 2021
e359bf2
Merge branch 'main' into hide_rules
Ghostvv Feb 18, 2021
de0a9c5
extract rule only staff inside rulepolicy
Ghostvv Feb 19, 2021
9706297
undo changing moodbot config
Ghostvv Feb 22, 2021
025890b
Merge branch 'main' into hide_rules
Ghostvv Feb 22, 2021
6be585a
Merge branch 'main' into hide_rules
Ghostvv Feb 24, 2021
5b4ec07
Merge branch 'main' into hide_rules
Ghostvv Mar 9, 2021
d6ced62
unwrap kwargs as early as possible
Ghostvv Mar 9, 2021
2220a93
Update rasa/core/policies/rule_policy.py
Ghostvv Mar 9, 2021
625dcc5
rename method in ensemble
Ghostvv Mar 9, 2021
b6784e8
use version 2.0 when create domain
Ghostvv Mar 9, 2021
60b2830
Merge branch 'hide_rules' of https://github.com/RasaHQ/rasa into hide…
Ghostvv Mar 9, 2021
b1bf011
use f-string
Ghostvv Mar 9, 2021
2322f93
add tests to remove DefinePrevUserUtteredFeaturization
Ghostvv Mar 9, 2021
869f405
test processor to ignore rules
Ghostvv Mar 9, 2021
df8ddd7
Merge branch 'main' into hide_rules
Ghostvv Mar 9, 2021
c372d89
Merge branch 'main' into hide_rules
Ghostvv Mar 10, 2021
9c4f3fc
fix domain yaml strings in test
Ghostvv Mar 10, 2021
72a03aa
mention rule only staff directly in arg
Ghostvv Mar 10, 2021
02edec0
Update rasa/shared/core/domain.py
Ghostvv Mar 10, 2021
249dcb8
create _predict helper
Ghostvv Mar 10, 2021
313966b
Merge branch 'main' into hide_rules
Ghostvv Mar 10, 2021
16984c8
add new arguments to changelog
Ghostvv Mar 10, 2021
35978ed
add story without a rule as example to docs
Ghostvv Mar 10, 2021
9ce5e91
don't try to fix domain yaml in test_actions.py
Ghostvv Mar 10, 2021
b351015
Merge branch 'main' into hide_rules
Ghostvv Mar 10, 2021
7c3b0ea
Merge branch 'main' into hide_rules
Ghostvv Mar 10, 2021
017e01a
Merge branch 'main' into hide_rules
Ghostvv Mar 11, 2021
d65feaa
simplify rule_only_data for policies
Ghostvv Mar 11, 2021
d981e27
add docstring
Ghostvv Mar 11, 2021
19b7305
Merge branch 'main' into hide_rules
Ghostvv Mar 11, 2021
703ff3c
merge main
Ghostvv Mar 11, 2021
962b411
merge main
Ghostvv Mar 15, 2021
34d48dd
fix omit_unset_slots merge
Ghostvv Mar 15, 2021
fd3af73
Merge branch 'main' into hide_rules
Ghostvv Mar 18, 2021
8a298ec
rename to shared states
Ghostvv Mar 18, 2021
68660b9
Merge branch 'main' into hide_rules
Ghostvv Mar 19, 2021
5d5f83d
Update rasa/shared/core/domain.py
Ghostvv Mar 19, 2021
e2b7342
Update rasa/shared/core/trackers.py
Ghostvv Mar 19, 2021
fb039cd
Update rasa/core/policies/rule_policy.py
Ghostvv Mar 19, 2021
c1ed6ba
Update rasa/shared/core/generator.py
Ghostvv Mar 19, 2021
fe2aab6
update changelog
Ghostvv Mar 19, 2021
031c8a4
Merge branch 'main' into hide_rules
Ghostvv Mar 22, 2021
67502b6
Merge branch 'main' into hide_rules
Ghostvv Mar 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog/7701.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Hide dialogue turns predicted by `RulePolicy` in the tracker states
for ML-only policies like `TEDPolicy`
if those dialogue turns only appear as rules in the training data and do not appear in stories.

Add `set_shared_policy_states(...)` method to all policies.
This method sets `_rule_only_data` dict with keys:
- `rule_only_slots`: Slot names, which only occur in rules but not in stories.
- `rule_only_loops`: Loop names, which only occur in rules but not in stories.

This information is needed for correct featurization to hide dialogue turns that appear only in rules.
6 changes: 4 additions & 2 deletions data/test_dialogues/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"confidence": null,
"policy": null,
"timestamp": 1551952977.4850519,
"unpredictable": false
"unpredictable": false,
"hide_rule_turn": false
},
{
"py/object": "rasa.shared.core.events.UserUttered",
Expand Down Expand Up @@ -61,7 +62,8 @@
"confidence": null,
"policy": null,
"timestamp": 1551953040.607782,
"unpredictable": false
"unpredictable": false,
"hide_rule_turn": false
},
{
"py/object": "rasa.shared.core.events.BotUttered",
Expand Down
24 changes: 16 additions & 8 deletions data/test_dialogues/formbot.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"confidence":null,
"policy":null,
"timestamp":1551884035.892855,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.UserUttered",
Expand Down Expand Up @@ -43,7 +44,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551884060.466681,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.BotUttered",
Expand All @@ -62,7 +64,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551884061.9350882,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.UserUttered",
Expand Down Expand Up @@ -118,7 +121,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551884095.542748,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.ActionExecuted",
Expand All @@ -127,7 +131,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551884097.570883,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.BotUttered",
Expand All @@ -146,7 +151,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551884098.8006358,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.UserUttered",
Expand Down Expand Up @@ -180,7 +186,8 @@
"confidence":null,
"policy":null,
"timestamp":1551884214.951055,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.ActiveLoop",
Expand All @@ -200,7 +207,8 @@
"confidence":0.7680902069097734,
"policy":"policy_0_TEDPolicy",
"timestamp":1551884216.705635,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
}
]
}
21 changes: 14 additions & 7 deletions data/test_dialogues/moodbot.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"confidence":null,
"policy":null,
"timestamp":1551883958.346432,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.UserUttered",
Expand Down Expand Up @@ -69,7 +70,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551883975.6456478,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.BotUttered",
Expand Down Expand Up @@ -97,7 +99,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551883979.098331,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.UserUttered",
Expand Down Expand Up @@ -157,7 +160,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551883985.031668,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.BotUttered",
Expand All @@ -176,7 +180,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551883985.940413,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.BotUttered",
Expand All @@ -195,7 +200,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551883986.958556,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.UserUttered",
Expand Down Expand Up @@ -255,7 +261,8 @@
"confidence":1.0,
"policy":"policy_2_MemoizationPolicy",
"timestamp":1551883991.061463,
"unpredictable":false
"unpredictable":false,
"hide_rule_turn": false
},
{
"py/object":"rasa.shared.core.events.BotUttered",
Expand Down
15 changes: 10 additions & 5 deletions data/test_trackers/tracker_moodbot.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"name": "action_listen",
"action_text": null,
"policy": null,
"confidence": null
"confidence": null,
"hide_rule_turn": false
},
{
"timestamp": 1517821726.200036,
Expand Down Expand Up @@ -78,15 +79,17 @@
"name": "utter_greet",
"action_text": null,
"policy": null,
"confidence": null
"confidence": null,
"hide_rule_turn": false
},
{
"timestamp": 1517821726.211038,
"event": "action",
"name": "action_listen",
"action_text": null,
"policy": null,
"confidence": null
"confidence": null,
"hide_rule_turn": false
},
{
"timestamp": 1517821726.209836,
Expand Down Expand Up @@ -125,15 +128,17 @@
"name": "utter_happy",
"action_text": null,
"policy": "policy_1_TEDPolicy",
"confidence": 0.8
"confidence": 0.8,
"hide_rule_turn": false
},
{
"timestamp": 1517821726.211042,
"event": "action",
"name": "action_listen",
"action_text": null,
"policy": "policy_2_MemoizationPolicy",
"confidence": 1.0
"confidence": 1.0,
"hide_rule_turn": false
}
]
}
21 changes: 14 additions & 7 deletions data/test_trackers/tracker_moodbot_with_new_utterances.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"event": "action",
"name": "action_listen",
"policy": null,
"confidence": null
"confidence": null,
"hide_rule_turn": false
},
{
"timestamp": 1517821726.200036,
Expand Down Expand Up @@ -76,14 +77,16 @@
"event": "action",
"name": "utter_greet",
"policy": null,
"confidence": null
"confidence": null,
"hide_rule_turn": false
},
{
"timestamp": 1517821726.211038,
"event": "action",
"name": "action_listen",
"policy": null,
"confidence": null
"confidence": null,
"hide_rule_turn": false
},
{
"timestamp": 1517821726.209836,
Expand Down Expand Up @@ -121,14 +124,16 @@
"event": "action",
"name": "utter_happy",
"policy": "policy_1_TEDPolicy",
"confidence": 0.8
"confidence": 0.8,
"hide_rule_turn": false
},
{
"timestamp": 1517821726.211042,
"event": "action",
"name": "action_listen",
"policy": "policy_2_MemoizationPolicy",
"confidence": 1.0
"confidence": 1.0,
"hide_rule_turn": false
},
{
"timestamp": 1517821730.209836,
Expand Down Expand Up @@ -166,14 +171,16 @@
"event": "action",
"name": "utter_happy",
"policy": "policy_1_TEDPolicy",
"confidence": 0.8
"confidence": 0.8,
"hide_rule_turn": false
},
{
"timestamp": 1517821750.211042,
"event": "action",
"name": "action_listen",
"policy": "policy_2_MemoizationPolicy",
"confidence": 1.0
"confidence": 1.0,
"hide_rule_turn": false
}
]
}
23 changes: 23 additions & 0 deletions docs/docs/rules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ rules:
This example rule applies at the start of conversation as well as when the user decides
to a send a message with an intent `greet` in the middle of an ongoing conversation.

Dialogue turns that only appear as rules in the training data and do not appear in stories
will be ignored by ML-only policies like `TEDPolicy` at prediction time.

```yaml-rasa
rules:
- rule: Say `hello` whenever the user sends a message with intent `greet`
steps:
- intent: greet
- action: utter_greet

stories:
- story: story to find a restaurant
steps:
- intent: find_restaurant
- action: restaurant_form
- action: utter_restaurant_found
```

For example if you define the greeting rule as above and don't add it to any of your stories,
Ghostvv marked this conversation as resolved.
Show resolved Hide resolved
after `RulePolicy` predicts `utter_greet`, `TEDPolicy` will
make predictions as if the `greet, utter_greet` turn did not occur.


### Rules for the Conversation Start

To write a rule which only applies at the beginning of a conversation, add a
Expand Down
1 change: 1 addition & 0 deletions examples/e2ebot/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: en
pipeline:
- name: WhitespaceTokenizer
intent_tokenization_flag: True
- name: LanguageModelFeaturizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
Expand Down
6 changes: 5 additions & 1 deletion rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ def event_for_successful_execution(
Event which should be logged onto the tracker.
"""
return ActionExecuted(
self.name(), prediction.policy_name, prediction.max_confidence
self.name(),
prediction.policy_name,
prediction.max_confidence,
hide_rule_turn=prediction.hide_rule_turn,
)


Expand Down Expand Up @@ -332,6 +335,7 @@ def event_for_successful_execution(
policy=prediction.policy_name,
confidence=prediction.max_confidence,
action_text=self.action_text,
hide_rule_turn=prediction.hide_rule_turn,
)


Expand Down
Loading