Entities resolved incorrectly


#1

Using Jovo v4.0.0.

Entities are resolving incorrectly, or am I missing something?

model json:

{
  "invocation": "my app",
  "version": "4.0",
  "intents": {
    "GetForexRate": {
      "phrases": [
        "exchange rates",
        "conversion rates",
        "forex",
        "convert from {ccyFrom} to {ccyTo}",
        "what is the exchange rate from {ccyFrom} to {ccyTo}",
        "exchange rate for {ccyFrom} to {ccyTo}",
        "what is the rate from {ccyFrom} to {ccyTo}",
        "convert {ccyFrom} to {ccyTo}",
        "how many {ccyFrom} does one {ccyTo} cost",
        "how many {ccyTo} is one {ccyFrom}",
        "how many {ccyTo} are one {ccyFrom}"
      ],
      "entities": {
        "ccyFrom": {
          "type": "currency"
        },
        "ccyTo": {
          "type": "currency"
        }
      }
    }
  },
  "entityTypes": {
    "currency": {
      "values": [
        "USD",
        "INR",
        "GBP",
        "AUD"
      ]
    }
  }
}

When I type ‘USD to INR’, I expect to receive ccyFrom = USD and ccyTo = INR. But I’m getting different values, like below:

this.$input.nlu.entities = {ccyTo: {id: 'INR', ....}}    // only one entry

and

this.$input.nlu.raw.entities = [     // 2 entries, but alias is incorrect
    {alias: 'ccyTo_0', entity: 'ccyTo', option: 'USD', ...},
    {alias: 'ccyTo_1', entity: 'ccyTo', option: 'INR', ...}
]

Debug view:



#2

Thank you. We’ll investigate this. cc @Max


#3

Hey there, it looks like an issue of nlpjs based on the information you posted.

I will take a look and get back to you.


#4

@Max Were you able to spot the issue? My observation is only the last slot/entity is resolving.

Because of this issue, slot filling went into an infinite loop. Any help is much appreciated. Thanks


#5

Also, when I enter just one value (ex: USD), it is always resolving for ccyTo, but never to ccyFrom. How to do slot filling properly?

I mean, I need values for slots: ccyFrom and ccyTo.

Scenario #1: User says USD to INR --> system should resolve USD to ccyFrom and INR to ccyTo
Scenario #2: System asks the user for ccyFrom first and then ccyTo. When the system asks for ccyFrom, I’m expecting Jovo to resolve the user said value to ccyFrom instead of ccyTo.

How to achieve this? Thanks


#6

Hello there,

I’ve had time to test this issue and had the same problem. I’ve implemented some improvements for the model conversion but the issue persists. The problem is how Nlpjs handles entities.

For every entity, a rule is added. In your case, you have two rules. When the incoming text looks like that: “USD to EUR” Nlpjs will match USD to ccyFrom as well as ccyTo. The same happens with EUR in that case.

This happens due to both rules being applied after another while disregarding if the previous rule already used some of the text, therefore the rules will be checked for the whole text twice. Now, CurrencyType is used in both entities and therefore it can match both.

I hope this is somewhat understandable.

tl;dr: Nlpjs has some issues with processing the same entity type multiple times due to not knowing the previously matches entities for that text


#7

@Max thanks for this detailed explanation of what’s happening. Is there any workaround to have multiple entities of the same type? Can you please share if you have any plans to fix it? Please let me know if I can be of any help. Thanks


#8

The alias issue was fixed and will be released today: https://github.com/jovotech/jovo-framework/pull/1158

Unfortunately, this is a limitation of NLPjs, not Jovo. The only workaround would be to switch to a different NLU service. We’ve had some good success with Snips NLU: https://www.jovo.tech/marketplace/nlu-snips

You can also change the NLU used by the Debugger: https://www.jovo.tech/docs/debugger#nlu


#9

Thanks @jan @Max for the suggestions. I’ll try as suggested. Thanks