10. NLU

The definition of the pattern element to perform intent recognition processing.
If nlu is defined as a child element of pattern, it is evaluated for matching the intent of the intent recognition.
In the dialog control, the rule base intention interpretation is carried out according to the description of the scenario, and the response is returned according to the result of the evaluation by pattern matching. If there is no matching pattern, it performs dialog control using the intent result of advanced intent interpretation.
This is to give priority to what the scenario developer describes rather than the result of intent recognition.
As an exception, if there is a category in the pattern that only describes wildcards, the wildcard-only matching process will be performed after both scenario description matching and intent recognition matching have failed to match.
Even if you define nlu for a child element, the contents of the pattern element do the usual pattern evaluation.
For nlu element attributes, see nlu .

10.1. Basic usage

The following example shows the return of intent and slot information in the following format from the intent recognition.

{
    "intents": [
        {"intent": "transportation", "score": 0.9 },
        {"intent": "aroundsearch", "score": 0.8 }
    ],
    "slots": [
        {"slot": "departure", "entity": "Tokyo", "score": 0.85, "startOffset": 3, "endOffset": 5 },
        {"slot": "arrival", "entity": "Kyoto", "score": 0.86, "startOffset": 8, "endOffset": 10 },
        {"slot": "departure_time", "entity": "2018/11/1 19:00", "score": 0.87, "startOffset": 12, "endOffset": 14 },
        {"slot": "arrival_time", "entity": "2018/11/1 11:00", "score": 0.88, "startOffset": 13, "endOffset": 18 }
    ]
}

10.1.1. Intent Matching

Describes nlu as a child element of pattern in AIML.
In the example below, the intent returned from the intent recognition is ‘transportation’, it will match and return a response.
<category>
    <pattern>
        <nlu intent="transportation" />
    </pattern>
    <template>
        Is it transfer information?
    </template>
</category>
Input: I want to go from Tokyo to Kyoto.
Output: Is it transfer information?

10.1.2. Pattern that is a candidate intent but does not match

In the following example, the intent for intent recognition is ‘aroundsearch’.
‘aroundsearch’ is a candidate intent, but it is not a maximum likelihood candidate, so it does not match.
<category>
    <pattern>
        <nlu intent="aroundsearch" />
    </pattern>
    <template>
        Around search?
    </template>
</category>
Input: I want to go from Tokyo to Kyoto.
Output: NO_MATCH

10.1.3. Matching when it is not a maximum likelihood candidate

Set the attribute maxLikelihood to false if you want to match the intent including ‘aroundsearch’ even if ‘aroundsearch’ is not a maximum likelihood candidate.
If maxLikelihood is not specified, the behavior is the same as specifying true .
<category>
    <pattern>
        <nlu intent="aroundsearch" maxLikelihood="false" />
    </pattern>
    <template>
        Around search?
    </template>
</category>
Input: I want to go from Tokyo to Kyoto.
Output: Around search?

10.1.4. Match with score specification

Describes the match condition by the score value of the intent.
Five types of attributes, scoreGt, scoreGe, score, scoreLe, and scoreLt, can now be specified, and the settings are as follows.
Also, if this attribute is specified, maxLikelihood will be treated as false for comparison matching by confidence.
Parameter Name Meaning Description
scoreGt > Matches if the confidence level of the target intent is greater than the specified value.
scoreGe >= Matches if the confidence level of the target intent is greater than or equal to the specified value.
score = Matches if the confidence level of the target intent is equal to the specified value.
scoreLe <= Matches if the confidence level of the target intent is less than or equal to the specified value.
scoreLt < Matches if the confidence level of the target intent is less than the specified value.

The operation when scoreXx is specified is the following matching.

<nlu intent="transportation" scoreGt="0.9"/>  Do not match transportation.
<nlu intent="transportation" scoreGe="0.9"/>  Matching transportation.
<nlu intent="transportation" score="0.9"/>    Matching transportation.
<nlu intent="aroundsearch" scoreLe="0.8"/>  Matching aroundsearch.
<nlu intent="aroundsearch" scoreLt="0.8"/>  Do not match aroundsearch.
As shown in the following example, it is possible to describe multiple conditions depending on the result of Intent Recognition, but the order of category in the AIML file is the first to be applied.
When multiple AIML files are used, the AIML expansion process is performed in ascending order by directory name and file name, so the order must be kept in mind.
(If a subdirectory is used, the files in the upper directory are processed before moving to the file processing under the subdirectory.)
<category>
    <pattern><nlu intent="transportation" scoreGe="0.8"/></pattern>
    <template> Is it transfer information?</template>
</category>

<category>
    <pattern><nlu intent="aroundsearch" scoreGe="0.8"/></pattern>
    <template> Around search?</template>
</category>

10.1.5. Intent matches and wildcards

The following is an example of calling a chat subagent if it does not match the rule base or intent recognition result. If there is a category with only wildcards as pattern, it will match after matching both the scenario description and the intent recognition.

<aiml>
    <category>
        <pattern>Hello </pattern>
        <template>Hello </template>
    </category>

    <category>
        <pattern><nlu intent="aroundsearch" /></pattern>
        <template>
            Around search.
        </template>
    </category>

    <category>
        <pattern>
            *
        </pattern>
        <template>
            <sraix service="chatting"><get var="__USER_UTTERANCE__" /></sraix>
        </template>
    </category>
</aiml>
Input: Hello
Output: Hello
Input: Convenience stores around here
Output: Around search.
Input: chatting
Output: It’s the result of a chatting.

10.2. Getting NLU Data

The NLU data is expanded into the variable __SYSTEM_NLUDATA__ . Here is an example of using a JSON element to get data for an example of a intent recognition result .

<category>
    <pattern>
        <nlu intent="transportation" />
    </pattern>
    <template>
        <think>
                <set var="slot"><json var="__SYSTEM_NLUDATA__.slots"><index>1</index></json></set>
                <set var="entity"><json var="slot.entity" /></set>
                <set var="score"><json var="slot.score" /></set>
        </think>
        <get var="entity"/> has a score of <get var="score" />.
    </template>
</category>
Input: I want to go from Tokyo to Kyoto.
Output: Tokyo has a score of 0.85.

See also: nluJSON element

10.3. Getting NLU Intent

Use nluintent to get the contents of an intent with template. The NLU processing result explains how to get intent information on the assumption that the following result is obtained.

{
    "intents": [
        {"intent": "restaurantsearch", "score": 0.9 },
        {"intent": "aroundsearch", "score": 0.4 }
    ],
    "slots": [
        {"slot": "genre", "entity": "Italian", "score": 0.95, "startOffset": 0, "endOffset": 5 },
        {"slot": "genre", "entity": "French", "score": 0.86, "startOffset": 7, "endOffset": 10 },
        {"slot": "genre", "entity": "Chinese", "score": 0.75, "startOffset": 12, "endOffset": 14 }
    ]
}

This example gets the intent information processed by the NLU. The map is supposed to be defined to count up values. Keep the intent count in the intentCount and get the intent name and score for each slot until variable count equals the intentCount.

<category>
    <pattern>
        <nlu intent="restaurantsearch"/>
    </pattern>
    <template>
        <think>
          <set var="count">0</set>
          <set var="intentCount"><nluintent name="*" item="count" /></set>
        </think>
        <condition>
            <li var="count"><value><get var="intentCount" /></value></li>
            <li>
                intent:<nluintent name="*" item="intent"><index><get var="count" /></index></nluintent>
                score:<nluintent name="*" item="score"><index><get var="count" /></index></nluintent>
                <think>
                    <set var="count"><map name="upcount"><get var="count" /></map></set>
                </think>
                <loop/>
            </li>
        </condition>
    </template>
</category>
Input: Look for Italian, French or Chinese.
Output: intent:restaurantsearch score:0.9 intent:aroundsearch score:0.4

See also: nluintent

10.4. Getting NLU Slots

Use nluslot to get the contents of the slot resulting from NLU processing with template. The NLU processing result explains how to get slot information on the assumption that the following result is obtained.

{
    "intents": [
        {"intent": "restaurantsearch", "score": 0.9 },
        {"intent": "aroundsearch", "score": 0.4 }
    ],
    "slots": [
        {"slot": "genre", "entity": "Italian", "score": 0.95, "startOffset": 0, "endOffset": 5 },
        {"slot": "genre", "entity": "French", "score": 0.86, "startOffset": 7, "endOffset": 10 },
        {"slot": "genre", "entity": "Chinese", "score": 0.75, "startOffset": 12, "endOffset": 14 }
    ]
}

This example gets the slot information processed by the NLU. The map is supposed to be defined to count up values. Keep the slot count in the slotCount and get the slot name, entity and score for each slot until variable count equals the slotCount.

<category>
    <pattern>
        <nlu intent="restaurantsearch" />
    </pattern>
    <template>
        <think>
          <set var="count">0</set>
          <set var="slotCount"><nluslot name="*" item="count" /></set>
        </think>
        <condition>
            <li var="count"><value><get var="slotCount" /></value></li>
            <li>
                slot:<nluslot name="*" item="slot"><index><get var="count" /></index></nluslot>
                entity:<nluslot name="*" item="entity"><index><get var="count" /></index></nluslot>
                score:<nluslot name="*" item="score"><index><get var="count" /></index></nluslot>
                <think>
                    <set var="count"><map name="upcount"><get var="count" /></map></set>
                </think>
                <loop/>
            </li>
        </condition>
    </template>
</category>
Input: Look for Italian, French or Chinese.
Output: slot:genre entity:Italian score:0.95 slot:genre entity:French score:0.86 slot:genre entity:Chinese score:0.75

See also: nluslot