RasaHQ / rasa

💬 Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
https://rasa.com/docs/rasa/
Apache License 2.0
19.02k stars 4.65k forks source link

Unable to detect correct slot value #2191

Closed DhruvMevada closed 5 years ago

DhruvMevada commented 6 years ago
**Rasa Core version**: 0.9.0a5 **Python version**: 3.5 **Operating system** (windows, osx, ...): **Issue**: Currently I'm implementing chatbot which help people to book a taxi. In that I found that I need to ask user about **source location** and **destination location** as Mandatory slot But, when we try to train the data, **Bot will be confuse in what user inform is source location or destination location. For Example:** **User 1**: want to book a taxi from New York to New Jersey **User 2**: want to book a taxi from New Jersey to New York In this scenario when user said New York it will take source location both the time. When Bot ask (Because of Mandatory Slot) for destination location at that time user input should be store in destination location. I'm sharing code file here. [rasa_chat_bot.zip](https://github.com/RasaHQ/rasa_core/files/2071002/rasa_chat_bot.zip) **Story file:** **Content of domain file** (if used & relevant): ```yaml ## story_1 * greet - act_greet * booking - action_booking - slot{"requested_slot": "source_location"} - slot{"requested_slot": "destination_location"} * inform{"text": "NewYork"} - action_booking - slot{"city": "newyork"} - slot{"requested_slot": "destination_location"} * inform{"text": "NewJersey"} - action_booking - slot{"destination_location": "NewJersey"} * bye - act_goodbye ``` **NLU training Data File:** ```yaml { "rasa_nlu_data": { "common_examples": [ { "text": "i want to book a ride from satellite to rajkot in tokyo on 1:00", "intent": "int.ride_sharing.book_trip", "entities": [ { "start": 27, "end": 36, "value": "satellite", "entity": "source_location" }, { "start": 40, "end": 46, "value": "rajkot", "entity": "destination_location" }, { "start": 50, "end": 55, "value": "tokyo", "entity": "city" } ] }, { "text": "please book a ride from ahmedabad to gandhinagar", "intent": "int.ride_sharing.book_trip", "entities": [ { "start": 24, "end": 33, "value": "ahmedabad", "entity": "source_location" }, { "start": 37, "end": 48, "value": "gandhinagar", "entity": "destination_location" } ] }, { "text": "book a ride from ahmebabad to surat on 1:00", "intent": "int.ride_sharing.book_trip", "entities": [ { "start": 17, "end": 26, "value": "satellite", "entity": "source_location" },{ "start": 30, "end": 35, "value": "tokyo", "entity": "destination_location" } ] }, { "text": "need a cab from gurukul to iscon in ahmedabad on 1:00", "intent": "int.ride_sharing.book_trip", "entities": [ { "start": 16, "end": 22, "value": "gurukul", "entity": "source_location" }, { "start": 27, "end": 32, "value": "iscon", "entity": "destination_location" }, { "start": 36, "end": 45, "value": "ahmedabad", "entity": "city" } ] }, { "text": "I wish to book a taxi from nahrunagar to akhbarnagar in ahmedabad on 1:00", "intent": "int.ride_sharing.book_trip", "entities": [ { "start": 27, "end": 37, "value": "nahrunagar", "entity": "source_location" }, { "start": 41, "end": 52, "value": "akhbarnagar", "entity": "destination_location" }, { "start": 56, "end": 65, "value": "ahmedabad", "entity": "city" } ] }, { "text": "please book a ride in ahmedabad", "intent": "int.ride_sharing.book_trip", "entities": [ { "start": 22, "end": 31, "value": "ahmedabad", "entity": "city" } ] }, { "text": "i want to cancel my booking", "intent": "int.ride_sharing.cancel" }, { "text": "please cancel my booking", "intent": "int.ride_sharing.cancel" }, { "text": "please cancel my ride booking", "intent": "int.ride_sharing.cancel" }, { "text": "cancel my ride booking", "intent": "int.ride_sharing.cancel" }, { "text": "cancel my ride", "intent": "int.ride_sharing.cancel" }, { "text": "in ahmedabad", "intent": "inform", "entities": [ { "start": 3, "end": 12, "value": "ahmedabad", "entity": "destination_location" } ] }, { "text": "in gandhinagar", "intent": "inform", "entities": [ { "start": 3, "end": 14, "value": "gandhinagar", "entity": "destination_location" } ] },{ "text": "in pune", "intent": "inform", "entities": [ { "start": 3, "end": 7, "value": "pune", "entity": "destination_location" } ] },{ "text": "in banglore", "intent": "inform", "entities": [ { "start": 3, "end": 11, "value": "ahmedabad", "entity": "destination_location" } ] },{ "text": "in surat", "intent": "inform", "entities": [ { "start": 3, "end": 8, "value": "surat", "entity": "destination_location" } ] },{ "text": "in chennai", "intent": "inform", "entities": [ { "start": 3, "end": 10, "value": "chennai", "entity": "destination_location" } ] }, { "text": "in gandhinagar", "intent": "inform", "entities": [ { "start": 3, "end": 14, "value": "gandhinagar", "entity": "source_location" } ] },{ "text": "in pune", "intent": "inform", "entities": [ { "start": 3, "end": 7, "value": "pune", "entity": "source_location" } ] },{ "text": "in banglore", "intent": "inform", "entities": [ { "start": 3, "end": 11, "value": "ahmedabad", "entity": "source_location" } ] },{ "text": "in surat", "intent": "inform", "entities": [ { "start": 3, "end": 8, "value": "surat", "entity": "source_location" } ] },{ "text": "in chennai", "intent": "inform", "entities": [ { "start": 3, "end": 10, "value": "chennai", "entity": "source_location" } ] }, { "text": "hello", "intent": "int.general.greeting" }, { "text": "good morning", "intent": "int.general.greeting" }, { "text": "hi", "intent": "int.general.greeting" }, { "text": "hey", "intent": "int.general.greeting" }, { "text": "good evening", "intent": "int.general.greeting" }, { "text": "good afternoon", "intent": "int.general.greeting" }, { "text": "good bye", "intent": "int.general.goodbye" }, { "text": "see you later", "intent": "int.general.goodbye" }, { "text": "good night", "intent": "int.general.goodbye" }, { "text": "goodbye", "intent": "int.general.goodbye" }, { "text": "bye bye", "intent": "int.general.goodbye" }, { "text": "see you later", "intent": "int.general.goodbye" } ] } } ``` **Output:** ```yaml 2018-06-05 11:18:12.854777: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2018-06-05 11:18:27 INFO rasa_nlu.components - Added 'nlp_spacy' to component cache. Key 'nlp_spacy-en'. 2018-06-05 11:18:42 INFO root - Finished loading agent, starting input channel & server. Bot loaded. Type a message and press enter: Hi 2018-06-05 11:19:11 DEBUG rasa_core.tracker_store - Creating a new tracker for id 'default'. 2018-06-05 11:19:11 WARNING py.warnings - /home/dishank/local/lib/python2.7/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty. if diff: 2018-06-05 11:19:11 DEBUG rasa_core.processor - Received user message 'Hi' with intent '{u'confidence': 0.7453943588971064, u'name': u'int.general.greeting'}' and entities '[]' 2018-06-05 11:19:11 DEBUG rasa_core.processor - Logged UserUtterance - tracker now has 2 events 2018-06-05 11:19:11 DEBUG rasa_core.processor - Current slot values: source_location: None city: None requested_slot: None destination_location: None person: None 2018-06-05 11:19:11 DEBUG rasa_core.policies.memoization - Current tracker state [None, {}, {u'intent_int.ride_sharing.cancel': 0.057394109118420626, u'intent_int.general.goodbye': 0.06533073873098039, u'intent_int.general.greeting': 0.7453943588971064, u'intent_inform': 0.05906662276104775, u'prev_action_listen': 1.0, u'intent_int.ride_sharing.book_trip': 0.07281417049244424}] 2018-06-05 11:19:11 DEBUG rasa_core.policies.ensemble - Predicted next action 'act_greet' with prob 0.74. Greetings for the day 2018-06-05 11:19:11 DEBUG rasa_core.processor - Bot utterance 'BotUttered(text: Greetings for the day, data: null)' 2018-06-05 11:19:11 DEBUG rasa_core.processor - Action 'act_greet' ended with events '[]' 2018-06-05 11:19:11 DEBUG rasa_core.policies.memoization - Current tracker state [{}, {u'intent_int.ride_sharing.cancel': 0.057394109118420626, u'intent_int.general.goodbye': 0.06533073873098039, u'intent_int.general.greeting': 0.7453943588971064, u'intent_inform': 0.05906662276104775, u'prev_action_listen': 1.0, u'intent_int.ride_sharing.book_trip': 0.07281417049244424}, {u'intent_int.ride_sharing.cancel': 0.057394109118420626, u'intent_int.general.goodbye': 0.06533073873098039, u'intent_int.general.greeting': 0.7453943588971064, u'intent_inform': 0.05906662276104775, u'intent_int.ride_sharing.book_trip': 0.07281417049244424, u'prev_act_greet': 1.0}] 2018-06-05 11:19:11 DEBUG rasa_core.policies.ensemble - Predicted next action 'action_listen' with prob 0.78. 2018-06-05 11:19:11 DEBUG rasa_core.processor - Action 'action_listen' ended with events '[]' 2018-06-05 11:19:11 DEBUG rasa_core.processor - Current topic: None book a cab 2018-06-05 11:19:23 DEBUG rasa_core.tracker_store - Recreating tracker for id 'default' 2018-06-05 11:19:23 WARNING py.warnings - /home/dishank/local/lib/python2.7/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty. if diff: 2018-06-05 11:19:23 DEBUG rasa_core.processor - Received user message 'book a cab' with intent '{u'confidence': 0.6075605828385227, u'name': u'int.ride_sharing.book_trip'}' and entities '[]' 2018-06-05 11:19:23 DEBUG rasa_core.processor - Logged UserUtterance - tracker now has 6 events 2018-06-05 11:19:23 DEBUG rasa_core.processor - Current slot values: source_location: None city: None requested_slot: None destination_location: None person: None 2018-06-05 11:19:23 DEBUG rasa_core.policies.memoization - Current tracker state [{u'intent_int.ride_sharing.cancel': 0.057394109118420626, u'intent_int.general.goodbye': 0.06533073873098039, u'intent_int.general.greeting': 0.7453943588971064, u'intent_inform': 0.05906662276104775, u'prev_action_listen': 1.0, u'intent_int.ride_sharing.book_trip': 0.07281417049244424}, {u'intent_int.ride_sharing.cancel': 0.057394109118420626, u'intent_int.general.goodbye': 0.06533073873098039, u'intent_int.general.greeting': 0.7453943588971064, u'intent_inform': 0.05906662276104775, u'intent_int.ride_sharing.book_trip': 0.07281417049244424, u'prev_act_greet': 1.0}, {u'intent_int.ride_sharing.cancel': 0.11595299761082925, u'intent_int.general.goodbye': 0.1388611549581425, u'intent_int.general.greeting': 0.07939681815788609, u'intent_inform': 0.058228446434619524, u'prev_action_listen': 1.0, u'intent_int.ride_sharing.book_trip': 0.6075605828385227}] 2018-06-05 11:19:23 DEBUG rasa_core.policies.ensemble - Predicted next action 'action_booking' with prob 0.87. 2018-06-05 11:19:23 DEBUG rasa_core.actions.forms - FormAction Run -----------enter----------------- 2018-06-05 11:19:23 DEBUG rasa_core.actions.forms - FormAction Run -----------before field----------------- [, ] : end 2018-06-05 11:19:23 DEBUG rasa_core.actions.forms - FormAction Run -----------field----------------- : end which source Location ? 2018-06-05 11:19:23 DEBUG rasa_core.processor - Bot utterance 'BotUttered(text: which source Location ?, data: null)' 2018-06-05 11:19:23 DEBUG rasa_core.processor - Action 'action_booking' ended with events '[u'SlotSet(key: requested_slot, value: source_location)']' 2018-06-05 11:19:23 DEBUG rasa_core.policies.memoization - Current tracker state [{u'intent_int.ride_sharing.cancel': 0.057394109118420626, u'intent_int.general.goodbye': 0.06533073873098039, u'intent_int.general.greeting': 0.7453943588971064, u'intent_inform': 0.05906662276104775, u'intent_int.ride_sharing.book_trip': 0.07281417049244424, u'prev_act_greet': 1.0}, {u'intent_int.ride_sharing.cancel': 0.11595299761082925, u'intent_int.general.goodbye': 0.1388611549581425, u'intent_int.general.greeting': 0.07939681815788609, u'intent_inform':0.058228446434619524, u'prev_action_listen': 1.0, u'intent_int.ride_sharing.book_trip': 0.6075605828385227}, {u'intent_int.ride_sharing.cancel': 0.11595299761082925, u'intent_int.general.goodbye': 0.1388611549581425, u'intent_int.general.greeting': 0.07939681815788609, u'intent_inform': 0.058228446434619524, u'prev_action_booking': 1.0, u'intent_int.ride_sharing.book_trip': 0.6075605828385227}] 2018-06-05 11:19:23 DEBUG rasa_core.policies.ensemble - Predicted next action 'action_listen' with prob 1.00. 2018-06-05 11:19:23 DEBUG rasa_core.processor - Action 'action_listen' ended with events '[]' 2018-06-05 11:19:23 DEBUG rasa_core.processor - Current topic: None newyork 2018-06-05 11:19:28 DEBUG rasa_core.tracker_store - Recreating tracker for id 'default' 2018-06-05 11:19:28 WARNING py.warnings - /home/dishank/local/lib/python2.7/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty. if diff: 2018-06-05 11:19:28 DEBUG rasa_core.processor - Received user message 'newyork' with intent '{u'confidence': 0.7790142380549658, u'name': u'inform'}' and entities '[{u'extractor':u'ner_crf', u'confidence': 0.37477483075261214, u'end': 7, u'value': u'newyork', u'entity': 'destination_location', u'start': 0}]' 2018-06-05 11:19:28 DEBUG rasa_core.processor - Logged UserUtterance - tracker now has 12 events 2018-06-05 11:19:28 DEBUG rasa_core.processor - Current slot values: source_location: None city: None requested_slot: source_location destination_location: newyork person: None 2018-06-05 11:19:28 DEBUG rasa_core.policies.memoization - Current tracker state [{u'intent_int.ride_sharing.cancel': 0.11595299761082925, u'intent_int.general.goodbye': 0.1388611549581425, u'intent_int.general.greeting': 0.07939681815788609, u'intent_inform': 0.058228446434619524, u'prev_action_listen': 1.0, u'intent_int.ride_sharing.book_trip': 0.6075605828385227}, {u'intent_int.ride_sharing.cancel': 0.11595299761082925, u'intent_int.general.goodbye': 0.1388611549581425, u'intent_int.general.greeting': 0.07939681815788609, u'intent_inform': 0.058228446434619524, u'prev_action_booking': 1.0, u'intent_int.ride_sharing.book_trip': 0.6075605828385227}, {u'intent_int.ride_sharing.cancel': 0.04572284379891411, u'intent_int.general.greeting': 0.05196333630066613, u'prev_action_listen': 1.0, u'entity_destination_location': 1.0, u'slot_destination_location_0': 1.0, u'intent_int.general.goodbye': 0.03537435392138472, u'intent_inform': 0.7790142380549658, u'intent_int.ride_sharing.book_trip': 0.08792522792406904}] 2018-06-05 11:19:28 DEBUG rasa_core.policies.ensemble - Predicted next action 'action_booking' with prob 1.00. 2018-06-05 11:19:28 DEBUG rasa_core.actions.forms - FormAction Run -----------enter----------------- 2018-06-05 11:19:28 DEBUG rasa_core.actions.forms - FormAction Run -----------before field----------------- [, ] : end 2018-06-05 11:19:28 DEBUG rasa_core.actions.forms - FormAction Run -----------field----------------- : end which source Location ? 2018-06-05 11:19:28 DEBUG rasa_core.processor - Bot utterance 'BotUttered(text: which source Location ?, data: null)' 2018-06-05 11:19:28 DEBUG rasa_core.processor - Action 'action_booking' ended with events '[u'SlotSet(key: destination_location, value: newyork)', u'SlotSet(key: requested_slot, value: source_location)']' 2018-06-05 11:19:28 DEBUG rasa_core.policies.memoization - Current tracker state [{u'intent_int.ride_sharing.cancel': 0.11595299761082925, u'intent_int.general.goodbye': 0.1388611549581425, u'intent_int.general.greeting': 0.07939681815788609, u'intent_inform': 0.058228446434619524, u'prev_action_booking': 1.0, u'intent_int.ride_sharing.book_trip': 0.6075605828385227}, {u'intent_int.ride_sharing.cancel': 0.04572284379891411, u'intent_int.general.greeting': 0.05196333630066613, u'prev_action_listen': 1.0, u'entity_destination_location': 1.0,u'slot_destination_location_0': 1.0, u'intent_int.general.goodbye': 0.03537435392138472, u'intent_inform': 0.7790142380549658, u'intent_int.ride_sharing.book_trip': 0.08792522792406904}, {u'intent_int.ride_sharing.cancel': 0.04572284379891411, u'intent_int.general.greeting': 0.05196333630066613, u'prev_action_booking': 1.0, u'entity_destination_location': 1.0, u'slot_destination_location_0': 1.0, u'intent_int.general.goodbye': 0.03537435392138472, u'intent_inform': 0.7790142380549658, u'intent_int.ride_sharing.book_trip': 0.08792522792406904}] 2018-06-05 11:19:28 DEBUG rasa_core.policies.ensemble - Predicted next action 'action_listen' with prob 1.00. 2018-06-05 11:19:28 DEBUG rasa_core.processor - Action 'action_listen' ended with events '[]' 2018-06-05 11:19:28 DEBUG rasa_core.processor - Current topic: None ```
RAJAT--PALIWAL commented 6 years ago

Test your Entity Recognizer with just NLU, don't add rasa core and you will figure out why it is happening. My guess is NLU model is not able to generalize well.

DhruvMevada commented 6 years ago

Rasa NLU is working well. We tried with different entity like: Person & city. Both have different value like 3 persons and NewYork So, In this scenario its working fine. But, When more then one entity have same value

For Example :- NewJersey( NewJersey could be source_location OR Destination_location)

But, Somehow Rasa NLU could not able to identify what is context of user. Even BOT was asking for source_location then also Rasa NLU stores its value in destination_location. Due to training data.

In our example if source_location is not found in user message, BOT simply ask BOT: which source_location? User will answer : NewJersey

Here, due to this we have to set training data as below

 {
        "text": "NewJersey", 
        "intent": "inform", 
        "entities": [
          {
            "start": 0, 
            "end": 9, 
            "value": "NewJersey", 
            "entity": "destination_location"
          }
        ]
      },
 {
        "text": "NewJersey", 
        "intent": "inform", 
        "entities": [
          {
            "start": 0, 
            "end": 9, 
            "value": "NewJersey", 
            "entity": "source_location"
          }
        ]
      },

Due to this training data, Rasa NLU identifies that NewJersey is destination_location always.

So Please help us to solve this.

akelad commented 6 years ago

You should have a third entity called location for those cases, when it's not clear from the context whether it's source or destination. And then you would need to store this in the according slots in a custom action.

jahid-ict commented 6 years ago

@DhruvMevada did you solved it? If do, please give me some suggestion.

DhruvMevada commented 6 years ago

@jahid-ict I didn't solve that. but I have solve by creating another location slot location and handled in the actions.py file. And also given training data for location slot.

In actions.py I handle it by putting simple condition that if source_location slot is not filled then location slot value will move to source_location slot else it will go to destination_location slot and then reset the location slot after both condition executes.

tmbo commented 6 years ago

I'll close this for now, please let us know if you have any further questions.