totoro
totoro

Reputation: 195

Using Entity Type for Profile Variable in Watson Dialog

I noticed that we can use Watson EntityType to extract time reference from user input, e.g.:

<folder label="Invite Time">
                <output id="output_invite_time">
                    <prompt>
                        <item>What time is your meeting?</item>
                    </prompt>
                    <getUserInput>
                        <input>
                            <grammar>
                                <item>$ (DATE_TIME_RANGE)={var-invite_time}</item>
                            </grammar>
                            <action varName="var-invite_time" operator="SET_TO">{var-invite_time.value:FROM_TIME}</action>
                            <goto ref="output_invite_date"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid time to continue.</item>
                            </prompt>
                            <goto ref="output_invite_time"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>

I'm trying to figure out how to use other (supported?) EntityTypes like Generic, Location, Amount, etc. But the result is sometimes unexpected. For example "nice house in Denver, Colorado" for Location entity results in "nice"; or specifying "yesterday" for date results in incorrect date.

My simplified dialog file as follow:

<?xml version="1.0" encoding="UTF-8"?>
<dialog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="WatsonDialogDocument_1.0.xsd">
    <flow>
        <folder label="Main" id="Main">
            <output id="start">
                <prompt selectionType="RANDOM">
                    <item>DIALOG START - asking for user input</item>
                </prompt>
                <goto ref="processUserInput_start"/>
            </output>
            <getUserInput id="processUserInput_start">
                <search ref="library_supported-intents"/>
                <default>
                    <output>
                        <prompt selectionType="RANDOM">
                            <item>I am sorry, I did not understand your intents. Please choose intent1.</item>
                        </prompt>
                    </output>
                </default>
            </getUserInput>
        </folder>
        <folder label="Library" id="Library">
            <folder label="Main Input" id="library_supported-intents">
                <input>
                    <grammar>
                        <item>intent1</item>
                    </grammar>
                    <output>
                        <prompt selectionType="RANDOM">
                            <item>OK. Executing intent 1</item>
                        </prompt>
                        <goto ref="intent1-detail-generic"/>
                    </output>
                </input>
            </folder>
            <folder label="Intent 1 Input Generic" id="library_intent1-generic">
                <output id="intent1-detail-generic">
                    <prompt>
                        <item>Please specify generic</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (ZIPCODE)={var-param_generic}</item>
                            </grammar>
                            <action varName="var-param_generic" operator="SET_TO">{var-param_generic.value:main}</action>
                            <goto ref="intent1-detail-location"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid generic to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-generic"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
            <folder label="Intent 1 Input Location" id="library_intent1-location">
                <output id="intent1-detail-location">
                    <prompt>
                        <item>Please specify Location</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (LOCATION)={var-param_location}</item>
                            </grammar>
                            <action varName="var-param_location" operator="SET_TO">{var-param_location.source}</action>
                            <goto ref="intent1-detail-amount"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid location to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-location"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
            <folder label="Intent 1 Input Location" id="library_intent1-amount">
                <output id="intent1-detail-amount">
                    <prompt>
                        <item>Please specify Amount</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (AMOUNT)={var-param_amount}</item>
                            </grammar>
                            <action varName="var-param_amount" operator="SET_TO">{var-param_amount.value:main}</action>
                            <goto ref="intent1-detail-time"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid amount to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-amount"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
            <folder label="Intent 1 Input Time" id="library_intent1-time">
                <output id="intent1-detail-time">
                    <prompt>
                        <item>Please specify time</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (DATE_TIME_RANGE)={var-param_time}</item>
                            </grammar>
                            <action varName="var-param_time" operator="SET_TO">{var-param_time.value:FROM_TIME}</action>
                            <goto ref="intent1-detail-date"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid time to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-time"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
            <folder label="Intent 1 Input Date" id="library_intent1-date">
                <output id="intent1-detail-date">
                    <prompt>
                        <item>Please specify date</item>
                    </prompt>
                    <getUserInput>
                        <search ref="library_supported-intents"/>
                        <input>
                            <grammar>
                                <item>$ (DATE_TIME_RANGE)={var-param_date}</item>
                            </grammar>
                            <action varName="var-param_date" operator="SET_TO">{var-param_date.value:FROM_DATE}</action>
                            <output>
                                <prompt>
                                    <item>You've specified {var-param_time} on {var-param_date}.</item>
                                </prompt>
                            </output>
                            <goto ref="processUserInput_start"/>
                        </input>
                        <output>
                            <prompt>
                                <item>I'll need a valid date to continue.</item>
                            </prompt>
                            <goto ref="intent1-detail-date"/>
                        </output>
                    </getUserInput>
                </output>
            </folder>
        </folder>
        <folder label="Concepts" id="Concepts"></folder>
    </flow>
    <entities>
        <entity name="ZIPCODE" entityType="GENERIC">
            <value name="10024" value="10024"/>
            <value name="07928" value="07928"/>
            <value name="95118" value="95118"/>
            <value name="95120" value="95120"/>
            <value name="uszipcode" value="!^[0-9]{5}$"/>
            <entityRules></entityRules>
        </entity>
    </entities>
    <variables>
        <var_folder name="Home">
            <var name="IntentClass" type="TEXT"/>
            <var name="Class1" type="TEXT"/>
            <var name="Class1_Confidence" type="NUMBER" initValue="0" description="Confidence score for Class1 from NL classifier"/>
            <var name="var-param_date" type="TEXT" description="Date object"/>
            <var name="var-param_time" type="TEXT" description="Time object"/>
            <var name="var-param_generic" type="TEXT" description="Generic Object"/>
            <var name="var-param_location" type="TEXT" description="Location Object"/>
            <var name="var-param_amount" type="TEXT" description="Amount Object"/>
        </var_folder>
    </variables>
</dialog>

I'm not sure if I use it the right way given the sample tutorial only mentioned {ProfVar.value:main} or {ProfVar.value:name}. I could not find FROM_TIME and FROM_DATE for DATE_TIME_RANGE in the official documentation.

What entity types are supported and how can I properly extract entity specific info in Watson Dialog?

Upvotes: 1

Views: 423

Answers (1)

Simon O&#39;Doherty
Simon O&#39;Doherty

Reputation: 9359

I'm trying to figure out how to use other (supported?) EntityTypes like Generic, Location, Amount, etc. But the result is sometimes unexpected. For example "nice house in Denver, Colorado" for Location entity results in "nice"; or specifying "yesterday" for date results in incorrect date.

"Nice" is the city in France. So it gave the correct response.

The issue is that Dialogs entity extraction is very basic. From your sample:

$ (LOCATION)={var-param_location}

This will find the first entity and stop looking. To demonstrate the limitation, lets say you want to get three possible locations within a users response.

$ (LOCATION)={var-param_location}
$ (LOCATION)={var-param_location} (LOCATION)={var-param_location2}
$ (LOCATION)={var-param_location} * (LOCATION)={var-param_location2}
$ (LOCATION)={var-param_location} (LOCATION)={var-param_location2} (LOCATION)={var-param_location3}
$ (LOCATION)={var-param_location} * (LOCATION)={var-param_location2} (LOCATION)={var-param_location3}
$ (LOCATION)={var-param_location} * (LOCATION)={var-param_location2 * (LOCATION)={var-param_location3}
$ (LOCATION)={var-param_location} (LOCATION)={var-param_location2 * (LOCATION)={var-param_location3}

As you can see, it will start getting messy real fast. It is really only meant for where you expect one entity or an explicit amount of entities being returned.

If you want to get a more accurate entity/keyword extraction, then send it to something like AlchemyAPI first. Have the API return the keyword/entities, then work with them.

Upvotes: 0

Related Questions