2016-12-30 75 views
0

我想創建一個多語言機器人並使用LUIS處理自然語言,但我想知道如何在同一個機器人中創建兩個模型,每種語言一個。如何使LuisRecognizer爲每種語言使用不同的模型

我知道這是可能的,因爲OD的documentation

如果你使用像LUIS系統進行自然語言處理 你可以用一個單獨的模型 配置LuisRecognizer爲每種語言的殭屍支持和SDK將自動 選擇匹配用戶首選區域設置的模型。

我該如何做到這一點?我嘗試這樣做:

// 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); 

謝謝

回答

2

下面是用兩種語言,並讓模特之間進行切換殭屍的例子:

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); 
+0

它的工作原理!謝謝 –

相關問題