How to have LuisRecognizer with a separate model for each language

430 views Asked by At

I want to create a multilanguage bot and I´m using LUIS in order to process natural language, but I want to know how can I create two models in the same bot, one for each language.

I know that it is possible because od the documentation:

if you’re using a system like LUIS to perform natural language processing you can configure your LuisRecognizer with a separate model for each language your bot supports and the SDK will automatically select the model matching the users preferred locale.

How can I achieve this? I tried this:

// Configure bots default locale and locale folder path.
bot.set('localizerSettings', {
    botLocalePath: "./locale", 
    defaultLocale: "es" 
});

// Create LUIS recognizer.
//LUIS English
var model = 'https://api.projectoxford.ai/luis/v2.0/apps/....';
var recognizer = new builder.LuisRecognizer(model);
//LUIS Spanish
var model_es = 'https://api.projectoxford.ai/luis/v2.0/apps/...';
var recognizer_es = new builder.LuisRecognizer(model_es);

var dialog = new builder.IntentDialog({ recognizers: [recognizer, recognizer_es] });

//=========================================================
// Bots Dialogs
//=========================================================

bot.dialog('/', dialog);

Thank you

1

There are 1 answers

0
Lars On BEST ANSWER

Here is an example of a bot that uses two languages and lets the user switch between the models:

var model_en = 'https://api.projectoxford.ai/luis/v2.0/apps/{YOUR ENGLISH MODEL}';
var model_es = 'https://api.projectoxford.ai/luis/v2.0/apps/{YOUR SPANISH MODEL}';
var recognizer = new builder.LuisRecognizer({'en': model_en, 'es' : model_es});

//=========================================================
// Bots Dialogs
//=========================================================
var intents = new builder.IntentDialog({ recognizers: [recognizer] });

intents.matches('hello', function (session) {
    session.send('Hello!');
});

intents.matches('goodbye', function (session) {
    session.send('Goodbye!');
});

intents.matches('spanish', function (session) {
    session.send('Switching to Spanish Model');
    session.preferredLocale('es');
});

intents.matches('english', function (session) {
     session.send('Switching to English Model');
    session.preferredLocale('en');
});

intents.matches('None', function (session) {
    if (session.preferredLocale() == 'en')
    {
        session.send('I do not understand');
    }
    else
    {
        session.send('No entiendo');
    }
});


bot.dialog('/', intents);