botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Multiple LUIS Mode Parent Child relationship

Open ajit-drag opened this issue 10 years ago • 3 comments

I trying to make bot that uses multiple LUIS models. I have designed my models in such a way that parent do the simple classification on input and on the basis of that sentence is further classified by child LUIS model. Here is my code :

var bot = new builder.UniversalBot(chatConnector);

var parentNlpModel = <parent luis model>;
var parentRecognizer = new builder.LuisRecognizer(parentNlpModel);
var parentIntent = new builder.IntentDialog({ recognizers: [parentRecognizer] });

var newsReporterNlpModel = <child luis model>;
var newsReporterRecognizer = new builder.LuisRecognizer(newsReporterNlpModel);
var newsReporterIntent = new builder.IntentDialog({ recognizers: [newsReporterRecognizer] });

bot.dialog('/', parentIntent);

parentIntent.matches('greeting', function (session) { greeting(session, builder) });
parentIntent.matches('newsReporter', function (session) { session.beginDialog('/newsReporter')});
parentIntent.onDefault(builder.DialogAction.send("I am not saying anything about this !!"));

bot.dialog('/newsReporter', newsReporterIntent);
newsReporterIntent.matches('weather', function (session) { session.send("Hi..") });
newsReporterIntent.onDefault(builder.DialogAction.send("I am not saying anything about thiss !!"));

First classication done correctly. But next classification is not giving any response. How to achive my usecase , Is this a correct way ?

ajit-drag avatar Nov 10 '16 19:11 ajit-drag

Have you tried var newsReporterIntent = new builder.IntentDialog({ recognizeMode: builder.RecognizeMode.onBegin, recognizers: [newsReporterRecognizer] }); Otherwise the newsReporterIntent will not automatically try to handle the sentence that triggered that dialog.

Here's a reference to that option.

cmgreivel avatar Nov 11 '16 00:11 cmgreivel

The other thing you could do is create a new recognizer that aggregates both models and flattens them out:

var parentModel = new builder.LuisRecognizer('<model>');
var childModel = new builder.LuisRecognizer('<model>');
var myRecognizer = {
    recognize: function (context, done) {
        parentModel.recognize(context, function (err, intent) {
            if (!err) {
                switch (intent.intent) {
                    case 'ChildIntent':
                        childModel.recognize(context, done);
                        break;
                    default:
                        done(null, intent);
                        break;
                }
            } else {
                done(err, null);
            }
        }); 
    }
};

Stevenic avatar Nov 14 '16 09:11 Stevenic

Closing since answered and no activity. If you have a further issue, please let us know.

chrimc62 avatar Nov 28 '16 00:11 chrimc62