Intent matching

Your project can have many intents. When the user says anything, Alan matches the user’s utterance to the most appropriate intent in the voice script. To do this, Alan evaluates every intent separately and assigns different weights, or match scores, to intents.

Match score values range from 1.0 — the most accurate match, to 0.0 — no match. Once all intents are scored, Alan selects the highest scoring intent as the best match. If all intents are scored 0, no intent is matched and Alan plays an error message.

In the example below, if the user asks: What is the weather?, the first intent will be selected as the best match. The second intent will not be matched since it contains more words than the user’s utterance. And vice versa, if the user asks: What is the weather today?, the second intent will have a higher score since it is the most accurate match.

Voice script
intent('What is the weather?', p => {
    p.play('The weather is the day-to-day state of the atmosphere');
});

intent('What is the weather today?', p => {
    p.play('The weather today is great!')
});

To see match scores, open Alan Studio logs, make sure the Input filter is on and check the score next to the user’s input in the list.

../../_images/score.png

Using p.score

The score assigned to the matched intent is stored in the p.score predefined object. You can use p.score in the voice script to adjust the accuracy of Alan’s answers.

Note

The value stored in p.score is a float data type. Due to floating point numbers nature, they may sometimes lose precision. When using p.score, pick a sensible tolerance so that your voice script can operate as expected.

Consider the following example:

Voice script
intent('What is the weather today?', p => {
    p.play('The weather today is great!')
});

By default, if the user asks: What is today's weather, Alan will interpret this question as a weather request and give an answer, although this phrase does not exactly match the phrase in the pattern of the intent. Let’s assume you want the voice assistant to reply only if the user’s utterance matches the phrase in the pattern precisely. You can use p.score to get the match score and provide different responses depending on the score value:

Voice script
let minScore = 0.99;

intent('What is the weather today?', p => {
    console.log(p.score);
    if (p.score >= minScore) {
        p.play('The weather today is great!');
    } else {
        p.play('Sorry, I cannot help you with that');
    }
});

Here, if the user asks: What is the weather today?, Alan will reply: The weather today is great!. However, if the user changes the question to: What is today's weather?, the match score will be less than the minimal score set in the voice script, and Alan will get back with: Sorry, I cannot help you with that.

See also