python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

Pass Entity into Message Request

Open jhoelzl opened this issue 8 years ago • 5 comments

Hello, i am using Pyhton 3.5.2 and the latest version 1.4.0 of this python-sdk.

For a use case, the user should choose a contact name from a contact list (which is stored as an entity in IBM Watson Assistant). So, possibly, there are multiple contact names matching the user input e.g. when only the firstname is given by the user. For example "michael" gives back 4 suitable contact names. Therefore, i present the 4 names (with fullname) and the user should choose one of them.

Therefore i want to use the possibility to pass the already filtered contact entity values (4 contacts) into the second bot request, as stated in the documentation https://www.ibm.com/watson/developercloud/assistant/api/v1/python.html?python#message. Beside the context, it is also possible to pass the entities:

Entities to use when evaluating the message. Include entities from the previous response to continue using those entities rather than detecting entities in the new input.

I did that with this python example:

# IBM API Text Request
response = ibm_conversation.message(
   workspace_id=ibm_workspace,
   input={'text': message.lower()},
   context=response["context"],  # context from the previous request
   entities=response["context"]["entities"]  #recognized entities from the previous request
)

However, the result of the second request is not as expected. There are still 4 entity values detected (the same that i passed into the message request) and all of them were matched to the second user input text which is not correct.

Example: First user input:

"i want to call michael"

First answer:

Okay, there are 4 contact matching: "Michael W, Michael Z, Michael Y, Michael Z. Please choose one!".

Second user input:

"Okay, i choose Z".

Second bot answer:

Okay, there are 4 contact matching: "Michael W, Michael Z, Michael Y, Michael Z. Please choose one!"

It is because in the response, i see that the string "Z" is extracted as the four entities.

For me it would be logical to only get the "Michael Z" as extracted entity for the user input message "Okay, i choose Z".

The main goal of this, is that there are also other contact names with the lastname "Z", so when i do not pass the already filtered entity from the first bot response into the second bot request, it gives me back all contacts matching "Z" and this is not what i want.

Any suggestions? Thanks! Josef

jhoelzl avatar Jun 14 '18 10:06 jhoelzl

Hmm, i think that the specification from https://www.ibm.com/watson/developercloud/assistant/api/v1/python.html?python#message

Entities to use when evaluating the message. Include entities from the previous response to continue using those entities rather than detecting entities in the new input.

means that exactly these given entities are used for the request. I supposed that IBM Watson uses these given entities and in addition filters them based on the user input message, which is apparently not the case.

jhoelzl avatar Jun 14 '18 11:06 jhoelzl

@jhoelzl .. I don't quite understand your use case, could you be a little more specific? It seems from your description you want the system to be able to match Z to Michael Z? This is beyond the abilities of our current entity detection algorithm as there is too great a difference between Michael Z and Z..

doconnor78 avatar Jun 18 '18 18:06 doconnor78

Hi @doconnor78,

the thing is, that i have a contact list as an entity with the fullname (="firstname + lastname") as entity value name and multiple synonymns (only firstname, only lastname, "lastname + firstname").

So, i when i say "michael" i want to get all contact entity values that include "michael". Since i included the firstnames as synonyms, from my opition, the API should return all matching entity values not only the first matching one.

jhoelzl avatar Jun 18 '18 18:06 jhoelzl

The system is behaving as I would expect, it is stateless so it knows nothing about the previously returned entity. As a test I mimicked up an address book entity: image

I have 3 names in there.. But there is over lap between 2 of them (2 have same first name, two have same last name) image

This is the expected behavior of the system. You will need to build additional logic into your app and your dialog to understand that the previous name was 'dan' and the current name is "o'sullivan" and piece the two together. As far as I can tell from your description and what I've show above the system is behaving as designed. Please reopen if you see an apparent bug.

doconnor78 avatar Jun 18 '18 22:06 doconnor78

@doconnor78 you are absolutely right, the API is working as excepted. I mixed up some bugs with a Google dialogflow agent, where i have the described problem with the entity extraction.

jhoelzl avatar Jun 19 '18 07:06 jhoelzl