Using same entity/slot for different intents - works only the first time

Hi, I am working on a FAQ type of a bot. I have 3 applications for my domain and there are more than 15 FAQs where the questions are same across the three applications, but the answers(utterances only) will be different per application. So, I defined Entity:“app”, Slot:“app”, type :text. I have written a custom action as below for each Q:

class Actionnewconsumer(Action):

def name(self):
    return "action_newconsumer_byapp"

def run(self, dispatcher, tracker, domain):
    appl = tracker.get_slot('appl')

    if appl == 'A':
        dispatcher.utter_template('utter_newconsumer_A', tracker)
    elif appl == 'B':
        dispatcher.utter_template('utter_newconsumer_B', tracker)
    else:
        dispatcher.utter_template('utter_cantunderstand', tracker)

    return []   

Also, defined a custom action to reset slot. class ActionResetSlotapp(Action):

def name(self):
    return "action_reset_slot"

def run(self, dispatcher, tracker, domain):
    return [SlotSet("appl", None)]      

My stories are as below:(this is just for one Q(new consumer). There are stories like this for all 15 Qs for the same A and B applications)

NewConsumer story1

  • New_Consumer
    • utter_ask_newconsumer_byapp
  • enter_data{“appl”: B"}
    • action_newconsumer_byapp
    • action_reset_slot
    • utter_did_that_help

NewConsumer story2

  • New_Consumer{“appl”: “A”}
    • action_newconsumer_byapp
    • action_reset_slot
    • utter_did_that_help

So, basically, if a user specifies the appl in the Q itself, it should directly give the answer- which works perfect. Now, if the user doesnt specify the application, it asks the application- which is also as expected. But after the appl is specified, for the first time it answers correctly, the second time, it takes the correct entity value(A or B), but identifies intent as “enter_data” and hence replies for any of the 15 Qs where this slot is being used.

My config is as below:

language: en_core_web_sm pipeline: supervised_embeddings policies:

  • name: AugmentedMemoizationPolicy max_history: 5
  • name: KerasPolicy max_history: 5
  • name: MappingPolicy
  • name: FallbackPolicy nlu_threshold: 0.3 core_threshold: 0.3 fallback_action_name: action_default_fallback

I also tried increasing the augmentation factor upto 250 and changing to Memoization policy as well, but this part fails to work correctly. Sorry for the super-long Q.

Thanks!

Also, each Q is a separate intent. So, around 15 intents that use the same entity.

Any idea @JiteshGaikwad @akelad @chatbot_Ra?

hey @vvasani, In your Actionnewconsumer(Action) can you replace

appl = tracker.get_slot(‘appl’)

with

appl = next(tracker.get_latest_entity_values(“appl”), None)

What I am trying to say here is if user specifies the appl in the question itself it will be captured in the entities by NLU and then you extract the user specified entity in the action using the above code. So here it will only capture the appl only if the user has specified and if user has not specified we don’t need to use the slot.

Let me know if this helps :slight_smile:

1 Like

@JiteshGaikwad Thank you so much for your time. But I will always need to appl to be specified. So, what am trying to do is, if the user specifies the appl, utterance is for that appl directly, else, the bot will ask for that appl, which is captured by the “enter_data” intent. The issue is that the slot(appl) is being captured correctly always, the intent is not correct,since it picks up the intent as “enter_data” which is being used in multiple stories, it randomly picks any intent after that. I have specified the max_history as 5, but still it picks up incorrect intents, since the last intent it picks up is “enter_data”.

So, say I have two actual intents: 1)New consumer 2)Email id

I have two actions as specified above, for each for these and they both use “appl” entity and slot. My stories are as below:

NewConsumer story1

  • New_Consumer
    • utter_ask_newconsumer_byapp
  • enter_data{“appl”: B"}
    • action_newconsumer_byapp
    • action_reset_slot
    • utter_did_that_help

NewConsumer story2

  • New_Consumer{“appl”: “A”}
    • action_newconsumer_byapp
    • action_reset_slot
    • utter_did_that_help

Email story1

  • Email
    • utter_ask_email_byapp
  • enter_data{“appl”: B"}
    • action_email_byapp
    • action_reset_slot
    • utter_did_that_help

Email story2

  • Email{“appl”: “A”}
    • action_email_byapp
    • action_reset_slot
    • utter_did_that_help

So, the first time I ask about new consumer, it asks me for what appl, I say appA, it gives me the correct answer.

The next time, I ask about email, it asks what appl, I say appl B, it gives me the utterance for Newconsumer for appl B. So, my guess is the slots are being reset correctly, just the intent being recognized it enter_data and it is not following the stories. I have multiple such intents that use the same slot. Am I making sense? Sorry it is a little confusing.
Thanks!

@akelad, @erohmensing any ideas?

Hello Guyz i am having similar issue i am using same entity for different intends . its actually not recognizing that particular intend please help

welcome message status_of_order

  • get_started
    • utter_welcome_message
  • quickreply{“quickreply_value”:“status_of_my_order”}
    • slot{“quickreply_value”:“status_of_my_order”}
    • utter_business_email
  • email{“business_email”: “ppreetham0@gmail.com”}

welcome message Order_placed_tommorrow

  • get_started
    • utter_welcome_message
  • quickreply{“quickreply_value”:“Order_placed_tommorrow”}
    • slot{“quickreply_value”:“whether order placed for tomorrow”}
    • utter_business_email
  • email{“business_email”: “ppreetham0@gmail.com”}

welcome message today’s Lunchbox_details

  • get_started
    • utter_welcome_message
  • quickreply{“quickreply_value”:“todays_Lunchbox_details”}
    • slot{“quickreply_value”:“Want to know todays lunchbox details”}
    • utter_business_email
  • email{“business_email”: “ppreetham0@gmail.com”}

welcome message cancel_order_for_next_friday

  • get_started
    • utter_welcome_message
  • quickreply{“quickreply_value”:“cancel_order_for_next_friday”}
    • slot{“quickreply_value”:“cancel your order for Next Friday”}
    • utter_business_email
  • email{“business_email”: “ppreetham0@gmail.com”}

my stories.md

welcome message lunchpacks_available

  • get_started
    • utter_welcome_message
  • quickreply{“quickreply_value”:“lunchpacks_available”}
    • slot{“quickreply_value”:“Want to know about lunchpacks available”}
    • utter_business_email
  • email{“business_email”: “ppreetham0@gmail.com”}

My action file

class ActionStatusOfMyOrder(Action): “”“Business Email Extractions”""

def name(self):
    return "action_status_of_my_order"

def run(self,dispatcher,tracker,domain):
    value=tracker.get_slot('business_email')
    if re.match(r"[a-zA-Z0-9_.+-]+@[a-zA-Z]+\.[^@]+",str(value)):
        print("inside if")
        print(value)
        # entity was picked up, validate slot
        return(dispatcher.utter_message("Valid_email_statusOfOrder"))
    else:
        # no entity was picked up, we want to ask again
        print("inside else")
        dispatcher.utter_message(template="utter_no_email")
        return [UserUtteranceReverted()]

class ActionOrderPlacedTommorrow(Action): “”“Call order placed tommorrow api “””

def name(self):
    return "action_Order_placed_tommorrow"

def run(self,dispatcher,tracker,domain):
    value=tracker.get_slot('business_email')
    if re.match(r"[a-zA-Z0-9_.+-]+@[a-zA-Z]+\.[^@]+",str(value)):
        print("inside if")
        print(value)
        # entity was picked up, validate slot
        return(dispatcher.utter_message("Valid_email_Order_placed_tommorrow"))
    else:
        # no entity was picked up, we want to ask again
        print("inside else")
        dispatcher.utter_message(template="utter_no_email")
        return [UserUtteranceReverted()]

class ActionCancelOrderForNextFriday(Action): “”“Call order cancel_order_for_next_friday api “””

def name(self):
    return "action_cancel_order_for_next_friday"

def run(self,dispatcher,tracker,domain):
    value=tracker.get_slot('business_email')
    if re.match(r"[a-zA-Z0-9_.+-]+@[a-zA-Z]+\.[^@]+",str(value)):
        print("inside if")
        print(value)
        # entity was picked up, validate slot
        return(dispatcher.utter_message("Valid_email_cancel_order_for_next_friday"))
    else:
        # no entity was picked up, we want to ask again
        print("inside else")
        dispatcher.utter_message(template="utter_no_email")
        return [UserUtteranceReverted()]

class ActionLunchPacksAvailable(Action): “”“Call order lunchpacks_available api “””

def name(self):
    return "action_lunchpacks_available"

def run(self,dispatcher,tracker,domain):
    value=tracker.get_slot('business_email')
    if re.match(r"[a-zA-Z0-9_.+-]+@[a-zA-Z]+\.[^@]+",str(value)):
        print("inside if")
        print(value)
        # entity was picked up, validate slot
        return(dispatcher.utter_message("Valid_email_lunchpacks_available"))
    else:
        # no entity was picked up, we want to ask again
        print("inside else")
        dispatcher.utter_message(template="utter_no_email")
        return [UserUtteranceReverted()]

class ActionTodaysLunchBoxDetails(Action): “”“Call order lunchpacks_available api “””

def name(self):
    return "action_todays_Lunchbox_details"

def run(self,dispatcher,tracker,domain):
    value=tracker.get_slot('business_email')
    if re.match(r"[a-zA-Z0-9_.+-]+@[a-zA-Z]+\.[^@]+",str(value)):
        print("inside if")
        print(value)
        # entity was picked up, validate slot
        return(dispatcher.utter_message("Valid_email_todays_Lunchbox_details"))
    else:
        # no entity was picked up, we want to ask again
        print("inside else")
        dispatcher.utter_message(template="utter_no_email")
        return [UserUtteranceReverted()]

when the user clicks on status of order it is asking email after that its not going to actions status of order its going for some other actions. looks like its not identifying intends kindly help

Have you guys found any solution to this problem?