microsoft / ConversationLearner-Samples

Sample bot using the ConversationLearner SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

memoryManager.RememberEntityAsync has bug when dealing with daterange type entity.

gragonraja opened this issue · comments

Do you want to request a feature or report a bug?

Report a bug

What's the current behavior?

The function memoryManager.RememberEntityAsync() will fail when the builtin_datetimev2 entity is a daterange.

I am manipulating a builtin_datetimeV2 entity for my bot. Sometimes I need to make a copy of the current builtin_datetimev2 entity into a new entity created by myself named dateTimeNorm. It is a custom entity.

In the code, I first get the current value of builtin-datetimev2 by
var newDateTime = await memoryManager.EntityValueAsPrebuiltAsync("builtin-datetimev2");

Then I copy the value to dateTimeNorm by the following.
if(newDateTime.length>0){
//
await memoryManager.ForgetEntityAsync("dateTimeNorm");
await memoryManager.RememberEntityAsync("dateTimeNorm", newDateTime);
//await memoryManager.ForgetEntityAsync("companyName");
}

The problem is, when builtin-datetimev2 is a date type (e.g. 3-12-2018), there is not problem. However, if it is a daterange (e.g. past six months), RememberEntityAsync will throw out an error.
Log is as follows.

My Apps
Settings
Mycroft-V2
Tag: MasterLIVE
Status:  Running
Last Updated: 17 hours agoRefresh

Home

Entities
10

Actions
12

Train Dialogs
13

Log Dialogs

Settings

My Apps
Train Dialogs
Train Dialogs are example conversations you want your bot to imitate
Search:

Entity:
Action:
what is mad of today
ConversationLearnerDeveloper
MetricAPI: mad 2018-06-12

Bot
what is mad of yesterday ?
ConversationLearnerDeveloper
MetricAPI: mad 2018-06-11

Bot
what is mad of march 12,2018
ConversationLearnerDeveloper
MetricAPI: mad 2018-03-12

Bot
what is mad last week
ConversationLearnerDeveloper at 12:09:58 AM

Type your message...
Train Dialog
User Input
Entity Memory
Entity Detection
Select text to label it as an entity
​what is
+metric
​mad​ last week​
Pre-Built Entities:
what is mad
last week​

Add alternative input...
RUN_SCORER_ASYNC Failed
Request failed with status code 400
{"data":"Bad Request\n{"FilledEntities[3].Values[0].DisplayText":["The field DisplayText must be a string with a maximum length of 200."]}","status":400,"statusText":"Bad Request","headers":{"date":"Tue, 12 Jun 2018 07:10:02 GMT","content-type":"application/json","content-length":"135"},"config":{"transformRequest":{},"transformResponse":{},"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"headers":{"Accept":"application/json, text/plain, /","Content-Type":"application/json","x-conversationlearner-memory-key":"A-ed08ca4d27e1f1988c26000f7e0eef967b55c2e67853c169b1af84b20063d0a2"},"method":"put","url":"http://localhost:5000/app/51672d83-dc56-46b0-ae43-f3c0a02bbd2b/teach/62550b87-8c74-409d-8fb0-ce62ff752da2/scorer","data":"{\"trainExtractorStep\":{\"textVariations\":[{\"text\":\"what is mad last week","labelEntities":[{"score":0.9784021,"entityId":"3bdee2dd-9d47-4e92-8422-c7dbefb4e110","startCharIndex":8,"endCharIndex":10,"entityText":"mad"},{"score":0,"entityId":"bd4c8838-c86f-4908-a930-171c80e54244","startCharIndex":12,"endCharIndex":20,"entityText":"last week","resolution":{"values":[{"end":"2018-06-11","start":"2018-06-04","timex":"2018-W23","type":"daterange"}]},"builtinType":"builtin.datetimeV2.daterange"}]}]},"extractResponse":{"tokenMetadata":[],"tokenizedText":[],"text":"what is mad last week","predictedEntities":[{"score":0.9784021,"entityId":"3bdee2dd-9d47-4e92-8422-c7dbefb4e110","startCharIndex":8,"endCharIndex":10,"entityText":"mad"},{"score":0,"entityId":"bd4c8838-c86f-4908-a930-171c80e54244","startCharIndex":12,"endCharIndex":20,"entityText":"last week","resolution":{"values":[{"end":"2018-06-11","start":"2018-06-04","timex":"2018-W23","type":"daterange"}]},"builtinType":"builtin.datetimeV2.daterange"}],"metrics":{"predictMetrics":{"contextDialogBlisTime":0.009719371795654297,"luisTime":0.07672429084777832}},"packageId":"2e32e993-3712-42b5-82fb-14fa7489b023","definitions":{"entities":[{"entityId":"893ee862-839e-431e-85b5-8956ebebc0b8","entityName":"companyName","entityType":"LUIS","isMultivalue":true,"isNegatible":true,"isReversable":false,"negativeId":"db93c269-7614-449c-9146-e31f2a7f904c"},{"entityId":"db93c269-7614-449c-9146-e31f2a7f904c","entityName":"~companyName","entityType":"LUIS","isMultivalue":true,"isNegatible":true,"isReversable":false,"positiveId":"893ee862-839e-431e-85b5-8956ebebc0b8"},{"entityId":"adfd39d5-f6d5-401c-b4a5-3848748bbe4b","entityName":"companyNameNorm","entityType":"LOCAL","isMultivalue":true,"isNegatible":false,"isReversable":false},{"entityId":"95dbb076-ce29-413e-9831-51f4dec1c044","entityName":"filter","entityType":"LUIS","isMultivalue":true,"isNegatible":true,"isReversable":false,"negativeId":"e364b1a6-bd24-4352-8143-7aaaca424e0f"},{"entityId":"e364b1a6-bd24-4352-8143-7aaaca424e0f","entityName":"~filter","entityType":"LUIS","isMultivalue":true,"isNegatible":true,"isReversable":false,"positiveId":"95dbb076-ce29-413e-9831-51f4dec1c044"},{"entityId":"688d4dfa-39fb-4c90-a9f8-430f4eccd57f","entityName":"filterNorm","entityType":"LOCAL","isMultivalue":true,"isNegatible":false,"isReversable":false},{"entityId":"3bdee2dd-9d47-4e92-8422-c7dbefb4e110","entityName":"metric","entityType":"LUIS","isMultivalue":true,"isNegatible":true,"isReversable":false,"negativeId":"a6dd6c26-0f35-45d5-a01c-212a5b9c13ca"},{"entityId":"a6dd6c26-0f35-45d5-a01c-212a5b9c13ca","entityName":"~metric","entityType":"LUIS","isMultivalue":true,"isNegatible":true,"isReversable":false,"positiveId":"3bdee2dd-9d47-4e92-8422-c7dbefb4e110"},{"entityId":"f504b7d1-811c-44e0-ada3-8f8c2b9dfd80","entityName":"metricNorm","entityType":"LOCAL","isMultivalue":true,"isNegatible":false,"isReversable":false},{"entityId":"222525e8-6162-4ccf-ab9b-b13eb9bc2260","entityName":"slicer","entityType":"LUIS","isMultivalue":false,"isNegatible":true,"isReversable":false,"negativeId":"2818e3c7-9ce3-4655-b63a-85a7687fb8c7"},{"entityId":"2818e3c7-9ce3-4655-b63a-85a7687fb8c7","entityName":"~slicer","entityType":"LUIS","isMultivalue":false,"isNegatible":true,"isReversable":false,"positiveId":"222525e8-6162-4ccf-ab9b-b13eb9bc2260"},{"entityId":"64c2fd94-8c62-4d7f-9030-5ed6541f2d4e","entityName":"slicerNorm","entityType":"LOCAL","isMultivalue":false,"isNegatible":false,"isReversable":false},{"entityId":"bd4c8838-c86f-4908-a930-171c80e54244","entityName":"builtin-datetimev2","entityType":"datetimeV2","isMultivalue":true,"isNegatible":false,"isReversable":false},{"entityId":"4cf3e432-9da3-47f0-8f51-465b56b0ac24","entityName":"dateTimeNorm","entityType":"LOCAL","isMultivalue":true,"isNegatible":false,"isReversable":false}]}}}"},"request":{}}

What's the expected behavior?

I expect memoryManager.RememberEntityAsync works equally well for both date type and daterange type.

Please tell us about your environment:

Windows Version 1803 OS build 17134.48
node v8.11.1
npm 5.6.0
Chrome Version 66.0.3359.181 (Official Build) (64-bit)

@msft-shahins - Looks like the issue is that more complex datetime resolutions are more than 200 characters

@gragonraja We have confirmed the issue and will be deploy a fix early next week.

To be clear for everyone else. The value of a pre-built date time in the case of last week will look like this:

[
    {
        "userText": "last week",
        "displayText": "2018-06-04 to 2018-06-11",
        "builtinType": "builtin.datetimeV2.daterange",
        "resolution": {
            "values": [
                {
                    "end": "2018-06-11",
                    "start": "2018-06-04",
                    "timex": "2018-W23",
                    "type": "daterange"
                }
            ]
        }
    }
]

It just so happens that it is 218 characters which exceeded the max of 200. In the short term, we will be increasing the limit to 500 (to match max length of other entity field) since this is an expected use case. In longer term we're trying to find alternate solutions for entity passing / storing between actions to increase or remove the limits.

Sometimes I need to make a copy of the current builtin_datetimev2 entity into a new entity created by myself named dateTimeNorm. It is a custom entity.

Also, can you explain more about the reason for wanting to copy a prebuilt entity value so we can better understand if we're providing the correct tools to manage memory? Based on your entity name dateTimeNorm I expect there to be some normalization happening where you inspect the datetime value and then save certain metadata about it as opposed to simply copying it.

Example code:

    const newDateTime = await memoryManager.EntityValueAsPrebuilt("builtin-datetimev2")

    if (newDateTime.length > 0) {
        await memoryManager.ForgetEntity("dateTimeNorm")
        await memoryManager.RememberEntity("dateTimeNorm", newDateTime)
    }
  1. It seems that newDateTime.length > 0 will always be true when there is a datetime detected and in this case you are also setting dateTimeNorm so if there is a date they would always both be set. If you were using it as requiredEntity I think it wouldn't matter

  2. You are setting the dateTimeNorm to the entire entity value which includes all previous datetime in the memory. If dateTimeNorm is single value, then this will always be the same as builtin-datetimeV2. If it is multi-value it would have duplicates like [ { "userText": "last week"... }, [{ "userText": "last week"... }, , { "userText": "tomorrow"... }], [{ "userText": "last week"... }, , { "userText": "tomorrow"... }, { "userText": "next week"... }], ...] which seems odd.

We have deployed the fix to increase limit of displayText to match userText so they are both 500.