10. NLU¶
nlu
is defined as a child element of pattern, it is evaluated for matching the intent of the intent recognition.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¶
<category>
<pattern>
<nlu intent="transportation" />
</pattern>
<template>
Is it transfer information?
</template>
</category>
10.1.2. Pattern that is a candidate intent but does not match¶
<category>
<pattern>
<nlu intent="aroundsearch" />
</pattern>
<template>
Around search?
</template>
</category>
10.1.3. Matching when it is not a maximum likelihood candidate¶
maxLikelihood
to false
if you want to match the intent including ‘aroundsearch’ even if ‘aroundsearch’ is not a maximum likelihood candidate.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>
10.1.4. Match with score specification¶
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.
<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>
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>
See also: nlu、 JSON 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>
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>
See also: nluslot