Unified Language Model
From version 3.4.0 onwards, Syn Bot framework supports Unified Language Model file generation. This new file system takes out the burden of individually saving each aspect of the trained model after bot training has completed. You no longer have to take care of optimized versions of bot vocabulary, word embeddings and classifier as all optimized data is now preserved within a single binary file.
One of the main goals behind Oscova's unified language model has been to reduce cluttering of required data by production application by generating a single file that has all the information.
The generated language model is platform agnostic and can be imported by the same bot project across multiple platforms seamlessly. The new model file is built around the philosophy that the Bot needs to just learn about words and entities for the domain it addresses and anything beyond that remains as sparse data both in memory and hard-drives.
For this, the unified language model system internally disregards unrelated data, this not only reduces the model file size drastically but also reduces memory footprint on deployment machines.
Note
Unified language model file generation feature is not available in Community Edition of Syn Bot framework.
Saving the Model
Saving the model file is only possible at the end of Bot training process. As after the training has ended the TrainingFinishedEventArgs
returns an object that provides a method to save the trained model to the specified file path.
Note
The process of generating the model file for saving to disk is only initiated when the SaveModel()
method is called. Prior to calling this method all the newly generated information is retained in memory and is used accordingly by the bot.
The code below shows how you can save the language model file to disk for usage by production applications.
var bot = new OscovaBot();
bot.Dialogs.Add(new HomeIoTDialog());
bot.TrainingFinished += Bot_OnTrainingFinished;
bot.Trainer.StartTraining();
private void Bot_OnTrainingFinished(object sender, TrainingFinishedEventArgs e)
{
//Saves the model file to the specified file.
e.SaveModel(@"D:\iot-bot-model.bin");
}
In the above code, once the training is finished the Bot_OnTrainingFinished()
method gets called, which saves the language model file to disk.
Note
During development it is recommended that you do not save the language model file to disk. You may however, save the model once your bot is ready for deployment.
Loading the Model
Once you have saved the file to disk, your deployment application can use the saved model as shown below.
var bot = new OscovaBot();
bot.Dialogs.Add(new HomeIoTDialog());
//Specify the path to the language model file.
bot.Trainer.StartTraining(@"D:\iot-bot-model.bin");
As seen in the above code you can easily import a model file by passing the file location while calling the StartTraining()
method.
Important
Oscova bot requires the training process to be initiated on both development and deployment environment. The only difference in the deployment environment is that the training process will be faster as a trained model is already being provided to the trainer.