Rules

How to combine stories and rules when writing training data without making them contradict each other.

Hi there, not sure I’ve understood your question, but I’ll give it a shot, let me know if you were looking for something else.

Basically, rules are law. Any conversation sequence that matches the “beginning of a rule” has to result in the end of the rule, because the system will always complete the steps of the rule. For example, say you have a rule that looks like:

- rule: return greeting
  steps:
  - intent: greet
  - action: utter_greet

This means, anytime the user greets the bot, the bot must greet back. A story that contradicts this would look like:

 - story: rude bot
   steps:
   - intent: greet
   - action: utter_dont_talk_to_me

This story contradicts the rule, because action: utter_greet didn’t follow intent: greet. Any story that contains some rule steps must contain the entire rule step sequence or disambiguate somehow (for example with slots, or a condition).

Hi!

Would it be possible for you to check my own thread, where I mention similar problem with rules/stories?

I didn’t obtain viable response on what’s actually wrong in my case and still - I don’t understand why it’s not working.

@BarMin, yep, see my response there! :slight_smile:

Hi, which means the rules and the stories need to be the same? Also, how can I link stories to each other

Well, they don’t have to be the same. Generally I’d expect a story to be longer than a rule. What’s important is that if the first steps of a rule match steps in the story the outcome in both the rule and the story must be the same, unless you disambiguate them with slots or a condition. So for example:

- story: sad path 1
  steps:
  - intent: greet
  - action: utter_greet
  - intent: mood_unhappy
  - action: utter_cheer_up
  - action: utter_did_that_help
  - intent: affirm
  - action: utter_happy

Can’t be paired with the rule:

rules:
 - rule: 
   steps:
   - intent: mood_unhappy
   - action: utter_cheer_up
   - action: utter_ask_how_are_you

Because the bot can’t learn what action to take after seeing a conversation like below. Should it be utter_ask_how_are_you or utter_did_that_help?

   user: mood_unhappy
   bot: utter_cheer_up

I’m not sure what you mean by linking stories. You shouldn’t have to do anything additional to allow the bot to transition from one story to another. Depending on the policy you have, the bot will predict the next action for an exact match, or a similar story. For example:

“The MemoizationPolicy remembers the stories from your training data. It checks if the current conversation matches the stories in your stories.yml file. If so, it will predict the next action from the matching stories of your training data” (source)

TEDPolicy and AugmentedMemoizationPolicy will generalise, meaning they can attempt to predict the next action even if they haven’t seen this sequence of events before.

You can try running rasa data validate to validate your stories, not the rules. But RulePolicy will abort training if there is a conflict between your rules and stories, so you’ll be alerted and have the opportunity to fix it. If you feel those error messages are confusing, you can feel free to ask a followup question here and tag me.