Incorrect recognition of bank account and amount entity

I have two slots: receiver_account and receiver_amount used inside a form action and both are of type unfeaturized.

And I have a intent to transfer balance where it normally has the name and the amount to be transferred but not the account number.

##intent: balance_tansfer

  • I need to send some money
  • What do I need to do to send money?
  • I need to send money
  • Can you send money?
  • How can I transfer 50000 to Anjana?
  • How can I send 15000 to Rajitha Sujana?
  • How can I transfer balance to Anil Jayasinghe?
  • I need to send 20000 money

The form action has required_slots : receiver_name, receiver_amount, reciever_account and receiver_branch.

So when the form asks the user to enter the bank_account, it is extracted as receiver_amount and the initial amount gets replaced.

Example scenario: User asks : Please transfer 20000 to John

Here, amount and name is extracted. So the form actions for account and branch.

Bot : Enter the account number User : 123456789

The above value (123456789) is recognized as amount and the initial value of 20000 gets replaced. However, there is a constraint that account number is of 10 digits while amount is <= 7 digits.

Here is the slot_mappings function in actions.py for the form:

def slot_mappings(self):
    # type: () -> Dict[Text: Union[Dict, List[Dict]]]
    """A dictionary to map required slots to
        - an extracted entity
        - intent: value pairs
        - a whole message
        or a list of them, where a first match will be picked"""
    #print('PIN number is '+self.from_text())
    return {
        "receiver_account": [self.from_text()],
        "receiver_name": [
            self.from_entity(entity="receiver_name", intent="transfer_balance"),
            self.from_text()
        ],
        "receiver_amount": [
            self.from_entity(entity="receiver_amount", intent="transfer_balance"),
            self.from_text()
        ],
        "receiver_branch": [self.from_text()],
    }

Any workaround to handle this scenario ?

You could try and use a regular expression, so that an account number doesn’t collide with amount.

In the NLU file, add these lines to only match a number value with 1-7 digits to receiver_ammount:

## regex: receiver_amount
- \d{1,7}

But I think you might have a collision with the branch number, as well.

Thanks @samscudder for your response. I added the lines like you suggested

regex:receiver_amount

  • \d{1,6}

regex:receiver_account

  • \d{1,10}

Still, when the user asks: Transfer 2000 to John, it takes amount as 2000 first. Then asks for account number and when user enters 123456789, the amount is reset to None because I have validated. But the problem is still there.

This is how I try to validate the amount. But since the account number is also taken as amount, it gets reset to None, or else it will override the account number value.

def validate_receiver_amount(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
) -> Dict[Text, Any]:
    """Validate receiver amount."""
    #print("Validating Receiver Amount")
    number = int(value)
    digits = len(str(abs(number)))
    if(digits <= 7):
        print("Amount validated")
        return {"receiver_amount": value}
    else:
        print("Invalid amount")
        return {"receiver_amount": None}

Btw, do I need to add CRFEntityExtractor in the config file as it says in doc. But regex is supported by DIETClassifier as well.

Here is my nlp pipeline in config file.

language: en pipeline:

  • name: SpacyNLP model: “en_core_web_md” case_sensitive: False
  • name: WhitespaceTokenizer
  • name: SpacyEntityExtractor dimensions: [“PERSON”, “LOC”, “ORG”, “PRODUCT”]
  • name: RegexFeaturizer
  • name: LexicalSyntacticFeaturizer
  • name: CountVectorsFeaturizer
  • name: CountVectorsFeaturizer analyzer: “char_wb” min_ngram: 1 max_ngram: 4
  • name: DIETClassifier epochs: 100
  • name: EntitySynonymMapper
  • name: ResponseSelector epochs: 100

Is there anything else to be modified after adding regex ? Because it seems the regex is not working. Any more thoughts will be helpful.