# Incorrect recognition of bank account and amount entity

**URL:** <https://forum.rasa.com/t/incorrect-recognition-of-bank-account-and-amount-entity/27202>\
**Category:** Rasa Open Source\
**Created:** [April 8, 2020, 6:59am UTC](https://forum.rasa.com/t/incorrect-recognition-of-bank-account-and-amount-entity/27202 "2020-04-08T06:59:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saugat](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@saugat](https://forum.rasa.com/u/saugat)\
**Post date:** [April 8, 2020, 6:59am UTC](https://forum.rasa.com/t/incorrect-recognition-of-bank-account-and-amount-entity/27202/1 "2020-04-08T06:59:21Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![samscudder](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/samscudder/32/4466_2.png) [@samscudder](https://forum.rasa.com/u/samscudder)\
**Post date:** [April 9, 2020, 12:03pm UTC](https://forum.rasa.com/t/incorrect-recognition-of-bank-account-and-amount-entity/27202/2 "2020-04-09T12:03:09Z")

</div>

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`:

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

```

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

---

<div class="post-metadata">

**Author:** ![saugat](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@saugat](https://forum.rasa.com/u/saugat)\
**Post date:** [April 16, 2020, 7:18pm UTC](https://forum.rasa.com/t/incorrect-recognition-of-bank-account-and-amount-entity/27202/3 "2020-04-16T19:18:30Z")

</div>

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.
