How to write training stories with multiple values for one entity

Hello,

I am new to the Rasa platform and I have a question about how to write the stories for training where one entity can have two or more different values extracted from the NLU part. I will ask my question through example.

  1. I have an intent ask_product_info with the following training data:
## intent:ask_product_info
- Can you tell me more about rasa [core](product)?
- Please, provide me more information about rasa [nlu](product)
- information about [core](product)
- can you explain how [nlu](product) works 
  1. I have separate utterances that explains core and nlu utter_provide_core_info utter_provide_nlu_info.

  2. At the beginning, I have the following stories:

* greet
    - utter_greet
* ask_product_info{"product": "core"}
    - utter_provide_core_info

* greet
    - utter_greet
* ask_product_info{"product": "nlu"}
    - utter_provide_nlu_info

So, basically I want the bot to provide different information based on the entity that is extracted. I am somewhat familiar with slots as well, but I excluded that part for simplicity.

Question: My question is, is there a way to create story where for the product entity there would be multiple values, for example something like this:

* greet
    - utter_greet
* ask_product_info{"product": ["core", "nlu"]}
    - utter_provide_core_info
    - utter_provide_nlu_info

I haven’t seen this kind of example yet. Also, I tried using Interactive Learning, but it didn’t solve my problem. I typed “Can you tell me more about rasa core and rasa nlu?”, and the NLU part extracted both entities correctly, but after I finished with Interactive Learning and exported the data, my story had the following format:

* greet
    - utter_greet
* ask_product_info{"product": "nlu"}

So, the entity value for “core” was lost.

I would appreciate if someone could help me with this or provide me an opinion how to solve this. This is just an example, I couldn’t provide the original code because it is in Cyrillic and tried to reformat my problem with the example that I used. Thanks

2 Likes

Hi Goran, there’s a good example of this in the CarbonBot and it’s use of the city slot. You would define your product entity as a list (like city) and then use a form like airtravel_form. From the stories.md you’ll see the example:

* inform{"city": "Berlin"}
    - slot{"city": ["Berlin", "San Francisco"]}
    - airtravel_form
    - form{"name": "airtravel_form"}
    - form{"name": null}

What about the case where you just want to see if the slot has ANY value set?

Ie. check to see if the slot is not None?

This is really needed for dialogue flow, but I don’t see how to do it in the documentation.

You can specify it this way in either a Story or Rule. There’s a story example with a null value here.

    - slot_was_set:
      - my_slot_name: null

The syntax is the same for rules & stories. Rule conditions are discussed here.

1 Like

Wonderful, thanks Greg.

I had tried - my_intent {"my_slot": null} as suggested elsewhere in this forum, however contrary to what the poster said (“this works for me”) it did not actually seem to work.

However, I see this uses a Rule:

  1. Does that mean I need to add RulePolicy to policies.yml ?
  2. And does that mean it only works with 2.0, and not Rasa 1.x ?

Hmm, I appreciate the reply, but that does not work at all. Using the syntax you provided:

-slot_was_set:

- my_slot_name: null

results in:

Failed to use action 'my_slot_name: null' in history. Please make sure all actions are listed in the domains action list.

(to be clear, my_slot_name is the name of the actual slot.)

Also, what about cases where you want to check that the slot IS set (to any value, ie not null)

Also, the example you linked to is really unclear, it seems like it is setting the slot, not seeing if it is set!

What’s going on here? This is incredibly confusing. What exactly is going on here? The syntax given in the answer does not work, is there something missing?

Looks like there was a known issue regarding this which is discussed in more detail here and was fixed in version 2.1.0.

Glad to hear this was a known issue! It resulted in some extremely weird side effects that required significant debugging!

Does this mean that slot_was_set is working in 2.1.0 for stories? Or do you have to apply it using Rules?

Also, do you have anyone there who can explain the reason behind using “null” rather than “None”? Python doesn’t actually have “null” but instead uses the None singleton. Is there a CPP library being invoked here? Thanks, it’s a bit confusing.